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

Two surfaces reported quiz accuracy as if it were progress toward a gate that
never reads it.

`mastery_assess` aimed at a quantitative objective is refused outright, naming
the tools that do apply. The mirror direction was silent: posing a question at
a concept objective registered it like any other, so a tutor could work an
objective its questions cannot open and never be told. That direction stays
allowed — a question is a fair way to probe a concept before teaching it — but
it now says what grading the answer will and will not do.

The objective detail panel drew `mastery` as a progress bar for every gate.
On a qualitative one that is quiz accuracy, so an objective could show a full
bar next to an outline dot that was correctly still hollow. A boolean gate now
reads all-or-nothing, and says plainly that practice questions are not what
opens it.
This commit is contained in:
Bingxi Zhao (Frank)
2026-09-14 15:15:54 +08:00
parent d49a41cd99
commit 897fce52f2
6 changed files with 161 additions and 1 deletions

View File

@@ -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,

View File

@@ -233,6 +233,40 @@ async def test_quiz_then_grade_drives_memory_gate(path_id):
assert mastered is True
@pytest.mark.asyncio
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.

View File

@@ -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>
);
}

View File

@@ -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",

View File

@@ -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": "复习计划",

View File

@@ -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();
});
});