Files
openclaw/src/plugins/agent-tool-result-middleware.test.ts
Naka Masato 68dbf92281 fix(plugins): scope Codex relay with tool matchers (#109603)
* 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>
2026-07-30 01:39:08 +08:00

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,
);
});
});