From 0550b106367d67e3ef28dbb3d16797c341ba2dfd 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:30:39 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(insights):=20the=20run=20rep?= =?UTF-8?q?ort=20speaks=20Turkish,=20not=20the=20service's=20enum?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Three flags from the batch verification, one commit: - The Güven column printed the raw confidence tier (exploratory / stable / none). It now reads the app's own dictionary (insights.confidence.*), the same labels the student drawer shows, in both the view and the Markdown; an unknown tier stays raw rather than being guessed at. - failed_modules are zeka pipeline stage names (discover_students / fetch / compute / store). They get labels with an honest fallback for a stage this build does not know, the same sweep applied to the runs table's own issue line, and the raw stage list stays in the technical disclosure. - The export counted the pending students while the panel named them. The export now carries the same list in the same order (`—` for a student the roster could not resolve), so the .md, the clipboard and the print sheet say what the screen says. Tests pin each: the panel and the export show Keşifsel/Kararlı and never the raw enum; a known stage reads Veri toplama while an unknown one keeps its technical name and the raw list survives in the JSON disclosure; the pending line names Ayça Şahin. --- .../insights/insight-run-report.test.tsx | 42 ++++++++++++++++- .../insights/insight-run-report.tsx | 14 +++++- .../insights/insight-runs-table.tsx | 5 +- src/lib/insight-run-report.ts | 46 +++++++++++++++++-- 4 files changed, 99 insertions(+), 8 deletions(-) diff --git a/src/components/insights/insight-run-report.test.tsx b/src/components/insights/insight-run-report.test.tsx index 2235507..f2d439b 100644 --- a/src/components/insights/insight-run-report.test.tsx +++ b/src/components/insights/insight-run-report.test.tsx @@ -53,7 +53,9 @@ const RUN_B: InsightRun = { students_skipped: 6, rows_written: 9, pending_students: ["s2"], - failed_modules: ["attendance"], + // Real stage vocabulary (discover_students / fetch / compute / store), plus one + // unknown stage so the fallback is pinned too. + failed_modules: ["fetch", "mystery_stage"], }; const ROSTER: PersonRef[] = [ @@ -272,6 +274,43 @@ describe("InsightRunReport", () => { expect(print).toHaveBeenCalledTimes(1); }); + it("labels the confidence tier and the failed stage instead of printing the raw vocabulary", async () => { + await openReport(DAY_B); + await waitFor(() => expect(panel().getByText("Keşifsel")).toBeTruthy()); + + // The tier comes from the app's own dictionary (insights.confidence.*). + expect(panel().queryByText("exploratory")).toBeNull(); + // The failed stage is a zeka pipeline stage name, labelled; the unknown one + // keeps its technical name rather than getting a guessed label. + const issues = panel().getByText(/Veri üretmeyen modüller:/).textContent ?? ""; + expect(issues).toContain("Veri toplama"); + expect(issues).toContain("mystery_stage"); + expect(issues).not.toContain("fetch"); + // The raw stage list survives in the technical disclosure. + expect(panel().getByText(/"failed_modules"/)).toBeTruthy(); + }); + + it("names the pending students in the export exactly as the panel does", async () => { + await openReport(DAY_B); + await waitFor(() => expect(panel().getByText(/1 öğrenci sıradaki çalıştırmaya kaldı/)).toBeTruthy()); + + const markdown = buildRunReportMarkdown( + buildRunReportModel({ + run: RUN_B, + roster: ROSTER, + insights: { s1: INSIGHT_S1, s2: INSIGHT_S2, s3: INSIGHT_S3 }, + errors: {}, + coverageTotal: ROSTER.length, + rosterError: null, + }), + "tr", + ); + expect(markdown).toContain("1 öğrenci sıradaki çalıştırmaya kaldı: Ayça Şahin"); + expect(markdown).toContain("Veri üretmeyen modüller: Veri toplama, mystery_stage"); + expect(markdown).toContain("Keşifsel"); + expect(markdown).not.toContain("exploratory"); + }); + it("builds the same Markdown without a DOM", () => { const model = buildRunReportModel({ run: RUN_A, @@ -290,6 +329,7 @@ describe("InsightRunReport", () => { expect(markdown).toContain("71,0 (1/2)"); expect(markdown).toContain("75%"); expect(markdown).toContain("Çalışma: 0/3 öğrencide veri var → veri yok"); + expect(markdown).toContain("Keşifsel"); expect(markdown).toContain("```json"); }); }); diff --git a/src/components/insights/insight-run-report.tsx b/src/components/insights/insight-run-report.tsx index cea94e8..8fe6de8 100644 --- a/src/components/insights/insight-run-report.tsx +++ b/src/components/insights/insight-run-report.tsx @@ -13,6 +13,8 @@ import { formatDateTime } from "@/lib/format"; import { buildRunReportMarkdown, buildRunReportModel, + confidenceText, + failedStageText, formatRunDuration, moduleLabel, runReportFileName, @@ -130,7 +132,13 @@ function ReportDocument(props: { 0}> -
  • {tx("failedModules", { modules: props.model.run.failed_modules.join(", ") })}
  • +
  • + {tx("failedModules", { + modules: props.model.run.failed_modules + .map((stage) => failedStageText(prefs.locale(), stage)) + .join(", "), + })} +
  • @@ -216,7 +224,9 @@ function ReportDocument(props: { {student.name} {studentStatusText(prefs.locale(), student)} - {student.confidence ?? tx("noData")} + + {student.confidence == null ? tx("noData") : confidenceText(prefs.locale(), student.confidence)} + {student.attention} {student.cards} {studentMarksText(prefs.locale(), student)} diff --git a/src/components/insights/insight-runs-table.tsx b/src/components/insights/insight-runs-table.tsx index 8fe7dc3..e491d9b 100644 --- a/src/components/insights/insight-runs-table.tsx +++ b/src/components/insights/insight-runs-table.tsx @@ -10,6 +10,7 @@ import { TableRowActions } from "@/components/ui/table-row-actions"; import { runReportText, type RunReportKey } from "@/i18n/insights-run-report"; import { cn } from "@/lib/cn"; import { formatDateTime, formatDurationMinutes } from "@/lib/format"; +import { failedStageText } from "@/lib/insight-run-report"; import { usePreferences } from "@/stores/preferences-context"; function statusVariant(status: string) { @@ -96,7 +97,9 @@ export function InsightRunsTable(props: { runs: InsightRun[] }) { )} {run.failed_modules.length > 0 && (

    - {tx("insights.failedModules", { modules: run.failed_modules.join(", ") })} + {tx("insights.failedModules", { + modules: run.failed_modules.map((stage) => failedStageText(prefs.locale(), stage)).join(", "), + })}

    )} diff --git a/src/lib/insight-run-report.ts b/src/lib/insight-run-report.ts index 8db257c..d17ba31 100644 --- a/src/lib/insight-run-report.ts +++ b/src/lib/insight-run-report.ts @@ -1,6 +1,6 @@ import type { InsightRun, PersonRef, StudentInsight } from "@/api/client"; import { runReportText } from "@/i18n/insights-run-report"; -import type { Locale } from "@/i18n/messages"; +import { messages, type Locale, type MessageKey } from "@/i18n/messages"; import { formatDateTime } from "@/lib/format"; /** @@ -281,6 +281,38 @@ export function runReportStatusLabel(locale: Locale, status: string): string { return STATUS_LABELS[locale][status] ?? status; } +const CONFIDENCE_KEYS: Record = { + none: "insights.confidence.none", + exploratory: "insights.confidence.exploratory", + stable: "insights.confidence.stable", +}; + +/** + * ZEKA's confidence tiers, in the reader's language. They come from the app's + * own dictionary so the drawer and the report cannot disagree; a tier the + * dictionary does not know stays raw rather than being guessed at. + */ +export function confidenceText(locale: Locale, confidence: string): string { + const key = CONFIDENCE_KEYS[confidence]; + if (!key) return confidence; + return messages[locale][key] ?? messages.en[key] ?? confidence; +} + +/** + * A failed pipeline stage. The values are zeka's own stage names + * (`discover_students` / `fetch` / `compute` / `store`); an unrecognised one is + * shown as the technical stage it is, and the raw list stays in the report's + * technical disclosure. + */ +const FAILED_STAGE_LABELS: Record> = { + tr: { discover_students: "Öğrenci listesi", fetch: "Veri toplama", compute: "Hesaplama", store: "Kayıt" }, + en: { discover_students: "Student list", fetch: "Data fetch", compute: "Computation", store: "Storage" }, +}; + +export function failedStageText(locale: Locale, stage: string): string { + return FAILED_STAGE_LABELS[locale][stage] ?? stage; +} + export function runReportFileName(runDay: string): string { return `okul-analiz-raporu-${runDay}.md`; } @@ -349,10 +381,16 @@ export function buildRunReportMarkdown(model: RunReportModel, locale: Locale): s const issueCount = run.pending_students.length + run.failed_modules.length + (run.budget_exceeded ? 1 : 0); lines.push(`- ${t("issues")}: ${issueCount === 0 ? t("noIssues") : String(issueCount)}`); if (run.pending_students.length > 0) { - lines.push(`- ${t("pendingStudents", { count: run.pending_students.length })}`); + // Same list, same order as the panel: the export names them, not just counts them. + const named = model.pending.length > 0 + ? `: ${model.pending.map((row) => row.name ?? "—").join(", ")}` + : ""; + lines.push(`- ${t("pendingStudents", { count: run.pending_students.length })}${named}`); } if (run.failed_modules.length > 0) { - lines.push(`- ${t("failedModules", { modules: run.failed_modules.join(", ") })}`); + lines.push( + `- ${t("failedModules", { modules: run.failed_modules.map((stage) => failedStageText(locale, stage)).join(", ") })}`, + ); } lines.push(""); lines.push(`## ${t("schoolSection")}`); @@ -390,7 +428,7 @@ export function buildRunReportMarkdown(model: RunReportModel, locale: Locale): s const cells = [ student.name, studentStatusText(locale, student), - student.confidence ?? t("noData"), + student.confidence == null ? t("noData") : confidenceText(locale, student.confidence), String(student.attention), String(student.cards), studentMarksText(locale, student),