From 82091f95418da56b595652f93afd3db0e2a73207 Mon Sep 17 00:00:00 2001 From: Benjamin Schwing <63053132+BenjiAvH@users.noreply.github.com> Date: Wed, 25 Nov 2026 08:03:37 +0000 Subject: [PATCH 1/2] fix(quiz): let the AI judge grade objective items whose key names no option A choice or true/false key that resolves to no option or truth value ("Richtig, weil ...", an empty key) made exact matching fail the item and overrule any judge verdict. Such items are now graded by the judge, like open answers. Signed-off-by: Benjamin Schwing <63053132+BenjiAvH@users.noreply.github.com> --- web/components/quiz/QuizViewer.tsx | 21 +++++++++++++--- web/tests/quiz/QuizViewer.smoke.spec.tsx | 32 ++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/web/components/quiz/QuizViewer.tsx b/web/components/quiz/QuizViewer.tsx index c3f60c395b..b7f02be605 100644 --- a/web/components/quiz/QuizViewer.tsx +++ b/web/components/quiz/QuizViewer.tsx @@ -209,6 +209,23 @@ function isAnswerCorrect(question: QuizQuestion, answer: AnswerState): boolean { ); } +/** + * Choice / true-false items graded by exact match. A key that names no + * option or no truth value ("Richtig, weil …", or no key at all) leaves the + * item to the AI judge instead. + */ +function hasObjectiveKey(question: QuizQuestion): boolean { + const key = question.correct_answer.trim(); + if (!key) return false; + if (isMultipleChoice(question)) { + return resolveChoiceAnswerKey(key, question.options) in question.options!; + } + if (isConceptQuizQuestion(question.question_type)) { + return resolveConceptAnswer(key) !== ""; + } + return false; +} + /** Exact matching first; the AI verdict only grades what it cannot. */ function getAssessment( question: QuizQuestion, @@ -217,9 +234,7 @@ function getAssessment( ) { return resolveQuizAssessment({ exactCorrect: isAnswerCorrect(question, answer), - objective: - isMultipleChoice(question) || - isConceptQuizQuestion(question.question_type), + objective: hasObjectiveKey(question), hasImages: answer.images.length > 0, verdict, }); diff --git a/web/tests/quiz/QuizViewer.smoke.spec.tsx b/web/tests/quiz/QuizViewer.smoke.spec.tsx index 197458f49d..2787d19c5a 100644 --- a/web/tests/quiz/QuizViewer.smoke.spec.tsx +++ b/web/tests/quiz/QuizViewer.smoke.spec.tsx @@ -503,6 +503,38 @@ describe("QuizViewer smoke", () => { expect(screen.queryByText("Incorrect")).toBeNull(); }); + it("lets the judge grade a true/false item whose key names no truth value", async () => { + const user = userEvent.setup(); + renderViewer( + [{ ...conceptQuestion, correct_answer: "Richtig, weil ..." }], + { sessionId: "session-1", turnId: "turn-1" }, + ); + await user.click(screen.getByRole("button", { name: "True" })); + await user.click(screen.getByRole("button", { name: /Check Answer/ })); + await user.click(screen.getByRole("button", { name: /AI Judge/ })); + const verdict = { + result: "correct" as const, + is_correct: true, + final: true, + confidence: 0.9, + steps: [], + }; + act(() => { + mocks.judgeHandlers!.onVerdict!(verdict); + mocks.judgeHandlers!.onDone("Right."); + }); + + // Exact matching cannot read the key, so it must not overrule the judge. + await waitFor(() => { + expect(mocks.updateNotebookEntry).toHaveBeenCalledWith(11, { + ai_judgment: "Right.", + ai_verdict: verdict, + is_correct: true, + result: "correct", + }); + }); + }); + it("closes in-flight judge handles on unmount", async () => { const user = userEvent.setup(); const { unmount } = renderViewer([shortAnswerQuestion]); From e443fa2a9bda2bc8fb4fecf8f34cca8b95ac3f3c Mon Sep 17 00:00:00 2001 From: Benjamin Schwing <63053132+BenjiAvH@users.noreply.github.com> Date: Fri, 4 Dec 2026 23:49:37 +0000 Subject: [PATCH 2/2] fix(quiz): keep resolved choice keys authoritative --- web/components/quiz/QuizViewer.tsx | 36 ++++++++--- web/tests/quiz/QuizViewer.smoke.spec.tsx | 82 +++++++++++++++++++----- 2 files changed, 93 insertions(+), 25 deletions(-) diff --git a/web/components/quiz/QuizViewer.tsx b/web/components/quiz/QuizViewer.tsx index b7f02be605..6419c2455b 100644 --- a/web/components/quiz/QuizViewer.tsx +++ b/web/components/quiz/QuizViewer.tsx @@ -186,17 +186,21 @@ function getUserAnswer(question: QuizQuestion, answer: AnswerState): string { return answer.typed.trim(); } +function resolveObjectiveChoiceKey(question: QuizQuestion): string { + const correct = question.correct_answer.trim(); + const options = question.options!; + const resolved = resolveChoiceAnswerKey(correct, options); + if (Object.hasOwn(options, resolved)) return resolved; + const first = correct.charAt(0).toUpperCase(); + return Object.hasOwn(options, first) ? first : ""; +} + function isAnswerCorrect(question: QuizQuestion, answer: AnswerState): boolean { const userAnswer = getUserAnswer(question, answer); if (!userAnswer) return false; const correct = question.correct_answer.trim(); if (isMultipleChoice(question)) { - const correctChoiceKey = resolveChoiceAnswerKey(correct, question.options); - return ( - userAnswer.toUpperCase() === correctChoiceKey || - userAnswer.toUpperCase() === correct.toUpperCase() || - userAnswer.toUpperCase() === correct.charAt(0).toUpperCase() - ); + return userAnswer.toUpperCase() === resolveObjectiveChoiceKey(question); } if (isConceptQuizQuestion(question.question_type)) { const correctTF = resolveConceptAnswer(correct); @@ -218,7 +222,7 @@ function hasObjectiveKey(question: QuizQuestion): boolean { const key = question.correct_answer.trim(); if (!key) return false; if (isMultipleChoice(question)) { - return resolveChoiceAnswerKey(key, question.options) in question.options!; + return resolveObjectiveChoiceKey(question) !== ""; } if (isConceptQuizQuestion(question.question_type)) { return resolveConceptAnswer(key) !== ""; @@ -998,18 +1002,30 @@ export default function QuizViewer({ )} - {t(QUIZ_TYPE_LABEL_KEYS[normalizeQuizQuestionType(q.question_type)])} + {t( + QUIZ_TYPE_LABEL_KEYS[ + normalizeQuizQuestionType(q.question_type) + ], + )} {ans.submitted && (