Files
moltbot/src/agents/sandbox-tool-policy.test.ts
Agustin Rivera 193fdd6e3b fix(policy): preserve restrictive tool allowlists (#58476)
* fix(policy): preserve restrictive tool allowlists

Co-authored-by: David Silva <david.silva@gendigital.com>

* fix(policy): address review follow-ups

* fix(policy): restore additive alsoAllow semantics

* fix(policy): preserve optional tool opt-ins for allow-all configs

* fix(policy): narrow plugin-only allowlist warnings

* fix(policy): add changelog entry

* Revert "fix(policy): add changelog entry"

This reverts commit 4a996bf4caedfe8c9ff3a7f190816e657ead5d10.

* chore: add changelog for restrictive tool allowlists

---------

Co-authored-by: David Silva <david.silva@gendigital.com>
Co-authored-by: Devin Robison <drobison@nvidia.com>
2026-04-02 12:55:36 -06:00

81 lines
2.1 KiB
TypeScript

import { describe, expect, it } from "vitest";
import type { OpenClawConfig } from "../config/config.js";
import { resolveEffectiveToolPolicy } from "./pi-tools.policy.js";
import { pickSandboxToolPolicy } from "./sandbox-tool-policy.js";
import { resolveEffectiveToolFsRootExpansionAllowed } from "./tool-fs-policy.js";
describe("pickSandboxToolPolicy", () => {
it("returns undefined when neither allow nor deny is configured", () => {
expect(pickSandboxToolPolicy({})).toBeUndefined();
});
it("keeps alsoAllow without allow additive", () => {
expect(
pickSandboxToolPolicy({
alsoAllow: ["web_search"],
}),
).toEqual({
allow: ["*", "web_search"],
deny: undefined,
});
});
it("merges allow and alsoAllow when both are present", () => {
expect(
pickSandboxToolPolicy({
allow: ["read"],
alsoAllow: ["write"],
}),
).toEqual({
allow: ["read", "write"],
deny: undefined,
});
});
it("preserves allow-all semantics for allow: [] plus alsoAllow", () => {
expect(
pickSandboxToolPolicy({
allow: [],
alsoAllow: ["web_search"],
}),
).toEqual({
allow: ["*", "web_search"],
deny: undefined,
});
});
it("passes deny through unchanged", () => {
expect(
pickSandboxToolPolicy({
deny: ["exec"],
}),
).toEqual({
allow: undefined,
deny: ["exec"],
});
});
it("keeps global alsoAllow additive in effective tool policy resolution", () => {
const cfg: OpenClawConfig = {
tools: {
profile: "coding",
alsoAllow: ["lobster"],
},
};
const resolved = resolveEffectiveToolPolicy({ config: cfg, agentId: "main" });
expect(resolved.globalPolicy).toEqual({ allow: ["*", "lobster"], deny: undefined });
expect(resolved.profileAlsoAllow).toEqual(["lobster"]);
});
it("does not block fs root expansion when only global alsoAllow is configured", () => {
const cfg: OpenClawConfig = {
tools: {
alsoAllow: ["lobster"],
},
};
expect(resolveEffectiveToolFsRootExpansionAllowed({ cfg, agentId: "main" })).toBe(true);
});
});