mirror of
https://github.com/moltbot/moltbot.git
synced 2026-04-24 23:21:30 +00:00
* 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>
81 lines
2.1 KiB
TypeScript
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);
|
|
});
|
|
});
|