From 38a7e386a99e77f6f31f5674b6fc9115c425f086 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Sun, 27 Sep 2026 13:00:07 +0200 Subject: [PATCH] fix(coach): keep the chart on a table shown again Asking for an earlier table "as a chart" went through show_result, which builds the requested view, but collecting the turn's tables then reset every chart to null and only derived a new one for fresh tables. The table came back without its chart. A table shown again now keeps the view it was given. --- .../coach/results/__tests__/project.test.ts | 28 +++++++++++++++++++ src/lib/ai/coach/results/project.ts | 10 +++++-- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/src/lib/ai/coach/results/__tests__/project.test.ts b/src/lib/ai/coach/results/__tests__/project.test.ts index 6b3022711..7852f56ad 100644 --- a/src/lib/ai/coach/results/__tests__/project.test.ts +++ b/src/lib/ai/coach/results/__tests__/project.test.ts @@ -65,6 +65,34 @@ describe("projectResults", () => { expect(out.every((t) => !t.displayed && t.chart === null)).toBe(true); }); + it("keeps the view a table shown again was given", () => { + const shownAgain = { + ...table("r1", 5), + reusedFrom: { messageId: "m-a1", ref: "r2" }, + }; + const [asChart, asTable] = projectResults({ + locale: "en", + calls: [ + { name: "show_result", result: { present: true, table: shownAgain } }, + { + name: "show_result", + result: { + present: true, + table: { ...shownAgain, ref: "r2", chart: null, chartKind: null }, + }, + }, + ], + }); + expect(asChart.chart).toEqual({ + kind: "line", + x: "day", + series: ["value"], + }); + expect(asChart.chartKind).toBe("line"); + expect(asTable.chart).toBeNull(); + expect(asTable.chartKind).toBeNull(); + }); + it("trims a table to the row ceiling and says so", () => { const [out] = projectResults({ locale: "en", diff --git a/src/lib/ai/coach/results/project.ts b/src/lib/ai/coach/results/project.ts index bbf1b56f2..5bc974bba 100644 --- a/src/lib/ai/coach/results/project.ts +++ b/src/lib/ai/coach/results/project.ts @@ -37,7 +37,7 @@ function refNumber(ref: string): number { /** * Tables for this turn, in ref order (`r1`..), at most six, each trimmed to * `RESULT_TABLE_MAX_ROWS`. `chart` and `chartKind` are left for - * `deriveChartSpec` to fill. + * `deriveChartSpec` to fill, except on a table shown again. */ export function projectResults(args: { calls: SettledToolCall[]; @@ -56,8 +56,12 @@ export function projectResults(args: { rowCount: Math.max(table.rowCount, rows.length), truncated: table.truncated || rows.length < table.rows.length, displayed: false, - chart: null, - chartKind: null, + // A table shown again keeps the view `show_result` chose for it (a + // chart, a histogram, or none); `withChart` leaves it as it is. Every + // other table gets its chart from `deriveChartSpec`. + ...(table.reusedFrom + ? { chart: table.chart, chartKind: table.chartKind } + : { chart: null, chartKind: null }), }); } return tables