import { expect, test } from "bun:test";
import { renderToStaticMarkup } from "react-dom/server";
import { AgentChatMessage, type CloudAgentChatMessage } from "@/components/canvas/canvas-cloud-agent-chat-ui";
import { canvasThemes } from "@/lib/canvas-theme";
const error: CloudAgentChatMessage = { id: "error", role: "error", title: "Agent 执行失败", text: "Agent 执行失败" };
test("generic failure renders its title only once in both canvas themes", () => {
for (const theme of [canvasThemes.light, canvasThemes.dark]) {
const html = renderToStaticMarkup();
expect(html.match(/Agent 执行失败/g)).toHaveLength(1);
expect(html).not.toContain("agent-error-detail");
expect(html).toContain('role="status"');
}
});
test("diagnostic identifiers are preserved in a closed disclosure, not the main description", () => {
const html = renderToStaticMarkup();
expect(html).toContain("Agent 执行中断,请重新发送消息
");
expect(html).toContain("诊断信息");
expect(html).toContain("ag-test-run");
});
test("specific business failures and recovery guidance remain visible and are escaped", () => {
const html = renderToStaticMarkup(bad()", meta: "请联系管理员检查配额" }} theme={canvasThemes.light} />);
expect(html).toContain("余额不足 <script>bad()</script>");
expect(html).toContain("请联系管理员检查配额");
expect(html).not.toContain(" {
const html = renderToStaticMarkup( {}} retrying />);
expect(html).toContain("agent-status-message--warning");
expect(html).toContain("disabled=");
expect(html).toContain("重试中");
});