fix(agent): load frontend action plugin
This commit is contained in:
@@ -28,5 +28,8 @@
|
||||
},
|
||||
"edit": "ask"
|
||||
},
|
||||
"plugin": [
|
||||
"./.opencode/plugins/frontend-action-call-id.ts"
|
||||
],
|
||||
"default_agent": "instruction"
|
||||
}
|
||||
|
||||
@@ -1,8 +1,22 @@
|
||||
import { describe, expect, it } from "bun:test";
|
||||
import { readdirSync, readFileSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { frontendActionCallIdPlugin } from "../../.opencode/plugins/frontend-action-call-id.js";
|
||||
import { FRONTEND_ACTION_TOOLS, frontendActionCallIdPlugin } from "../../.opencode/plugins/frontend-action-call-id.js";
|
||||
import { frontendActionRegistry } from "../../src/frontendAction/registry.js";
|
||||
|
||||
const frontendActionToolNames = () => readdirSync(".opencode/tools")
|
||||
.filter((file) => file.endsWith(".ts"))
|
||||
.filter((file) => readFileSync(join(".opencode/tools", file), "utf8").includes("executeFrontendAction("))
|
||||
.map((file) => file.replace(/\.ts$/, ""))
|
||||
.sort();
|
||||
|
||||
describe("frontend action call ID plugin", () => {
|
||||
it("is registered in the OpenCode project config", () => {
|
||||
const config = JSON.parse(readFileSync("opencode.json", "utf8")) as { plugin?: unknown[] };
|
||||
expect(config.plugin).toContain("./.opencode/plugins/frontend-action-call-id.ts");
|
||||
});
|
||||
|
||||
it("overwrites forged IDs only for allowlisted tools", async () => {
|
||||
const hooks = await frontendActionCallIdPlugin({} as never);
|
||||
const before = hooks["tool.execute.before"];
|
||||
@@ -15,4 +29,10 @@ describe("frontend action call ID plugin", () => {
|
||||
await before({ tool: "web_search", sessionID: "session", callID: "ignored" }, ordinaryOutput);
|
||||
expect(ordinaryOutput.args).toEqual({ query: "water" });
|
||||
});
|
||||
|
||||
it("covers every tool that uses the frontend action bridge", () => {
|
||||
const bridgeTools = frontendActionToolNames();
|
||||
expect([...FRONTEND_ACTION_TOOLS].sort()).toEqual(bridgeTools);
|
||||
expect(frontendActionRegistry.map((action) => action.id).sort()).toEqual(bridgeTools);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user