Skip to content

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

fix(mastery): say which gate a number is being read against

Bingxi Zhao (Frank)897fce52f24b
diff --git a/deeptutor/capabilities/mastery/tools.py b/deeptutor/capabilities/mastery/tools.py
index d6477cbec..b910af014 100644
--- a/deeptutor/capabilities/mastery/tools.py
+++ b/deeptutor/capabilities/mastery/tools.py
@@ -922,6 +922,20 @@ class MasteryQuizTool(BaseTool):
"button. That list was removed from the stem. Pass the ask in "
"'question' and the choices only in 'options'."
)
+ if kp.type in QUALITATIVE_TYPES:
+ # The mirror of ``record_qualitative_for_path``, which refuses
+ # outright when mastery_assess is aimed at a quantitative
+ # objective. This direction stays allowed — a question is a fair
+ # way to probe a concept before teaching it — but it must not be
+ # silent: the attempt lands in ``mastery_levels``, the qualitative
+ # gate never reads it, and a tutor that assumes otherwise poses
+ # questions forever at an objective they cannot open.
+ notice += (
+ " This objective is gated qualitatively: grading this answer "
+ "will not open it, however right the answer is. Use the "
+ "question to probe, then have the learner explain the idea in "
+ "their own words and record that with mastery_assess."
+ )
return ToolResult(
content=notice,
diff --git a/deeptutor/learning/tests/test_mastery_tools.py b/deeptutor/learning/tests/test_mastery_tools.py
index 9b36c8b0a..d7c671b09 100644
--- a/deeptutor/learning/tests/test_mastery_tools.py
+++ b/deeptutor/learning/tests/test_mastery_tools.py
@@ -233,6 +233,40 @@ async def test_quiz_then_grade_drives_memory_gate(path_id):
assert mastered is True
+async def test_quiz_on_a_qualitative_objective_says_the_question_cannot_open_it(path_id):
+ """Probing a concept with a question is allowed, but never silent.
+
+ ``mastery_assess`` aimed at a quantitative objective is refused outright.
+ The mirror direction stays permitted — a question is a fair way to check
+ what the learner already knows — so the notice has to carry what the
+ refusal would otherwise have said.
+ """
+ build = json.loads((await _build_basic(path_id)).content)
+ points = build["map"]["modules"][0]["knowledge_points"]
+ concept_id = next(p["id"] for p in points if p["type"] == "concept")
+
+ result = await MasteryQuizTool().execute(
+ _mastery_path_id=path_id,
+ knowledge_point_id=concept_id,
+ question="Why does XOR matter?",
+ expected_answer="it is not linearly separable",
+ question_type="short",
+ )
+ assert "mastery_assess" in result.content
+
+ memory_id = next(p["id"] for p in points if p["type"] == "memory")
+ await MasterySkipQuestionTool().execute(_mastery_path_id=path_id)
+ quantitative = await MasteryQuizTool().execute(
+ _mastery_path_id=path_id,
+ knowledge_point_id=memory_id,
+ question="2+2?",
+ expected_answer="4",
+ question_type="short",
+ )
+ assert "mastery_assess" not in quantitative.content
+
+
@pytest.mark.asyncio
async def test_grade_on_a_qualitative_objective_sends_the_tutor_to_assess(path_id):
"""A concept objective cannot be cleared by questions, and grading says so.
diff --git a/web/components/space/learning/ObjectiveDetail.tsx b/web/components/space/learning/ObjectiveDetail.tsx
index 2b33185fe..70dec4c96 100644
--- a/web/components/space/learning/ObjectiveDetail.tsx
+++ b/web/components/space/learning/ObjectiveDetail.tsx
@@ -116,7 +116,16 @@ export function ObjectiveDetail({
/** Mastery against the gate it has to clear. */
function GateBar({ report }: { report: ObjectiveReport }) {
const { t } = useTranslation();
- const pct = Math.round(report.mastery * 100);
+ const qualitative = report.gate === "qualitative";
+ // A qualitative gate is a boolean, so all-or-nothing is the only honest
+ // fill. `mastery` carries quiz accuracy for these objectives too, and
+ // drawing that as gate progress is how a waypoint comes to show a full bar
+ // beside a hollow dot — the learner reads "100%, still not cleared".
+ const pct = qualitative
+ ? report.mastered
+ ? 100
+ : 0
+ : Math.round(report.mastery * 100);
const thresholdPct = Math.round(report.threshold * 100);
const perfectButBelowGate =
report.gate === "quantitative" &&
@@ -161,6 +170,13 @@ function GateBar({ report }: { report: ObjectiveReport }) {
)}
</p>
)}
+ {qualitative && !report.mastered && report.attempts.length > 0 && (
+ <p className="mt-1.5 text-[11px] leading-4 text-[var(--muted-foreground)]">
+ {t(
+ "Practice questions do not open this gate — it opens when you explain the idea in your own words and your tutor records that. Your answers here still count as practice.",
+ )}
+ </p>
+ )}
</div>
);
}
diff --git a/web/locales/en/app.json b/web/locales/en/app.json
index edbd0e683..99a278f2f 100644
--- a/web/locales/en/app.json
+++ b/web/locales/en/app.json
@@ -3175,6 +3175,7 @@
" · cleared": " · cleared",
"No attempts yet. Once you work through this waypoint, its questions, your answers, and the grading evidence will appear here.": "No attempts yet. Once you work through this waypoint, its questions, your answers, and the grading evidence will appear here.",
"Qualitative gate: explain it in your own words": "Qualitative gate: explain it in your own words",
+ "Practice questions do not open this gate — it opens when you explain the idea in your own words and your tutor records that. Your answers here still count as practice.": "Practice questions do not open this gate — it opens when you explain the idea in your own words and your tutor records that. Your answers here still count as practice.",
"Topic name": "Topic name",
"What is this path called?": "What is this path called?",
"Review plan": "Review plan",
diff --git a/web/locales/zh/app.json b/web/locales/zh/app.json
index 19d0c4312..e0c6bccbc 100644
--- a/web/locales/zh/app.json
+++ b/web/locales/zh/app.json
@@ -3175,6 +3175,7 @@
" · cleared": " · 已订正",
"No attempts yet. Once you work through this waypoint, its questions, your answers, and the grading evidence will appear here.": "还没有作答记录。在对话里继续辅导后,这里会出现题目、你的回答和判分。",
"Qualitative gate: explain it in your own words": "定性门槛:用自己的话讲清楚",
+ "Practice questions do not open this gate — it opens when you explain the idea in your own words and your tutor records that. Your answers here still count as practice.": "练习题打不开这道门——它要等你用自己的话把这个概念讲清楚、并由导师记录下来才会打开。你在这里的作答仍然算作练习。",
"Topic name": "目标名称",
"What is this path called?": "这条路叫什么?",
"Review plan": "复习计划",
diff --git a/web/tests/mastery-objective-gate-bar.spec.tsx b/web/tests/mastery-objective-gate-bar.spec.tsx
new file mode 100644
index 000000000..e6762b726
--- /dev/null
+++ b/web/tests/mastery-objective-gate-bar.spec.tsx
@@ -0,0 +1,94 @@
+import { render, screen } from "@testing-library/react";
+import { describe, expect, it } from "vitest";
+
+import { ObjectiveDetail } from "@/components/space/learning/ObjectiveDetail";
+import { initI18n } from "@/i18n/init";
+import type { ObjectiveReport } from "@/lib/learning-api";
+
+initI18n("en");
+
+function report(overrides: Partial<ObjectiveReport> = {}): ObjectiveReport {
+ return {
+ id: "kp1",
+ name: "Why XOR matters",
+ type: "concept",
+ module_name: "Module 1",
+ status: "learning",
+ gate: "qualitative",
+ mastered: false,
+ assessed_mastered: false,
+ mastery_source: "",
+ override_note: "",
+ // Quiz accuracy, which the qualitative gate never reads.
+ mastery: 1,
+ threshold: 1,
+ attempts: [
+ {
+ question_id: "q1",
+ prompt: "Why does XOR matter?",
+ answer: "it is not linearly separable",
+ is_correct: true,
+ error_type: "",
+ at: 1_700_000_000,
+ },
+ ],
+ correct_count: 1,
+ explanation: "",
+ review: null,
+ errors: [],
+ ...overrides,
+ };
+}
+
+describe("objective gate bar", () => {
+ it("does not draw quiz accuracy as progress toward a qualitative gate", () => {
+ // The reading that made this necessary: mastery 1.0 against threshold 1.0
+ // on an objective that is not mastered. Shown as a bar it says "full, yet
+ // not cleared" — beside an outline dot that is correctly still hollow.
+ render(<ObjectiveDetail report={report()} zh={false} />);
+
+ expect(screen.getByText("0%")).toBeTruthy();
+ expect(screen.queryByText("100%")).toBeNull();
+ expect(
+ screen.getByText(/Practice questions do not open this gate/),
+ ).toBeTruthy();
+ });
+
+ it("fills the bar once the qualitative gate actually opens", () => {
+ render(
+ <ObjectiveDetail
+ report={report({
+ mastered: true,
+ assessed_mastered: true,
+ status: "mastered",
+ mastery_source: "system",
+ })}
+ zh={false}
+ />,
+ );
+
+ expect(screen.getByText("100%")).toBeTruthy();
+ expect(
+ screen.queryByText(/Practice questions do not open this gate/),
+ ).toBeNull();
+ });
+
+ it("still reports real progress against a quantitative gate", () => {
+ render(
+ <ObjectiveDetail
+ report={report({
+ type: "memory",
+ gate: "quantitative",
+ mastery: 0.5,
+ threshold: 0.9,
+ })}
+ zh={false}
+ />,
+ );
+
+ expect(screen.getByText("50%")).toBeTruthy();
+ expect(
+ screen.queryByText(/Practice questions do not open this gate/),
+ ).toBeNull();
+ });
+});