mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-05 18:11:48 +00:00
* fix(plugins): scope Codex relay matchers Co-authored-by: Masato Naka <masatonaka1989@gmail.com> * fix(plugins): reject sparse tool hook matchers * test(plugins): cover mixed relay matcher scopes * fix(plugins): fail closed on invalid policy matchers * test(plugins): prove composed relay policy scope * fix(plugins): keep matcher scope internal * fix(plugins): satisfy matcher static checks * fix(plugins): enforce canonical tool hook matchers * fix(codex): project native hook matcher aliases * fix(plugins): scope Codex relay with tool matchers * chore: keep release changelog maintainer-owned --------- Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
63 lines
2.3 KiB
TypeScript
63 lines
2.3 KiB
TypeScript
// Covers plugin middleware that can transform agent tool results.
|
|
import { describe, expect, it } from "vitest";
|
|
import {
|
|
agentToolResultMiddlewareRegistrationCoversTool,
|
|
appendAgentToolResultMiddlewareScope,
|
|
normalizeAgentToolResultMiddlewareRuntimeIds,
|
|
normalizeAgentToolResultMiddlewareRuntimes,
|
|
} from "./agent-tool-result-middleware.js";
|
|
import type { PluginAgentToolResultMiddlewareRegistration } from "./registry-types.js";
|
|
|
|
describe("normalizeAgentToolResultMiddlewareRuntimes", () => {
|
|
it("defaults omitted runtimes to every supported runtime", () => {
|
|
expect(normalizeAgentToolResultMiddlewareRuntimes()).toEqual(["openclaw", "codex"]);
|
|
});
|
|
|
|
it("preserves an explicit empty runtime list", () => {
|
|
expect(normalizeAgentToolResultMiddlewareRuntimes({ runtimes: [] })).toEqual([]);
|
|
});
|
|
|
|
it("ignores unknown runtime ids from manifest metadata", () => {
|
|
expect(normalizeAgentToolResultMiddlewareRuntimeIds(["codex-app-server", "openclaw"])).toEqual([
|
|
"openclaw",
|
|
]);
|
|
});
|
|
});
|
|
|
|
describe("agent tool result middleware scopes", () => {
|
|
it("keeps runtime and matcher registrations paired without cross-products", () => {
|
|
const handler = () => undefined;
|
|
const registration: PluginAgentToolResultMiddlewareRegistration = {
|
|
pluginId: "policy",
|
|
rawHandler: handler,
|
|
handler,
|
|
runtimes: ["codex"],
|
|
scopes: [{ runtimes: ["codex"], matcher: ["exec"] }],
|
|
source: "test",
|
|
};
|
|
appendAgentToolResultMiddlewareScope(registration, {
|
|
runtimes: ["openclaw"],
|
|
matcher: ["apply_patch"],
|
|
});
|
|
|
|
expect(agentToolResultMiddlewareRegistrationCoversTool(registration, "codex", "exec")).toBe(
|
|
true,
|
|
);
|
|
expect(agentToolResultMiddlewareRegistrationCoversTool(registration, "codex", "Bash")).toBe(
|
|
false,
|
|
);
|
|
expect(
|
|
agentToolResultMiddlewareRegistrationCoversTool(registration, "codex", "apply_patch"),
|
|
).toBe(false);
|
|
expect(
|
|
agentToolResultMiddlewareRegistrationCoversTool(registration, "openclaw", "apply_patch"),
|
|
).toBe(true);
|
|
expect(agentToolResultMiddlewareRegistrationCoversTool(registration, "openclaw", "Write")).toBe(
|
|
false,
|
|
);
|
|
expect(agentToolResultMiddlewareRegistrationCoversTool(registration, "openclaw", "exec")).toBe(
|
|
false,
|
|
);
|
|
});
|
|
});
|