43 lines
1.8 KiB
TypeScript
43 lines
1.8 KiB
TypeScript
import { describe, expect, it } from "bun:test";
|
|
|
|
import { tool } from "../../.opencode/tool.js";
|
|
import presentView from "../../.opencode/tools/present_view.js";
|
|
import { unwrapFrontendActionResult } from "../../.opencode/tools/frontend_action.js";
|
|
|
|
describe("frontend action tool bridge", () => {
|
|
it("accepts a presentation without a reason and trims optional explanations", () => {
|
|
const schema = tool.schema.object(presentView.args);
|
|
const command = { action: "clear_highlights" };
|
|
expect(schema.parse({ command })).toEqual({ command });
|
|
expect(schema.parse({ command, reason: " 清理上轮定位 " }).reason).toBe("清理上轮定位");
|
|
expect(schema.safeParse({ command, reason: " " }).success).toBeFalse();
|
|
});
|
|
|
|
it("returns only validated browser output for successful actions", () => {
|
|
expect(unwrapFrontendActionResult(JSON.stringify({
|
|
version: "frontend-action-result@2",
|
|
actionId: "action-1",
|
|
status: "succeeded",
|
|
output: { cleared: true },
|
|
completedAt: Date.now(),
|
|
}))).toBe('{"cleared":true}');
|
|
});
|
|
|
|
it("throws the browser error for failed and expired actions", () => {
|
|
expect(() => unwrapFrontendActionResult(JSON.stringify({
|
|
version: "frontend-action-result@2",
|
|
actionId: "action-1",
|
|
status: "failed",
|
|
error: { code: "WFS_UNAVAILABLE", message: "SCADA geometry query failed" },
|
|
completedAt: Date.now(),
|
|
}))).toThrow("WFS_UNAVAILABLE: SCADA geometry query failed");
|
|
expect(() => unwrapFrontendActionResult(JSON.stringify({
|
|
version: "frontend-action-result@2",
|
|
actionId: "action-2",
|
|
status: "expired",
|
|
error: { code: "ACTION_TIMEOUT", message: "browser action timed out" },
|
|
completedAt: Date.now(),
|
|
}))).toThrow("ACTION_TIMEOUT: browser action timed out");
|
|
});
|
|
});
|