@@ -1250,3 +1250,108 @@ async def test_synchronize_projects_removes_db_only_projects(project_service: Pr
12501250 db_project = await project_service .repository .get_by_name (test_project_name )
12511251 if db_project :
12521252 await project_service .repository .delete (db_project .id )
1253+
1254+
1255+ @pytest .mark .asyncio
1256+ async def test_remove_project_with_delete_notes_false (project_service : ProjectService ):
1257+ """Test that remove_project with delete_notes=False keeps directory intact."""
1258+ test_project_name = f"test-remove-keep-{ os .urandom (4 ).hex ()} "
1259+ with tempfile .TemporaryDirectory () as temp_dir :
1260+ test_root = Path (temp_dir )
1261+ test_project_path = test_root / "test-project"
1262+ test_project_path .mkdir ()
1263+ test_file = test_project_path / "test.md"
1264+ test_file .write_text ("# Test Note" )
1265+
1266+ try :
1267+ # Add project
1268+ await project_service .add_project (test_project_name , str (test_project_path ))
1269+
1270+ # Verify project exists
1271+ assert test_project_name in project_service .projects
1272+ assert test_project_path .exists ()
1273+ assert test_file .exists ()
1274+
1275+ # Remove project without deleting notes (default behavior)
1276+ await project_service .remove_project (test_project_name , delete_notes = False )
1277+
1278+ # Verify project is removed from config/db
1279+ assert test_project_name not in project_service .projects
1280+ db_project = await project_service .repository .get_by_name (test_project_name )
1281+ assert db_project is None
1282+
1283+ # Verify directory and files still exist
1284+ assert test_project_path .exists ()
1285+ assert test_file .exists ()
1286+
1287+ finally :
1288+ # Cleanup happens automatically with temp_dir context manager
1289+ pass
1290+
1291+
1292+ @pytest .mark .asyncio
1293+ async def test_remove_project_with_delete_notes_true (project_service : ProjectService ):
1294+ """Test that remove_project with delete_notes=True deletes directory."""
1295+ test_project_name = f"test-remove-delete-{ os .urandom (4 ).hex ()} "
1296+ with tempfile .TemporaryDirectory () as temp_dir :
1297+ test_root = Path (temp_dir )
1298+ test_project_path = test_root / "test-project"
1299+ test_project_path .mkdir ()
1300+ test_file = test_project_path / "test.md"
1301+ test_file .write_text ("# Test Note" )
1302+
1303+ try :
1304+ # Add project
1305+ await project_service .add_project (test_project_name , str (test_project_path ))
1306+
1307+ # Verify project exists
1308+ assert test_project_name in project_service .projects
1309+ assert test_project_path .exists ()
1310+ assert test_file .exists ()
1311+
1312+ # Remove project with delete_notes=True
1313+ await project_service .remove_project (test_project_name , delete_notes = True )
1314+
1315+ # Verify project is removed from config/db
1316+ assert test_project_name not in project_service .projects
1317+ db_project = await project_service .repository .get_by_name (test_project_name )
1318+ assert db_project is None
1319+
1320+ # Verify directory and files are deleted
1321+ assert not test_project_path .exists ()
1322+
1323+ finally :
1324+ # Cleanup happens automatically with temp_dir context manager
1325+ pass
1326+
1327+
1328+ @pytest .mark .asyncio
1329+ async def test_remove_project_delete_notes_missing_directory (project_service : ProjectService ):
1330+ """Test that remove_project with delete_notes=True handles missing directory gracefully."""
1331+ test_project_name = f"test-remove-missing-{ os .urandom (4 ).hex ()} "
1332+ test_project_path = f"/tmp/nonexistent-directory-{ os .urandom (8 ).hex ()} "
1333+
1334+ try :
1335+ # Add project pointing to non-existent path
1336+ await project_service .add_project (test_project_name , test_project_path )
1337+
1338+ # Verify project exists in config/db
1339+ assert test_project_name in project_service .projects
1340+ db_project = await project_service .repository .get_by_name (test_project_name )
1341+ assert db_project is not None
1342+
1343+ # Remove project with delete_notes=True (should not fail even if dir doesn't exist)
1344+ await project_service .remove_project (test_project_name , delete_notes = True )
1345+
1346+ # Verify project is removed from config/db
1347+ assert test_project_name not in project_service .projects
1348+ db_project = await project_service .repository .get_by_name (test_project_name )
1349+ assert db_project is None
1350+
1351+ finally :
1352+ # Ensure cleanup
1353+ if test_project_name in project_service .projects :
1354+ try :
1355+ project_service .config_manager .remove_project (test_project_name )
1356+ except Exception :
1357+ pass
0 commit comments