test: collapse sandbox agent config duplicate cases

This commit is contained in:
Peter Steinberger
2026-02-23 22:01:32 +00:00
parent 287586206c
commit c248c515a3

View File

@@ -250,25 +250,28 @@ describe("Agent-specific sandbox config", () => {
expect(context?.enabled).toBe(true); expect(context?.enabled).toBe(true);
}); });
it("should allow agent-specific docker setupCommand overrides", async () => { it("should resolve setupCommand overrides based on sandbox scope", async () => {
const cfg = createWorkSetupCommandConfig("agent"); for (const scenario of [
{
scope: "agent" as const,
expectedSetup: "echo work",
expectedContainerFragment: "agent-work",
},
{
scope: "shared" as const,
expectedSetup: "echo global",
expectedContainerFragment: "shared",
},
]) {
const cfg = createWorkSetupCommandConfig(scenario.scope);
const context = await resolveContext(cfg, "agent:work:main", "/tmp/test-work"); const context = await resolveContext(cfg, "agent:work:main", "/tmp/test-work");
expect(context).toBeDefined(); expect(context).toBeDefined();
expect(context?.docker.setupCommand).toBe("echo work"); expect(context?.docker.setupCommand).toBe(scenario.expectedSetup);
expectDockerSetupCommand("echo work"); expect(context?.containerName).toContain(scenario.expectedContainerFragment);
}); expectDockerSetupCommand(scenario.expectedSetup);
spawnCalls.length = 0;
it("should ignore agent-specific docker overrides when scope is shared", async () => { }
const cfg = createWorkSetupCommandConfig("shared");
const context = await resolveContext(cfg, "agent:work:main", "/tmp/test-work");
expect(context).toBeDefined();
expect(context?.docker.setupCommand).toBe("echo global");
expect(context?.containerName).toContain("shared");
expectDockerSetupCommand("echo global");
}); });
it("should allow agent-specific docker settings beyond setupCommand", async () => { it("should allow agent-specific docker settings beyond setupCommand", async () => {
@@ -308,8 +311,10 @@ describe("Agent-specific sandbox config", () => {
expect(context?.docker.network).toBe("bridge"); expect(context?.docker.network).toBe("bridge");
}); });
it("should override with agent-specific sandbox mode 'off'", async () => { it("should honor agent-specific sandbox mode overrides", async () => {
const cfg: OpenClawConfig = { for (const scenario of [
{
cfg: {
agents: { agents: {
defaults: { defaults: {
sandbox: { sandbox: {
@@ -327,15 +332,15 @@ describe("Agent-specific sandbox config", () => {
}, },
], ],
}, },
}; } satisfies OpenClawConfig,
sessionKey: "agent:main:main",
const context = await resolveContext(cfg, "agent:main:main", "/tmp/test"); workspaceDir: "/tmp/test",
assert: (context: Awaited<ReturnType<typeof resolveContext>>) => {
expect(context).toBeNull(); expect(context).toBeNull();
}); },
},
it("should use agent-specific sandbox mode 'all'", async () => { {
const cfg: OpenClawConfig = { cfg: {
agents: { agents: {
defaults: { defaults: {
sandbox: { sandbox: {
@@ -353,16 +358,22 @@ describe("Agent-specific sandbox config", () => {
}, },
], ],
}, },
}; } satisfies OpenClawConfig,
sessionKey: "agent:family:whatsapp:group:123",
const context = await resolveContext( workspaceDir: "/tmp/test-family",
cfg, assert: (context: Awaited<ReturnType<typeof resolveContext>>) => {
"agent:family:whatsapp:group:123",
"/tmp/test-family",
);
expect(context).toBeDefined(); expect(context).toBeDefined();
expect(context?.enabled).toBe(true); expect(context?.enabled).toBe(true);
},
},
]) {
const context = await resolveContext(
scenario.cfg,
scenario.sessionKey,
scenario.workspaceDir,
);
scenario.assert(context);
}
}); });
it("should use agent-specific scope", async () => { it("should use agent-specific scope", async () => {
@@ -393,22 +404,14 @@ describe("Agent-specific sandbox config", () => {
expect(context?.containerName).toContain("agent-work"); expect(context?.containerName).toContain("agent-work");
}); });
it("includes session_status in default sandbox allowlist", async () => { it("enforces required allowlist tools in default and explicit sandbox configs", async () => {
const cfg = createDefaultsSandboxConfig(); for (const scenario of [
{
const sandbox = resolveSandboxConfigForAgent(cfg, "main"); cfg: createDefaultsSandboxConfig(),
expect(sandbox.tools.allow).toContain("session_status"); expected: ["session_status", "image"],
}); },
{
it("includes image in default sandbox allowlist", async () => { cfg: {
const cfg = createDefaultsSandboxConfig();
const sandbox = resolveSandboxConfigForAgent(cfg, "main");
expect(sandbox.tools.allow).toContain("image");
});
it("injects image into explicit sandbox allowlists", async () => {
const cfg: OpenClawConfig = {
tools: { tools: {
sandbox: { sandbox: {
tools: { tools: {
@@ -425,9 +428,14 @@ describe("Agent-specific sandbox config", () => {
}, },
}, },
}, },
}; } satisfies OpenClawConfig,
expected: ["image"],
const sandbox = resolveSandboxConfigForAgent(cfg, "main"); },
expect(sandbox.tools.allow).toContain("image"); ]) {
const sandbox = resolveSandboxConfigForAgent(scenario.cfg, "main");
for (const tool of scenario.expected) {
expect(sandbox.tools.allow).toContain(tool);
}
}
}); });
}); });