Skip to content

DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.

fix: align integrated mastery catalog and regression fixtures

Bingxi Zhao (Frank)784de5fa6d6b
diff --git a/deeptutor/capabilities/mastery/prompts/en/mastery_loop.yaml b/deeptutor/capabilities/mastery/prompts/en/mastery_loop.yaml
index 44712c83c..275637534 100644
--- a/deeptutor/capabilities/mastery/prompts/en/mastery_loop.yaml
+++ b/deeptutor/capabilities/mastery/prompts/en/mastery_loop.yaml
@@ -63,7 +63,7 @@ session:
**This mode is for designing this mastery goal's outline with the learner, not for teaching.**
This mode has exactly one product: an outline you both agree on. You do not teach content and you do not examine them — the tools for posing questions are refused here.
- **Read which of the two `mastery_status` is describing.** `status: empty` means this goal has no outline yet and your job is the **first draft**; `status: active` means an outline already exists and the learner agreed to it, so your job is to **change** it — `mastery_revise` on the smallest piece that is wrong, not `mastery_build` over the whole thing. Those are entirely different experiences on their side; do not confuse them. When one coordinated change touches several modules, make it a single `mastery_revise` call with `modules=[...]`: they are revised together in one atomic change and one report, instead of replaying the whole outline once per module. For a coordinated outline edit, first use `action=preview` with those edits. Inspect the exact old/new changes, resets, interaction effects, and proposed map. If coherent and within the learner's request, call `action=commit` with only that `preview_id` in a later model round. If the proposal needs correction or has gone stale, preview a corrected plan; do not assume dependent edits commute.
+ **Read which of the two `mastery_status` is describing.** `status: empty` means this goal has no outline yet and your job is the **first draft**; `status: active` means an outline already exists and the learner agreed to it, so your job is to **change** it — `mastery_revise` on the smallest piece that is wrong, not `mastery_build` over the whole thing. Those are entirely different experiences on their side; do not confuse them. When one coordinated change touches several modules, make it a single `mastery_revise` call with `modules=[...]`: they are revised together in one atomic change and one report, instead of replaying the whole outline once per module. For a coordinated outline edit, first use `action=preview` with those edits. Inspect the exact old/new changes, resets, interaction effects, and proposed outline. If coherent and within the learner's request, call `action=commit` with only that `preview_id` in a later model round. If the proposal needs correction or has gone stale, preview a corrected plan; do not assume dependent edits commute.
Every round, `mastery_status` gives you `path_name` and `goal` — `goal` is what the learner wrote themselves when they created this. **You are already standing in that goal**: never ask which learning route they mean, never list their other goals for them to choose from, and never `mastery_switch` away. This is the one they opened.
diff --git a/deeptutor/learning/tests/test_mastery_mode.py b/deeptutor/learning/tests/test_mastery_mode.py
index c186d7f6d..b90508d22 100644
--- a/deeptutor/learning/tests/test_mastery_mode.py
+++ b/deeptutor/learning/tests/test_mastery_mode.py
@@ -173,25 +173,42 @@ async def test_review_refuses_a_knowledge_point_that_is_not_mastered_yet(path_id
@pytest.mark.asyncio
-async def test_review_may_re_examine_something_already_mastered_even_when_not_due(path_id):
+async def test_review_may_re_examine_something_already_mastered_even_when_not_due(
+ path_id, monkeypatch
+):
"""A due date is a reminder, not a permission — asking to go back over
something you have mastered is always allowed."""
+ from deeptutor.learning import semantic_assessment
+
+ learner_answer = "A noise schedule controls the variance added at each forward diffusion step."
+
+ async def judge(_config, items):
+ assert all(item["answer"] == learner_answer for item in items)
+ return {
+ item["question_id"]: semantic_assessment.Verdict(
+ result="correct", confidence=0.99, feedback="The explanation meets the objective."
+ )
+ for item in items
+ }
+
+ monkeypatch.setattr(semantic_assessment, "judge_answers", judge)
await _build(path_id)
kp = f"{path_id}_m0_kp0"
passed = await MasteryAssessTool().execute(
_mastery_path_id=path_id,
_mastery_session_mode=STUDY,
knowledge_point_id=kp,
- passed=True,
+ _learner_message=learner_answer,
explanation="解释得很清楚。",
)
+ assert passed.success, passed.content
assert json.loads(passed.content)["mastered"] is True
again = await MasteryAssessTool().execute(
_mastery_path_id=path_id,
_mastery_session_mode=REVIEW,
knowledge_point_id=kp,
- passed=True,
+ _learner_message=learner_answer,
explanation="复习时又讲了一遍。",
)
assert again.success is True
diff --git a/deeptutor/learning/tests/test_mastery_revise_batch.py b/deeptutor/learning/tests/test_mastery_revise_batch.py
index c5bc9436c..cd0a626d6 100644
--- a/deeptutor/learning/tests/test_mastery_revise_batch.py
+++ b/deeptutor/learning/tests/test_mastery_revise_batch.py
@@ -313,15 +313,32 @@ async def test_batch_shares_id_space_and_remaps_cross_module_prereqs(path_id):
@pytest.mark.asyncio
-async def test_batch_refuses_when_any_module_touches_mastered_work(path_id):
+async def test_batch_refuses_when_any_module_touches_mastered_work(path_id, monkeypatch):
"""Proven work in ANY module of the batch refuses the whole request."""
+ from deeptutor.learning import semantic_assessment
+
+ learner_answer = (
+ "Conjunction requires both propositions to be true; disjunction requires at least one."
+ )
+
+ async def judge(_config, items):
+ assert all(item["answer"] == learner_answer for item in items)
+ return {
+ item["question_id"]: semantic_assessment.Verdict(
+ result="correct", confidence=0.99, feedback="The explanation meets the objective."
+ )
+ for item in items
+ }
+
+ monkeypatch.setattr(semantic_assessment, "judge_answers", judge)
built = await _build_three_modules(path_id)
assessed = await MasteryAssessTool().execute(
_mastery_path_id=path_id,
knowledge_point_id="test_path_m1_kp0",
- passed=True,
+ _learner_message=learner_answer,
feedback="学习者用自己的话说清了合取与析取的区别。",
)
+ assert assessed.success, assessed.content
assert json.loads(assessed.content)["mastered"] is True
_, store = _stored_state(path_id)
post_assess_revision = store.load(path_id).version
diff --git a/deeptutor/runtime/bootstrap/builtin_capabilities.py b/deeptutor/runtime/bootstrap/builtin_capabilities.py
index 8968236e0..4a9444f0a 100644
--- a/deeptutor/runtime/bootstrap/builtin_capabilities.py
+++ b/deeptutor/runtime/bootstrap/builtin_capabilities.py
@@ -172,6 +172,7 @@ BUILTIN_CAPABILITY_SPECS: dict[str, BuiltinCapabilitySpec] = {
"Mastery-based tutoring: a dedicated agent loop drives an adaptive mastery path with a hard, per-type mastery gate and spaced review.",
stages=["responding"],
tools_used=[
+ "mastery_prepare_lesson",
"mastery_status",
"mastery_quiz",
"mastery_note_explained",
diff --git a/tests/capabilities/test_mastery_status_snapshot.py b/tests/capabilities/test_mastery_status_snapshot.py
index 94f12002d..ba3e9ae1f 100644
--- a/tests/capabilities/test_mastery_status_snapshot.py
+++ b/tests/capabilities/test_mastery_status_snapshot.py
@@ -87,5 +87,7 @@ async def test_prepass_failure_keeps_tool_fallback_and_grade_seed(monkeypatch):
)
pipeline = AgenticChatPipeline(language="en")
assert await pipeline._capability_pre_loop_briefings(context, None) == ""
- assert "already graded it: correct" in pipeline._capability_pre_loop_seed(context)
+ seed = pipeline._capability_pre_loop_seed(context)
+ assert "engine reports: correct" in seed
+ assert 'they answered "B"' in seed
assert "otherwise call this FIRST" in MasteryStatusTool().get_definition().description
diff --git a/tests/services/rag/test_llamaindex_embedding_failures.py b/tests/services/rag/test_llamaindex_embedding_failures.py
index 152140e4a..d4ca1c87f 100644
--- a/tests/services/rag/test_llamaindex_embedding_failures.py
+++ b/tests/services/rag/test_llamaindex_embedding_failures.py
@@ -87,7 +87,7 @@ async def test_search_returns_reindex_hint_for_null_vector_index(
monkeypatch.setattr(
storage_module,
"retrieve_nodes",
- lambda storage_dir, query, top_k=5: (_ for _ in ()).throw(
+ lambda storage_dir, query, top_k=5, document_keys=None: (_ for _ in ()).throw(
TypeError("unsupported operand type(s) for *: 'NoneType' and 'float'")
),
)
@@ -216,7 +216,7 @@ async def test_rag_service_hides_low_level_invalid_index_error_in_raw_logs(
monkeypatch.setattr(
storage_module,
"retrieve_nodes",
- lambda storage_dir, query, top_k=5: (_ for _ in ()).throw(
+ lambda storage_dir, query, top_k=5, document_keys=None: (_ for _ in ()).throw(
TypeError("unsupported operand type(s) for *: 'NoneType' and 'float'")
),
)
@@ -327,7 +327,7 @@ async def test_search_answer_keeps_reindex_steps_without_low_level_details(
monkeypatch.setattr(
storage_module,
"retrieve_nodes",
- lambda storage_dir, query, top_k=5: (_ for _ in ()).throw(
+ lambda storage_dir, query, top_k=5, document_keys=None: (_ for _ in ()).throw(
TypeError("unsupported operand type(s) for *: 'NoneType' and 'float'")
),
)
diff --git a/tests/services/rag/test_visual_assets.py b/tests/services/rag/test_visual_assets.py
index cc8808c2a..779686ea3 100644
--- a/tests/services/rag/test_visual_assets.py
+++ b/tests/services/rag/test_visual_assets.py
@@ -209,6 +209,13 @@ def test_hundred_figure_textbook_keeps_late_figures_searchable_and_delivers_pixe
from deeptutor.tools.builtin import RAGTool
kb_dir, source, image, parsed = _fixture(tmp_path)
+ # Page-grounded indexing now opens the physical PDF as well as parser output.
+ import pymupdf
+
+ with pymupdf.open() as pdf:
+ for _ in range(100):
+ pdf.new_page()
+ pdf.save(source)
image.unlink()
parsed = replace(
parsed,
@@ -255,11 +262,12 @@ def test_hundred_figure_textbook_keeps_late_figures_searchable_and_delivers_pixe
assert len(visuals) == 100
VisualAssetStore(kb_dir).publish(candidates)
index = VectorStoreIndex.from_documents(documents, embed_model=FigureEmbedding())
- retriever = index.as_retriever(similarity_top_k=1)
+ # The page text and its figure caption share the deterministic embedding.
+ retriever = index.as_retriever(similarity_top_k=2)
for number in (1, 50, 100):
nodes = retriever.retrieve(f"Figure {number}")
retrieved = LlamaIndexPipeline._nodes_to_result(None, f"Figure {number}", nodes)
- record = retrieved["sources"][0]
+ record = next(item for item in retrieved["sources"] if item.get("visual_asset_id"))
assert record["page"] == number
assert record["visual_asset_id"] == candidates[number - 1].record["asset_id"]
@@ -284,7 +292,9 @@ def test_hundred_figure_textbook_keeps_late_figures_searchable_and_delivers_pixe
parts = result.model_message["content"]
assert sum(part["type"] == "image_url" for part in parts) == 1
assert base64.b64decode(parts[1]["image_url"]["url"].split(",", 1)[1]) == expected_pixels
- assert late.record["asset_id"] in result.sources[0]["visual_asset_url"]
+ assert any(
+ late.record["asset_id"] in item.get("visual_asset_url", "") for item in result.sources
+ )
@pytest.mark.parametrize("suffix", [".pdf", ".epub"])