mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 19:54:57 +00:00
feat(sandbox): add sandbox explain inspector
This commit is contained in:
49
src/commands/sandbox-explain.test.ts
Normal file
49
src/commands/sandbox-explain.test.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
let mockCfg: unknown = {};
|
||||
|
||||
vi.mock("../config/config.js", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("../config/config.js")>();
|
||||
return {
|
||||
...actual,
|
||||
loadConfig: vi.fn().mockImplementation(() => mockCfg),
|
||||
};
|
||||
});
|
||||
|
||||
describe("sandbox explain command", () => {
|
||||
it("prints JSON shape + fix-it keys", async () => {
|
||||
mockCfg = {
|
||||
agents: {
|
||||
defaults: {
|
||||
sandbox: { mode: "all", scope: "agent", workspaceAccess: "none" },
|
||||
},
|
||||
},
|
||||
tools: {
|
||||
sandbox: { tools: { deny: ["browser"] } },
|
||||
elevated: { enabled: true, allowFrom: { whatsapp: ["*"] } },
|
||||
},
|
||||
session: { store: "/tmp/clawdbot-test-sessions-{agentId}.json" },
|
||||
};
|
||||
|
||||
const { sandboxExplainCommand } = await import("./sandbox-explain.js");
|
||||
|
||||
const logs: string[] = [];
|
||||
await sandboxExplainCommand(
|
||||
{ json: true, session: "agent:main:main" },
|
||||
{
|
||||
log: (msg: string) => logs.push(msg),
|
||||
error: (msg: string) => logs.push(msg),
|
||||
exit: (_code: number) => {},
|
||||
} as unknown as Parameters<typeof sandboxExplainCommand>[1],
|
||||
);
|
||||
|
||||
const out = logs.join("");
|
||||
const parsed = JSON.parse(out);
|
||||
expect(parsed).toHaveProperty("docsUrl", "https://docs.clawd.bot/sandbox");
|
||||
expect(parsed).toHaveProperty("sandbox.mode", "all");
|
||||
expect(parsed).toHaveProperty("sandbox.tools.sources.allow.source");
|
||||
expect(Array.isArray(parsed.fixIt)).toBe(true);
|
||||
expect(parsed.fixIt).toContain("agents.defaults.sandbox.mode=off");
|
||||
expect(parsed.fixIt).toContain("tools.sandbox.tools.deny");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user