fix: expose per-file cover identities in import scans

This commit is contained in:
2026-10-14 14:48:16 +08:00
parent c2dc9015ea
commit 0d6dc4b342
2 changed files with 29 additions and 2 deletions
@@ -24,6 +24,8 @@ def test_scan_selected_student_folder_prefills_cover_identity(tmp_path, monkeypa
assert project["status"] == "needs_confirmation"
assert len(project["files"]) == 5
assert project["missing"] == []
assert project["folder_identity"] == {"student_no": "", "name": "", "topic": ""}
assert all(file["detected_identity"]["student_no"] == "9000000001" for file in project["files"])
assert scan("test", root=tmp_path)["projects"] == result["projects"]
@@ -39,6 +41,26 @@ def test_scan_conflicting_covers_need_confirmation(tmp_path, monkeypatch):
assert project["student_no"] == ""
assert project["warnings"]
assert project["status"] == "needs_confirmation"
assert "学号" in project["warnings"][0]
assert "student_no" not in project["warnings"][0]
assert {file["detected_identity"]["student_no"] for file in project["files"]} == {"9000000001", "9000000002"}
def test_scan_unreadable_cover_has_no_stale_identity(tmp_path, monkeypatch):
from wisegrade import storage
folder = tmp_path / "9000000001_学生甲_机器人系统"
folder.mkdir()
(folder / "阶段报告1.pdf").write_bytes(b"fixture")
(folder / "阶段报告2.pdf").write_bytes(b"broken")
def read(path):
if path.name.endswith("2.pdf"):
raise ValueError("损坏PDF")
return "学号:9000000001\n姓名:学生甲\n题目:机器人系统"
monkeypatch.setattr(storage, "first_text", read)
project = scan(".", root=tmp_path)["projects"][0]
assert project["folder_identity"]["student_no"] == "9000000001"
assert project["files"][0]["detected_identity"]["student_no"] == "9000000001"
assert project["files"][1]["detected_identity"] == {}
def test_scan_parent_skips_empty_folders(tmp_path, monkeypatch):