@@ -1368,6 +1368,44 @@ def test_desktop_github_sync_applies_local_changes_after_remote_first_sync(tmp_p
13681368 assert (clone_check / "Daily Note - Jun 2026.md" ).exists ()
13691369
13701370
1371+ def test_desktop_github_sync_blocks_reading_note_deletions (tmp_path , monkeypatch : pytest .MonkeyPatch ) -> None :
1372+ bare = tmp_path / "notes.git"
1373+ seed = tmp_path / "seed"
1374+ notes = tmp_path / "Daily Note 2026"
1375+ agents ._run_git (["init" , "--bare" , str (bare )], tmp_path ) # noqa: SLF001 - git sync contract
1376+ seed .mkdir ()
1377+ agents ._run_git (["init" ], seed ) # noqa: SLF001
1378+ agents ._run_git (["checkout" , "-b" , "main" ], seed ) # noqa: SLF001
1379+ agents ._run_git (["config" , "user.email" , "paperflow@example.com" ], seed ) # noqa: SLF001
1380+ agents ._run_git (["config" , "user.name" , "PaperFlow Test" ], seed ) # noqa: SLF001
1381+ (seed / "Daily Note - Jan 2026.md" ).write_text ("# Jan Note\n " , encoding = "utf-8" )
1382+ (seed / "Daily Note - Jun 2026.md" ).write_text ("# Jun Note\n " , encoding = "utf-8" )
1383+ agents ._run_git (["add" , "." ], seed ) # noqa: SLF001
1384+ agents ._run_git (["commit" , "-m" , "Initialize reading notes" ], seed ) # noqa: SLF001
1385+ agents ._run_git (["remote" , "add" , "origin" , str (bare )], seed ) # noqa: SLF001
1386+ agents ._run_git (["push" , "-u" , "origin" , "main" ], seed ) # noqa: SLF001
1387+
1388+ agents ._run_git (["clone" , "-b" , "main" , str (bare ), str (notes )], tmp_path ) # noqa: SLF001
1389+ agents ._run_git (["config" , "user.email" , "paperflow@example.com" ], notes ) # noqa: SLF001
1390+ agents ._run_git (["config" , "user.name" , "PaperFlow Test" ], notes ) # noqa: SLF001
1391+ (notes / "Daily Note - Jan 2026.md" ).unlink ()
1392+ (notes / "Daily Note - Jun 2026.md" ).write_text ("# Jun Note\n \n New local content.\n " , encoding = "utf-8" )
1393+
1394+ monkeypatch .setattr (agents , "_configured_reading_notes_git_dir" , lambda : notes )
1395+ monkeypatch .setattr (agents , "_configured_reading_notes_git_remote" , lambda : str (bare ))
1396+ monkeypatch .setattr (agents , "_configured_reading_notes_git_branch" , lambda : "main" )
1397+ monkeypatch .setenv ("PAPERFLOW_READING_NOTES_GIT_LLM_REVIEW" , "false" )
1398+
1399+ with pytest .raises (RuntimeError , match = "删除阅读笔记文件" ):
1400+ agents .sync_reading_notes_github ("user_test" )
1401+
1402+ assert (notes / "Daily Note - Jan 2026.md" ).exists ()
1403+ clone_check = tmp_path / "check-delete-guard"
1404+ agents ._run_git (["clone" , "-b" , "main" , str (bare ), str (clone_check )], tmp_path ) # noqa: SLF001
1405+ assert (clone_check / "Daily Note - Jan 2026.md" ).exists ()
1406+ assert "New local content" not in (clone_check / "Daily Note - Jun 2026.md" ).read_text (encoding = "utf-8" )
1407+
1408+
13711409def test_desktop_github_sync_keeps_remote_on_note_conflict_without_branch (
13721410 tmp_path , monkeypatch : pytest .MonkeyPatch
13731411) -> None :
0 commit comments