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.
This commit is contained in:
Marc-André Bombeck committed 2026-09-27 13:00:07 +02:00
1 parent 74f4c6e767
commit 38a7e386a9
2 files changed
+35 -3

No files matched your search

@@ -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",
+7 -3
View File
@@ -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