Merge remote-tracking branch 'origin/pr-585' into codex/pr-557-589-security-integration

This commit is contained in:
ddCat
2026-09-22 11:10:48 +08:00
6 changed files with 514 additions and 79 deletions

View File

@@ -1,5 +1,5 @@
import { describe, expect, it } from "bun:test";
import { agentToolCategory, agentToolCategoryLabel, agentToolStatus, friendlyAgentToolSummary } from "@/lib/canvas/agent-tool-presentation";
import { agentToolCategory, agentToolCategoryLabel, agentToolErrorClassLabel, agentToolStatus, friendlyAgentToolSummary } from "@/lib/canvas/agent-tool-presentation";
describe("Agent tool presentation", () => {
it("separates read, create, and canvas operation activity", () => {
@@ -43,3 +43,15 @@ describe("Agent tool presentation", () => {
expect(friendlyAgentToolSummary("canvas_get_state", "无法访问", { eventType: "tool_failed" })).toBe("获取画布内容失败");
});
});
describe("Agent tool error classification", () => {
it("maps backend errorClass to a human label, with a local fallback", () => {
expect(agentToolErrorClassLabel({ errorClass: "schema_error" })).toBe("参数不符合契约");
expect(agentToolErrorClassLabel({ result: { errorClass: "state_conflict" } })).toBe("画布状态已变化");
expect(agentToolErrorClassLabel({ errorClass: "permission_violation", errorClassLabel: "超出本轮权限" })).toBe("超出本轮权限");
expect(agentToolErrorClassLabel({ result: { errorClass: "upstream_failure" } })).toBe("上游故障");
expect(agentToolErrorClassLabel({ errorClass: "invalid_model_output" })).toBe("模型输出问题");
expect(agentToolErrorClassLabel({ errorClass: "unknown_new_class" })).toBe("工具执行失败");
expect(agentToolErrorClassLabel({ text: "没有归类" })).toBeUndefined();
});
});