From e68e4b7d57738776868e96ac343ee63bf150d179 Mon Sep 17 00:00:00 2001 From: iomgaa Date: Tue, 14 Jul 2026 13:51:05 -0400 Subject: [PATCH] fix: restore sub_pattern when loading benchmark JSON --- app/question_gen/loader.py | 1 + .../test_generated_question_sub_pattern.py | 30 +++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/app/question_gen/loader.py b/app/question_gen/loader.py index bad3950..878bfef 100644 --- a/app/question_gen/loader.py +++ b/app/question_gen/loader.py @@ -51,6 +51,7 @@ def load_benchmark(questions_dir: Path) -> list[GeneratedQuestion]: family=qa.get("family"), skill_target=qa.get("skill_target"), difficulty_steps=qa.get("difficulty_steps"), + sub_pattern=qa.get("sub_pattern"), ) ) return results diff --git a/tests/unit/test_generated_question_sub_pattern.py b/tests/unit/test_generated_question_sub_pattern.py index 44f4659..c40feca 100644 --- a/tests/unit/test_generated_question_sub_pattern.py +++ b/tests/unit/test_generated_question_sub_pattern.py @@ -90,3 +90,33 @@ def test_append_to_json_writes_sub_pattern(tmp_path): data = json.loads((tmp_path / "v1.json").read_text(encoding="utf-8")) assert data[0]["sub_pattern"] == "temporal_reasoning_failure" + + +def test_load_benchmark_restores_sub_pattern(tmp_path): + from app.question_gen.loader import load_benchmark + import json + entry = { + "question_id": "v1_Action Recognition_0001", "video_id": "v1", + "task_type": "Action Recognition", "question": "?", + "options": ["A. 蒸", "B. 炒", "C. 煮", "D. 炸"], "answer": "A", + "source_nodes": ["n1"], "difficulty": "hard", + "family": "ACTION_RECOGNITION", "skill_target": "M1_AR", + "sub_pattern": "temporal_reasoning_failure", + } + (tmp_path / "v1.json").write_text(json.dumps([entry]), encoding="utf-8") + loaded = load_benchmark(tmp_path) + assert loaded[0].sub_pattern == "temporal_reasoning_failure" + + +def test_load_benchmark_sub_pattern_defaults_none_when_absent(tmp_path): + from app.question_gen.loader import load_benchmark + import json + entry = { + "question_id": "v1_Object Recognition_0001", "video_id": "v1", + "task_type": "Object Recognition", "question": "?", + "options": ["A. a", "B. b", "C. c", "D. d"], "answer": "A", + "source_nodes": ["n1"], "difficulty": "medium", + } + (tmp_path / "v1.json").write_text(json.dumps([entry]), encoding="utf-8") + loaded = load_benchmark(tmp_path) + assert loaded[0].sub_pattern is None