From 37ac68df92ecf9fa37887cc83d29b1ba799c47c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Fri, 18 Sep 2026 09:28:55 +0300 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=A9=B9=20the=20drawer=20stops=20ca?= =?UTF-8?q?lling=20an=20unresolved=20course=20school-wide?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two refute-first flags on the previous commit, both closed: - `courseLine` claimed "Okul geneli" for any course id whose title failed to resolve. The attention payload's own contract is that a *null* course is the school-wide case, so an unresolved id was inventing a fact on a student's report. A null course now says school-wide; an unresolved id reads "Ders adı çözümlenemedi" and its raw id stays in the technical disclosure. - The evidence renderer printed `dimension` raw, so one drawer showed both "Boyut: dikkat_tuzagi" and the segments section's "Dikkat tuzağı" for the same vocabulary. The dimension map moved to the i18n module and both call sites share it; an unmapped dimension is omitted from the human view and named in the technical-disclosure count instead. Tests: two new cases pin both flags — school-wide wording only for a null course, asserted together with the exact count of school-wide claims, and no snake_case dimension anywhere in the human view while the raw value survives in the disclosure. 7/7 pass; reverting either fix turns exactly its own test red. --- .../insights/insight-detail.test.tsx | 66 +++++++++++++++++++ src/components/insights/insight-detail.tsx | 21 +++--- .../insights/insight-module-views.tsx | 11 +++- src/i18n/insights-detail.ts | 16 ++++- 4 files changed, 100 insertions(+), 14 deletions(-) diff --git a/src/components/insights/insight-detail.test.tsx b/src/components/insights/insight-detail.test.tsx index 45cf8ae..bd093eb 100644 --- a/src/components/insights/insight-detail.test.tsx +++ b/src/components/insights/insight-detail.test.tsx @@ -218,6 +218,34 @@ const insight: StudentInsight = { created_at: NOW, expires_at: NOW + WEEK, }, + { + id: "card-2", + product: "O2", + rule_id: "O2.segment_cognitive_gap", + rule_version: 1, + scope: "bilissel_talep=var", + audience_role: "student", + course: null, + evidence: { + dimension: "dikkat_tuzagi", + label: "var", + fact: "Dikkat tuzağı sorularında doğruluk, öğrencinin genel düzeyinin altında.", + n_answers: 20, + n_correct: 9, + accuracy: 0.45, + overall_accuracy: 0.6, + overall_n_answers: 100, + contrast: -0.15, + reference_mean_contrast: -0.02, + reference_n_students: 180, + relative_contrast: -0.13, + gate_n_answers: 12, + rule: "relative_contrast <= -0.08 ve n_answers >= 12", + }, + confidence: "exploratory", + created_at: NOW, + expires_at: NOW + WEEK, + }, ], segments: [ { @@ -327,6 +355,44 @@ describe("InsightDetail", () => { expect(disclosure.open).toBe(true); }); + it("claims school-wide only when the payload has no course at all", () => { + const base = insight.attention[0]; + render(() => ( + + + + )); + const human = screen.getByTestId("insight-human").textContent ?? ""; + + expect(human).toContain("Okul geneli devamsızlık artışı."); + expect(human).toContain("Ders adı çözümlenemedi"); + // Exactly one item may read as school-wide: a course id whose title did not + // resolve is not evidence of a school-wide fact. + expect((human.match(/Okul geneli/g) ?? []).length).toBe(1); + expect(human).not.toContain("01a0b1b0-9d58-77f7-966f-5bfa87cb7e11"); + }); + + it("maps the segment vocabulary everywhere, never the machine name", () => { + renderDrawer(); + const human = screen.getByTestId("insight-human").textContent ?? ""; + + // Segments section and the O2 card's evidence must agree on the label. + expect(human).toContain("Dikkat tuzağı"); + expect(human).toContain("Bilişsel talep: var"); + expect(human).not.toContain("dikkat_tuzagi"); + expect(human).not.toContain("bilissel_talep"); + + expect(screen.getByTestId("insight-technical").textContent).toContain("dikkat_tuzagi"); + }); + it("keeps the cards-only mode free of the drawer's full-view sections", () => { renderDrawer({ mode: "cards" }); const human = screen.getByTestId("insight-human").textContent ?? ""; diff --git a/src/components/insights/insight-detail.tsx b/src/components/insights/insight-detail.tsx index ccc4891..4f32edc 100644 --- a/src/components/insights/insight-detail.tsx +++ b/src/components/insights/insight-detail.tsx @@ -8,7 +8,7 @@ import { import { Badge } from "@/components/ui/badge"; import { EmptyInline } from "@/components/ui/empty-inline"; import { IconAlert, IconChart, IconSparkles } from "@/components/ui/icons"; -import { detailText, type InsightDetailKey } from "@/i18n/insights-detail"; +import { detailText, dimensionLabel, type InsightDetailKey } from "@/i18n/insights-detail"; import { cn } from "@/lib/cn"; import { formatDateTime } from "@/lib/format"; import { isRecord } from "@/lib/is-record"; @@ -30,11 +30,6 @@ const TRIGGER_KEYS: Record = { homework: "trigger.homework", mark_trend: "trigger.mark_trend", }; -const DIMENSION_KEYS: Record = { - bilissel_talep: "segments.dimension.bilissel_talep", - dikkat_tuzagi: "segments.dimension.dikkat_tuzagi", - okuma_yuku: "segments.dimension.okuma_yuku", -}; const PRODUCT_KEYS: Record = { O1: "product.O1", O2: "product.O2", @@ -66,10 +61,16 @@ export function InsightDetail(props: { insight: StudentInsight; mode?: "full" | const title = isRecord(entry) ? entry.course_title : undefined; return typeof title === "string" && title.length > 0 ? title : null; }; - const courseLine = (id?: string | null) => courseTitle(id) ?? (id ? tx("insights.schoolWide") : null); - const dimensionLabel = (dimension: string | null | undefined) => { - const key = dimension ? DIMENSION_KEYS[dimension] : undefined; - return key ? detailText(key) : null; + /** + * The attention list's own contract: a null `course` means the fact is + * school-wide, so that is the only case that may say so. A course id whose + * title never made it into the payload is NOT school-wide — saying it were + * invents a fact on a student's report, so it is labelled as unresolved + * (the id itself stays in the technical disclosure). + */ + const courseLine = (id?: string | null) => { + if (!id) return tx("insights.schoolWide"); + return courseTitle(id) ?? detailText("detail.unresolvedCourse"); }; /** A card scope is `=