|
|
@@ -97,3 +97,39 @@ def test_rollback_restores_files_on_current_branch_with_new_commit(tmp_path):
|
|
|
after_count = int(_run_git(project_root, "rev-list", "--count", "HEAD").stdout.strip())
|
|
|
assert after_count == before_count + 1
|
|
|
assert "rollback: 恢复到 ch0001 备份点" in _run_git(project_root, "log", "-1", "--format=%s").stdout
|
|
|
+
|
|
|
+
|
|
|
+def test_local_backup_copies_manuscript_when_git_unavailable(tmp_path, monkeypatch):
|
|
|
+ monkeypatch.setattr(backup_manager, "is_git_available", lambda: False)
|
|
|
+
|
|
|
+ webnovel_dir = tmp_path / ".webnovel"
|
|
|
+ manuscript_dir = tmp_path / "正文"
|
|
|
+ outline_dir = tmp_path / "大纲"
|
|
|
+ settings_dir = tmp_path / "设定集"
|
|
|
+ webnovel_dir.mkdir()
|
|
|
+ manuscript_dir.mkdir()
|
|
|
+ outline_dir.mkdir()
|
|
|
+ settings_dir.mkdir()
|
|
|
+ (webnovel_dir / "state.json").write_text('{"current_chapter": 1}', encoding="utf-8")
|
|
|
+ (manuscript_dir / "第0001章-x.md").write_text("正文内容", encoding="utf-8")
|
|
|
+ (outline_dir / "第0001章.md").write_text("大纲内容", encoding="utf-8")
|
|
|
+ (settings_dir / "人物.md").write_text("设定内容", encoding="utf-8")
|
|
|
+
|
|
|
+ manager = GitBackupManager(str(tmp_path))
|
|
|
+
|
|
|
+ assert manager.backup(1) is True
|
|
|
+
|
|
|
+ snapshots = sorted((webnovel_dir / "backups").glob("snapshot_ch0001_*"))
|
|
|
+ assert len(snapshots) == 1
|
|
|
+ snapshot = snapshots[0]
|
|
|
+ assert (snapshot / "正文" / "第0001章-x.md").read_text(encoding="utf-8") == "正文内容"
|
|
|
+ assert (snapshot / "大纲" / "第0001章.md").read_text(encoding="utf-8") == "大纲内容"
|
|
|
+ assert (snapshot / "设定集" / "人物.md").read_text(encoding="utf-8") == "设定内容"
|
|
|
+ assert (snapshot / ".webnovel" / "state.json").read_text(encoding="utf-8") == '{"current_chapter": 1}'
|
|
|
+
|
|
|
+ for chapter in range(2, 13):
|
|
|
+ assert manager.backup(chapter) is True
|
|
|
+
|
|
|
+ snapshots = sorted((webnovel_dir / "backups").glob("snapshot_ch*"))
|
|
|
+ assert len(snapshots) == 10
|
|
|
+ assert snapshot not in snapshots
|