File size: 2,321 Bytes
fcd8223 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | // 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,
);
});
});
|