import { expect, test } from "bun:test";
import { renderToStaticMarkup } from "react-dom/server";
import { AgentToolCard } from "@/components/canvas/canvas-cloud-agent-chat-ui";
import { canvasThemes } from "@/lib/canvas-theme";
test("automatic correction is neutral and collapsed, with recovery and exhaustion history", () => {
for (const theme of [canvasThemes.dark, canvasThemes.light]) {
for (const status of ["retrying", "recovered", "exhausted"]) {
const html = renderToStaticMarkup();
expect(html).toContain("data-agent-tool-retry");
expect(html).toContain(" {
const html = renderToStaticMarkup();
expect(html).toContain("已获取可用模型");
expect(html).toContain('class="sr-only">已完成');
expect(html).not.toContain("agent-tool-label");
});
test("empty read and operation events stay flat instead of rendering empty cards", () => {
const readHtml = renderToStaticMarkup();
const operationHtml = renderToStaticMarkup();
expect(readHtml).toContain("agent-tool-row--plain");
expect(operationHtml).toContain("agent-tool-row--plain");
});
test("canvas reads show one node by default and expose the collapsed count", () => {
const html = renderToStaticMarkup( {}} />);
expect(html).toContain("读取了图片节点《第一个节点》");
expect(html).not.toContain("读取了文本节点《第二个节点》");
expect(html).toContain("已折叠 2 个节点,展开查看");
});
test("failed tools retain a visible failure label", () => {
const html = renderToStaticMarkup();
expect(html).toContain("agent-tool-label");
expect(html).toContain("执行失败");
});
test("long skill references wrap rather than truncate", () => {
const html = renderToStaticMarkup();
expect(html).toContain("references/storyboard-pass.md");
expect(html).toContain("break-words");
expect(html).not.toContain("truncate");
});
test("failed media shows its error and task identifier without hovering", () => {
const html = renderToStaticMarkup();
expect(html).toContain(">上游拒绝该生成规格");
expect(html).toContain("任务 ID:task-123");
});
test("canvas action trace is accessible and links to persisted node identities", () => {
const html = renderToStaticMarkup( {}} />);
expect(html).toContain('data-agent-node-id="video-1"');
expect(html).toContain('aria-label="在画布中定位满月动画"');
expect(html).toContain("创建了视频节点《满月动画》");
expect(html).toContain("引用了图片节点《满月照片》");
expect(html).not.toContain('disabled=""');
});
test("failed media trace retains node title and collapsible upstream details", () => {
const text = "上游拒绝规格:" + "错误详情".repeat(80);
const html = renderToStaticMarkup( {}} />);
expect(html).toContain("生成未完成:视频节点《满月动画》");
expect(html).toContain("查看完整错误详情");
expect(html).toContain("任务 ID:task-failed");
expect(html).toContain("