import { describe, expect, it } from "vitest"; import { renderPromptDialog } from "#src/presentation/dialog-renderer"; import type { PromptPayload } from "#src/presentation/prompt-payload"; const BUDGET = { maxRows: 40, fieldMaxWidth: 400, width: 120 }; function payload(overrides: Partial = {}): PromptPayload { return { kind: "bash", request: { requester: { agentName: null, forwarded: false, sessionId: null }, surface: "bash", toolName: "bash", invokedToolName: null, value: "rm -rf ./dist", matchedPattern: "rm*", commandContext: null, executedUnit: null, }, evidence: [], annotations: [], ...overrides, }; } describe("renderPromptDialog: decision notes", () => { it("renders a model-origin note with the model-generated suffix", () => { const view = renderPromptDialog(payload(), BUDGET, undefined, [ { origin: "model", text: "该操作的最坏后果可能不可逆。" }, ]); const joined = view.lines.join("\n"); expect(joined).toContain("review"); expect(joined).toContain("该操作的最坏后果可能不可逆。"); expect(joined).toContain("模型生成,仅供参考"); }); it("renders a system-origin note plain, without the suffix", () => { const view = renderPromptDialog(payload(), BUDGET, undefined, [ { origin: "system", text: "自动审查超时,已转人工确认。" }, ]); const joined = view.lines.join("\n"); expect(joined).toContain("review"); expect(joined).toContain("自动审查超时,已转人工确认。"); expect(joined).not.toContain("模型生成"); }); it("leads the ask facts, so a row-budget elision cannot drop the refusal reason", () => { const view = renderPromptDialog( payload({ evidence: Array.from({ length: 40 }, (_, index) => ({ label: `evidence-${index}`, text: `value-${index}`, detail: null, })), }), { maxRows: 6, fieldMaxWidth: 400, width: 120 }, undefined, [{ origin: "system", text: "risk too high" }], ); expect(view.lines.join("\n")).toContain("risk too high"); expect(view.elided).toBe(true); }); it("renders no note line when there are no notes", () => { const view = renderPromptDialog(payload(), BUDGET); const joined = view.lines.join("\n"); expect(joined).not.toContain("review"); }); });