forge
Explore
Log in

Don't you dare go Hollow

One label map, one pending line

Browse files at this commit

2cb6c6bcdbdc0e65f32336a0850523032b78e85dAhmet Kaan GümüşParent: 0550b10
  • refactor
    • one label map, one pending line
Show full message
♻️ refactor(insights): one label map, one pending line

Two same-class residuals from the delta review:

- The run status had two maps. The table's inline list used the app's
  dictionary (insights.status.*) while the report kept a private table — and
  they had ALREADY drifted: tr `running` read "Çalışıyor" in the dictionary and
  "Sürüyor" in the report. runReportStatusLabel now reads the dictionary, the
  table badge calls it, and there is one place a new status gets a label. An
  unknown status stays raw on both surfaces.
- The pending-students expression was copied between the panel and the export.
  pendingStudentsLine(locale, model) builds the one line (count, names in the
  ledger's order, `—` where the roster cannot resolve a name) and both render
  it, so the export cannot drift from the screen. The em-dash case now has a
  test on the same line the panel shows.

Gates: tsc clean; insight-run-report.test.tsx 11/11. Live: the ledger badge and
the report's Durum both read "Tamamlandı", the student rows read "Kararlı".
src/components/insights/insight-run-report.test.tsxmodified+8 -5
@@ -52,7 +52,9 @@ const RUN_B: InsightRun = {
52 students_failed: 1,52 students_failed: 1,
53 students_skipped: 6,53 students_skipped: 6,
54 rows_written: 9,54 rows_written: 9,
55- pending_students: ["s2"],55+ // One pending student the roster can name, one it cannot: the second pins the
56+ // `—` fallback (the id itself stays in the technical disclosure).
57+ pending_students: ["s2", "ghost-id"],
56 // Real stage vocabulary (discover_students / fetch / compute / store), plus one58 // Real stage vocabulary (discover_students / fetch / compute / store), plus one
57 // unknown stage so the fallback is pinned too.59 // unknown stage so the fallback is pinned too.
58 failed_modules: ["fetch", "mystery_stage"],60 failed_modules: ["fetch", "mystery_stage"],
@@ -165,8 +167,8 @@ describe("InsightRunReport", () => {
165 await openReport(DAY_B);167 await openReport(DAY_B);
166 168
167 expect(screen.getByText(`Çalıştırma günü ${DAY_B}`)).toBeTruthy();169 expect(screen.getByText(`Çalıştırma günü ${DAY_B}`)).toBeTruthy();
168- // RUN_B's own ledger row, not RUN_A's: its pending student is named in the report.170+ // RUN_B's own ledger row, not RUN_A's: its pending students are named in the report.
169- await waitFor(() => expect(panel().getByText(/1 öğrenci sıradaki çalıştırmaya kaldı: Ayça Şahin/)).toBeTruthy());171+ await waitFor(() => expect(panel().getByText(/2 öğrenci sıradaki çalıştırmaya kaldı: Ayça Şahin, —/)).toBeTruthy());
170 });172 });
171 173
172 it("renders the run's counters from the ledger row", async () => {174 it("renders the run's counters from the ledger row", async () => {
@@ -292,7 +294,7 @@ describe("InsightRunReport", () => {
292 294
293 it("names the pending students in the export exactly as the panel does", async () => {295 it("names the pending students in the export exactly as the panel does", async () => {
294 await openReport(DAY_B);296 await openReport(DAY_B);
295- await waitFor(() => expect(panel().getByText(/1 öğrenci sıradaki çalıştırmaya kaldı/)).toBeTruthy());297+ await waitFor(() => expect(panel().getByText(/2 öğrenci sıradaki çalıştırmaya kaldı/)).toBeTruthy());
296 298
297 const markdown = buildRunReportMarkdown(299 const markdown = buildRunReportMarkdown(
298 buildRunReportModel({300 buildRunReportModel({
@@ -305,7 +307,8 @@ describe("InsightRunReport", () => {
305 }),307 }),
306 "tr",308 "tr",
307 );309 );
308- expect(markdown).toContain("1 öğrenci sıradaki çalıştırmaya kaldı: Ayça Şahin");310+ // Same line, same order, same em-dash as the panel (one helper builds both).
311+ expect(markdown).toContain("2 öğrenci sıradaki çalıştırmaya kaldı: Ayça Şahin, —");
309 expect(markdown).toContain("Veri üretmeyen modüller: Veri toplama, mystery_stage");312 expect(markdown).toContain("Veri üretmeyen modüller: Veri toplama, mystery_stage");
310 expect(markdown).toContain("Keşifsel");313 expect(markdown).toContain("Keşifsel");
311 expect(markdown).not.toContain("exploratory");314 expect(markdown).not.toContain("exploratory");
src/components/insights/insight-run-report.tsxmodified+3 -5
@@ -17,6 +17,7 @@ import {
17 failedStageText,17 failedStageText,
18 formatRunDuration,18 formatRunDuration,
19 moduleLabel,19 moduleLabel,
20+ pendingStudentsLine,
20 runReportFileName,21 runReportFileName,
21 runReportStatusLabel,22 runReportStatusLabel,
22 studentAttendanceText,23 studentAttendanceText,
@@ -125,11 +126,8 @@ function ReportDocument(props: {
125 </dl>126 </dl>
126 <Show when={props.model.run.pending_students.length + props.model.run.failed_modules.length > 0}>127 <Show when={props.model.run.pending_students.length + props.model.run.failed_modules.length > 0}>
127 <ul class="space-y-1 text-xs text-warning">128 <ul class="space-y-1 text-xs text-warning">
128- <Show when={props.model.run.pending_students.length > 0}>129+ <Show when={pendingStudentsLine(prefs.locale(), props.model)}>
129- <li>130+ {(line) => <li>{line()}</li>}
130- {tx("pendingStudents", { count: props.model.run.pending_students.length })}
131- {props.model.pending.length > 0 ? `: ${props.model.pending.map((row) => row.name ?? "—").join(", ")}` : ""}
132- </li>
133 </Show>131 </Show>
134 <Show when={props.model.run.failed_modules.length > 0}>132 <Show when={props.model.run.failed_modules.length > 0}>
135 <li>133 <li>
src/components/insights/insight-runs-table.tsxmodified+2 -6
@@ -10,7 +10,7 @@ import { TableRowActions } from "@/components/ui/table-row-actions";
10 import { runReportText, type RunReportKey } from "@/i18n/insights-run-report";10 import { runReportText, type RunReportKey } from "@/i18n/insights-run-report";
11 import { cn } from "@/lib/cn";11 import { cn } from "@/lib/cn";
12 import { formatDateTime, formatDurationMinutes } from "@/lib/format";12 import { formatDateTime, formatDurationMinutes } from "@/lib/format";
13-import { failedStageText } from "@/lib/insight-run-report";13+import { failedStageText, runReportStatusLabel } from "@/lib/insight-run-report";
14 import { usePreferences } from "@/stores/preferences-context";14 import { usePreferences } from "@/stores/preferences-context";
15 15
16 function statusVariant(status: string) {16 function statusVariant(status: string) {
@@ -27,10 +27,6 @@ export function InsightRunsTable(props: { runs: InsightRun[] }) {
27 const rtx = (key: RunReportKey, vars?: Record<string, string | number>) =>27 const rtx = (key: RunReportKey, vars?: Record<string, string | number>) =>
28 runReportText(prefs.locale(), key, vars);28 runReportText(prefs.locale(), key, vars);
29 const [selectedRun, setSelectedRun] = createSignal<InsightRun | null>(null);29 const [selectedRun, setSelectedRun] = createSignal<InsightRun | null>(null);
30- const statusLabel = (status: string) =>
31- ["running", "ok", "partial", "failed", "skipped"].includes(status)
32- ? tx(`insights.status.${status}`)
33- : status;
34 const columns = createMemo<ColumnDef<InsightRun>[]>(() => [30 const columns = createMemo<ColumnDef<InsightRun>[]>(() => [
35 {31 {
36 accessorKey: "run_day",32 accessorKey: "run_day",
@@ -47,7 +43,7 @@ export function InsightRunsTable(props: { runs: InsightRun[] }) {
47 header: tx("insights.result"),43 header: tx("insights.result"),
48 cell: (cell) => (44 cell: (cell) => (
49 <Badge variant={statusVariant(cell.row.original.status)} class="rounded-full">45 <Badge variant={statusVariant(cell.row.original.status)} class="rounded-full">
50- {statusLabel(cell.row.original.status)}46+ {runReportStatusLabel(prefs.locale(), cell.row.original.status)}
51 </Badge>47 </Badge>
52 ),48 ),
53 },49 },
src/lib/insight-run-report.tsmodified+28 -11
@@ -272,13 +272,24 @@ export function moduleLabel(locale: Locale, id: ModuleId): string {
272 return runReportText(locale, "moduleSubmission");272 return runReportText(locale, "moduleSubmission");
273 }273 }
274 274
275-const STATUS_LABELS: Record<string, Record<string, string>> = {275+const STATUS_KEYS: Record<string, MessageKey> = {
276- tr: { running: "Sürüyor", ok: "Tamamlandı", partial: "Kısmi", failed: "Başarısız", skipped: "Atlandı" },276+ running: "insights.status.running",
277- en: { running: "Running", ok: "Completed", partial: "Partial", failed: "Failed", skipped: "Skipped" },277+ ok: "insights.status.ok",
278+ partial: "insights.status.partial",
279+ failed: "insights.status.failed",
280+ skipped: "insights.status.skipped",
278 };281 };
279 282
283+/**
284+ * A run status, from the app's dictionary — the same keys the run table's own
285+ * badge uses, so the ledger and the report can never disagree about what
286+ * `partial` says. A status this build does not know stays raw rather than being
287+ * guessed at.
288+ */
280 export function runReportStatusLabel(locale: Locale, status: string): string {289 export function runReportStatusLabel(locale: Locale, status: string): string {
281- return STATUS_LABELS[locale][status] ?? status;290+ const key = STATUS_KEYS[status];
291+ if (!key) return status;
292+ return messages[locale][key] ?? messages.en[key] ?? status;
282 }293 }
283 294
284 const CONFIDENCE_KEYS: Record<string, MessageKey> = {295 const CONFIDENCE_KEYS: Record<string, MessageKey> = {
@@ -317,6 +328,17 @@ export function runReportFileName(runDay: string): string {
317 return `okul-analiz-raporu-${runDay}.md`;328 return `okul-analiz-raporu-${runDay}.md`;
318 }329 }
319 330
331+/**
332+ * The run's pending students, by name, in the ledger's own order — the panel
333+ * and the export both render this one line, so the count, the names and the
334+ * `—` for a student the roster cannot resolve can never drift apart.
335+ */
336+export function pendingStudentsLine(locale: Locale, model: RunReportModel): string | null {
337+ if (model.run.pending_students.length === 0) return null;
338+ const named = model.pending.map((row) => row.name ?? "—").join(", ");
339+ return `${runReportText(locale, "pendingStudents", { count: model.run.pending_students.length })}: ${named}`;
340+}
341+
320 /** `0,716` in Turkish, `0.716` in English — the same number either way. */342 /** `0,716` in Turkish, `0.716` in English — the same number either way. */
321 export function runReportDecimal(value: number, locale: Locale): string {343 export function runReportDecimal(value: number, locale: Locale): string {
322 return value.toFixed(1).replace(".", locale === "tr" ? "," : ".");344 return value.toFixed(1).replace(".", locale === "tr" ? "," : ".");
@@ -380,13 +402,8 @@ export function buildRunReportMarkdown(model: RunReportModel, locale: Locale): s
380 );402 );
381 const issueCount = run.pending_students.length + run.failed_modules.length + (run.budget_exceeded ? 1 : 0);403 const issueCount = run.pending_students.length + run.failed_modules.length + (run.budget_exceeded ? 1 : 0);
382 lines.push(`- ${t("issues")}: ${issueCount === 0 ? t("noIssues") : String(issueCount)}`);404 lines.push(`- ${t("issues")}: ${issueCount === 0 ? t("noIssues") : String(issueCount)}`);
383- if (run.pending_students.length > 0) {405+ const pendingLine = pendingStudentsLine(locale, model);
384- // Same list, same order as the panel: the export names them, not just counts them.406+ if (pendingLine) lines.push(`- ${pendingLine}`);
385- const named = model.pending.length > 0
386- ? `: ${model.pending.map((row) => row.name ?? "—").join(", ")}`
387- : "";
388- lines.push(`- ${t("pendingStudents", { count: run.pending_students.length })}${named}`);
389- }
390 if (run.failed_modules.length > 0) {407 if (run.failed_modules.length > 0) {
391 lines.push(408 lines.push(
392 `- ${t("failedModules", { modules: run.failed_modules.map((stage) => failedStageText(locale, stage)).join(", ") })}`,409 `- ${t("failedModules", { modules: run.failed_modules.map((stage) => failedStageText(locale, stage)).join(", ") })}`,