test: strengthen ports, tool policy, and note wrapping

This commit is contained in:
Peter Steinberger
2026-02-16 01:31:06 +00:00
parent f50e1e8015
commit 4d9e310dad
3 changed files with 102 additions and 4 deletions

View File

@@ -1,6 +1,14 @@
import { describe, expect, it } from "vitest";
import type { AnyAgentTool } from "./tools/common.js";
import { TOOL_POLICY_CONFORMANCE } from "./tool-policy.conformance.js";
import { expandToolGroups, resolveToolProfilePolicy, TOOL_GROUPS } from "./tool-policy.js";
import {
applyOwnerOnlyToolPolicy,
expandToolGroups,
isOwnerOnlyToolName,
normalizeToolName,
resolveToolProfilePolicy,
TOOL_GROUPS,
} from "./tool-policy.js";
describe("tool-policy", () => {
it("expands groups and normalizes aliases", () => {
@@ -28,6 +36,53 @@ describe("tool-policy", () => {
expect(group).toContain("subagents");
expect(group).toContain("session_status");
});
it("normalizes tool names and aliases", () => {
expect(normalizeToolName(" BASH ")).toBe("exec");
expect(normalizeToolName("apply-patch")).toBe("apply_patch");
expect(normalizeToolName("READ")).toBe("read");
});
it("identifies owner-only tools", () => {
expect(isOwnerOnlyToolName("whatsapp_login")).toBe(true);
expect(isOwnerOnlyToolName("read")).toBe(false);
});
it("strips owner-only tools for non-owner senders", async () => {
const tools = [
{
name: "read",
// oxlint-disable-next-line typescript/no-explicit-any
execute: async () => ({ content: [], details: {} }) as any,
},
{
name: "whatsapp_login",
// oxlint-disable-next-line typescript/no-explicit-any
execute: async () => ({ content: [], details: {} }) as any,
},
] as unknown as AnyAgentTool[];
const filtered = applyOwnerOnlyToolPolicy(tools, false);
expect(filtered.map((t) => t.name)).toEqual(["read"]);
});
it("keeps owner-only tools for the owner sender", async () => {
const tools = [
{
name: "read",
// oxlint-disable-next-line typescript/no-explicit-any
execute: async () => ({ content: [], details: {} }) as any,
},
{
name: "whatsapp_login",
// oxlint-disable-next-line typescript/no-explicit-any
execute: async () => ({ content: [], details: {} }) as any,
},
] as unknown as AnyAgentTool[];
const filtered = applyOwnerOnlyToolPolicy(tools, true);
expect(filtered.map((t) => t.name)).toEqual(["read", "whatsapp_login"]);
});
});
describe("TOOL_POLICY_CONFORMANCE", () => {