test(tools): cover tool policy helpers

This commit is contained in:
Peter Steinberger
2026-01-13 06:32:59 +00:00
parent 2ae3b45ac1
commit f50e06a1b6
2 changed files with 49 additions and 0 deletions

View File

@@ -631,6 +631,17 @@ describe("createClawdbotCodingTools", () => {
expect(names.has("browser")).toBe(false);
});
it("expands group shorthands in global tool deny policy", () => {
const tools = createClawdbotCodingTools({
config: { tools: { deny: ["group:fs"] } },
});
const names = new Set(tools.map((tool) => tool.name));
expect(names.has("read")).toBe(false);
expect(names.has("write")).toBe(false);
expect(names.has("edit")).toBe(false);
expect(names.has("exec")).toBe(true);
});
it("lets agent profiles override global profiles", () => {
const tools = createClawdbotCodingTools({
sessionKey: "agent:work:main",

View File

@@ -0,0 +1,38 @@
import { describe, expect, it } from "vitest";
import {
expandToolGroups,
resolveToolProfilePolicy,
TOOL_GROUPS,
} from "./tool-policy.js";
describe("tool-policy", () => {
it("expands groups and normalizes aliases", () => {
const expanded = expandToolGroups([
"group:runtime",
"BASH",
"apply-patch",
"group:fs",
]);
const set = new Set(expanded);
expect(set.has("exec")).toBe(true);
expect(set.has("bash")).toBe(true);
expect(set.has("process")).toBe(true);
expect(set.has("apply_patch")).toBe(true);
expect(set.has("read")).toBe(true);
expect(set.has("write")).toBe(true);
expect(set.has("edit")).toBe(true);
});
it("resolves known profiles and ignores unknown ones", () => {
const coding = resolveToolProfilePolicy("coding");
expect(coding?.allow).toContain("group:fs");
expect(resolveToolProfilePolicy("nope")).toBeUndefined();
});
it("includes core tool groups in group:clawdbot", () => {
const group = TOOL_GROUPS["group:clawdbot"];
expect(group).toContain("browser");
expect(group).toContain("message");
expect(group).toContain("session_status");
});
});