Files
next-tjwater-agent/tests/frontendAction/command.test.ts
T
jiang 6336157ff4
Generic Container CI/CD / test-build-publish (push) Successful in 1m6s
Agent CI/CD / build-test-publish-and-deploy (push) Successful in 1m7s
feat: upgrade investigation and presentation runtime
2026-10-30 17:30:19 +08:00

46 lines
2.8 KiB
TypeScript

import { describe, expect, it } from "bun:test";
import presentView from "../../.opencode/tools/present_view.js";
import { taskPublicationCommandSchema } from "../../.opencode/tools/task-publication-schema.js";
import { viewCommandSchema } from "../../src/frontendAction/command.js";
import { taskPresentationCommandSchema } from "../../src/product/task-presentation.js";
import { frontendActionResultSchema } from "../../src/frontendAction/coordinator.js";
const data = { type: "FeatureCollection", features: [{ type: "Feature", geometry: { type: "Point", coordinates: [121, 31] }, properties: { value: 0.4 } }] };
const chart = { title: "压力", chart_type: "line", x_data: ["10:00"], series: [{ name: "MP01", data: [0.4] }] };
const commands = [
{ action: "locate_features", layer: "pipes", feature_ids: ["P1"] },
{ action: "zoom_to_map", center: [121, 31], zoom: 14 },
{ action: "highlight_features", layer: "pipes", feature_ids: ["P1"], effect: "pulse" },
{ action: "clear_highlights" },
{ action: "open_chart", chart_id: "pressure", chart, evidence_refs: ["E1"] },
{ action: "close_chart", chart_id: "pressure" },
{ action: "set_overlay", overlay_id: "points", title: "证据", mode: "geometry", evidence_id: "E1", data },
{ action: "clear_overlay", overlay_id: "points" },
{ action: "render_scada_analysis", items: [{ device_id: "MP01", level: "high" }] },
{ action: "clear_scada_analysis" },
];
describe("unified view commands", () => {
it("uses identical native and host command definitions for every action", () => {
for (const command of commands) {
expect(presentView.args.command.parse(command)).toEqual(viewCommandSchema.parse(command));
expect(taskPublicationCommandSchema.parse(command)).toEqual(taskPresentationCommandSchema.parse(command));
}
});
it("requires resolved chat overlays and evidence-backed task charts", () => {
const { data: _data, ...unresolved } = commands[6];
expect(viewCommandSchema.safeParse(unresolved).success).toBeFalse();
expect(taskPresentationCommandSchema.safeParse(unresolved).success).toBeTrue();
expect(viewCommandSchema.safeParse({ ...commands[4], evidence_refs: [] }).success).toBeTrue();
expect(taskPresentationCommandSchema.safeParse({ ...commands[4], evidence_refs: [] }).success).toBeFalse();
});
it("rejects old envelopes, unknown fields, scripts, nonfinite numbers and old receipts", () => {
for (const command of [
{ name: "locate_features", params: { layer: "pipes", feature_ids: ["P1"] } },
{ action: "show_chart", ...chart },
{ ...commands[1], zoom: Infinity },
{ ...commands[6], script: "alert(1)" },
]) expect(viewCommandSchema.safeParse(command).success).toBeFalse();
expect(frontendActionResultSchema.safeParse({ version: "frontend-action-result@1", actionId: "a", status: "succeeded", completedAt: Date.now() }).success).toBeFalse();
});
});