Bladeren bron

fix: 修复7个CLI测试的temp_project fixture缺少state.json

resolve_project_root()要求.webnovel/state.json存在,
之前的fallback已移除,需确保测试fixture创建该文件。
lingfengQAQ 2 maanden geleden
bovenliggende
commit
1507a8b96f

+ 2 - 0
webnovel-writer/scripts/data_modules/tests/test_entity_linker_cli.py

@@ -17,6 +17,8 @@ def temp_project(tmp_path):
     from data_modules.config import DataModulesConfig
     cfg = DataModulesConfig.from_project_root(tmp_path)
     cfg.ensure_dirs()
+    if not cfg.state_file.exists():
+        cfg.state_file.write_text("{}", encoding="utf-8")
     return cfg
 
 

+ 5 - 0
webnovel-writer/scripts/data_modules/tests/test_migrate_state_to_sqlite.py

@@ -22,6 +22,8 @@ from data_modules.index_manager import IndexManager
 def temp_project(tmp_path):
     cfg = DataModulesConfig.from_project_root(tmp_path)
     cfg.ensure_dirs()
+    if not cfg.state_file.exists():
+        cfg.state_file.write_text("{}", encoding="utf-8")
     return cfg
 
 
@@ -125,6 +127,9 @@ def test_migrate_state_verbose_and_dry_run(temp_project, capsys):
 
 def test_migrate_state_cli_main(tmp_path, monkeypatch, capsys):
     project_root = tmp_path
+    webnovel_dir = project_root / ".webnovel"
+    webnovel_dir.mkdir(parents=True, exist_ok=True)
+    (webnovel_dir / "state.json").write_text("{}", encoding="utf-8")
     args = [
         "migrate_state_to_sqlite",
         "--project-root",

+ 2 - 0
webnovel-writer/scripts/data_modules/tests/test_rag_adapter.py

@@ -61,6 +61,8 @@ class StubClientRerankFailure(StubClient):
 def temp_project(tmp_path, monkeypatch):
     cfg = DataModulesConfig.from_project_root(tmp_path)
     cfg.ensure_dirs()
+    if not cfg.state_file.exists():
+        cfg.state_file.write_text("{}", encoding="utf-8")
     monkeypatch.setattr(rag_module, "get_client", lambda config: StubClient())
     return cfg
 

+ 2 - 0
webnovel-writer/scripts/data_modules/tests/test_relationship_graph.py

@@ -23,6 +23,8 @@ from data_modules.index_manager import (
 def temp_project(tmp_path):
     cfg = DataModulesConfig.from_project_root(tmp_path)
     cfg.ensure_dirs()
+    if not cfg.state_file.exists():
+        cfg.state_file.write_text("{}", encoding="utf-8")
     return cfg
 
 

+ 2 - 0
webnovel-writer/scripts/data_modules/tests/test_sql_state_manager.py

@@ -19,6 +19,8 @@ def temp_project(tmp_path):
     from data_modules.config import DataModulesConfig
     cfg = DataModulesConfig.from_project_root(tmp_path)
     cfg.ensure_dirs()
+    if not cfg.state_file.exists():
+        cfg.state_file.write_text("{}", encoding="utf-8")
     return cfg
 
 

+ 2 - 0
webnovel-writer/scripts/data_modules/tests/test_style_sampler_cli.py

@@ -18,6 +18,8 @@ from data_modules.config import DataModulesConfig
 def temp_project(tmp_path):
     cfg = DataModulesConfig.from_project_root(tmp_path)
     cfg.ensure_dirs()
+    if not cfg.state_file.exists():
+        cfg.state_file.write_text("{}", encoding="utf-8")
     return cfg