import { expect, it } from "bun:test"; import { createViewCommandSchema } from "../../src/frontendAction/command.js"; import { parseAnswerUiInput } from "../../src/chat/answer-ui.js"; // Keep this matrix in sync with Agent and Server chart timestamp conformance tests. const cases: Array<[string, boolean]> = [ ["2026-06-14T12:00:00Z", true], ["2026-06-14T12:00:00+08:00", true], ["2026-06-14T12:00:00-03:30", true], ["2024-02-29T23:59:59.123456Z", true], ["2026-06-14T12:00:00+23:59", true], [`2026-06-14T12:00:00.${"1".repeat(43)}Z`, true], ["2026-06-14 12:00:00+08:00", false], ["2026-W24-7T12:00:00+08:00", false], ["2026-06-14T12:00+08:00", false], ["2026-06-14T12:00:00+0800", false], ["2026-02-30T12:00:00Z", false], ["2026-13-14T12:00:00Z", false], ["2026-06-00T12:00:00Z", false], ["2026-02-29T12:00:00Z", false], ["2026-06-14T24:00:00Z", false], ["2026-06-14T12:00:60Z", false], ["2026-06-14T12:00:00+24:00", false], ["2026-06-14T12:00:00+08:60", false], ["2026-06-14T12:00:00", false], ["2026-06-14T12:00:00z", false], ["0000-06-14T12:00:00Z", false], [`2026-06-14T12:00:00.${"1".repeat(44)}Z`, false] ]; const chart = (data: Array, sample_times: Array) => ({ title: "压力", chart_type: "line", x_data: ["12:00"], series: [{ name: "测点", data, sample_times }] }); const input = (value: ReturnType) => ({ block_id: "pressure", fallback_text: "压力数据", spec: { root: "chart", elements: { chart: { type: "Chart", props: { ...value, source: "实测" }, children: [] } } } }); const schemas = [createViewCommandSchema({ publication: false }), createViewCommandSchema({ publication: true })]; it.each(cases)("uses the same timestamp boundary for chart commands and answer blocks: %s", (time, accepted) => { const value = chart([1], [time]); for (const schema of schemas) expect(schema.safeParse({ action: "open_chart", chart_id: "pressure", evidence_refs: ["e"], chart: value }).success).toBe(accepted); expect(parseAnswerUiInput(input(value)) !== null).toBe(accepted); }); it.each([ [[0], [null], true], [[null], [null], true], [[null], ["2026-06-14T12:00:00Z"], false], [[1], [], false] ] as Array<[Array, Array, boolean]>)("preserves zero, null and sample alignment: %j %j", (data, times, accepted) => { const value = chart(data, times); for (const schema of schemas) expect(schema.safeParse({ action: "open_chart", chart_id: "pressure", evidence_refs: ["e"], chart: value }).success).toBe(accepted); expect(parseAnswerUiInput(input(value)) !== null).toBe(accepted); });