mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 10:10:45 +00:00
test: share sandbox docker create fixture
This commit is contained in:
@@ -157,6 +157,29 @@ function createSandboxConfig(
|
||||
};
|
||||
}
|
||||
|
||||
async function ensureSandboxCreateCallForTest(params: {
|
||||
cfg: SandboxConfig;
|
||||
workspaceDir?: string;
|
||||
sessionKey?: string;
|
||||
}): Promise<SpawnCall> {
|
||||
const workspaceDir = params.workspaceDir ?? "/tmp/workspace";
|
||||
await ensureSandboxContainer({
|
||||
sessionKey: params.sessionKey ?? "agent:main:session-1",
|
||||
workspaceDir,
|
||||
agentWorkspaceDir: workspaceDir,
|
||||
cfg: params.cfg,
|
||||
});
|
||||
|
||||
const createCall = spawnState.calls.find(
|
||||
(call) => call.command === "docker" && call.args[0] === "create",
|
||||
);
|
||||
expect(createCall).toBeDefined();
|
||||
if (!createCall) {
|
||||
throw new Error("expected docker create call");
|
||||
}
|
||||
return createCall;
|
||||
}
|
||||
|
||||
describe("ensureSandboxContainer config-hash recreation", () => {
|
||||
beforeEach(async () => {
|
||||
spawnState.calls.length = 0;
|
||||
@@ -259,20 +282,10 @@ describe("ensureSandboxContainer config-hash recreation", () => {
|
||||
],
|
||||
});
|
||||
|
||||
await ensureSandboxContainer({
|
||||
sessionKey: "agent:main:session-1",
|
||||
workspaceDir,
|
||||
agentWorkspaceDir: workspaceDir,
|
||||
cfg,
|
||||
});
|
||||
const createCall = await ensureSandboxCreateCallForTest({ cfg, workspaceDir });
|
||||
expect(createCall.args).toContain(`openclaw.configHash=${expectedHash}`);
|
||||
|
||||
const createCall = spawnState.calls.find(
|
||||
(call) => call.command === "docker" && call.args[0] === "create",
|
||||
);
|
||||
expect(createCall).toBeDefined();
|
||||
expect(createCall?.args).toContain(`openclaw.configHash=${expectedHash}`);
|
||||
|
||||
const bindArgs = collectDockerFlagValues(createCall?.args ?? [], "-v");
|
||||
const bindArgs = collectDockerFlagValues(createCall.args, "-v");
|
||||
const workspaceMountIdx = bindArgs.indexOf("/tmp/workspace:/workspace:z");
|
||||
const customMountIdx = bindArgs.indexOf("/tmp/workspace-shared/USER.md:/workspace/USER.md:ro");
|
||||
expect(workspaceMountIdx).toBeGreaterThanOrEqual(0);
|
||||
@@ -294,19 +307,9 @@ describe("ensureSandboxContainer config-hash recreation", () => {
|
||||
registryMocks.readRegistry.mockResolvedValue({ entries: [] });
|
||||
registryMocks.updateRegistry.mockResolvedValue(undefined);
|
||||
|
||||
await ensureSandboxContainer({
|
||||
sessionKey: "agent:main:session-1",
|
||||
workspaceDir,
|
||||
agentWorkspaceDir: workspaceDir,
|
||||
cfg,
|
||||
});
|
||||
const createCall = await ensureSandboxCreateCallForTest({ cfg, workspaceDir });
|
||||
|
||||
const createCall = spawnState.calls.find(
|
||||
(call) => call.command === "docker" && call.args[0] === "create",
|
||||
);
|
||||
expect(createCall).toBeDefined();
|
||||
|
||||
const bindArgs = collectDockerFlagValues(createCall?.args ?? [], "-v");
|
||||
const bindArgs = collectDockerFlagValues(createCall.args, "-v");
|
||||
expect(bindArgs).toContain(expectedMainMount);
|
||||
},
|
||||
);
|
||||
@@ -319,18 +322,8 @@ describe("ensureSandboxContainer config-hash recreation", () => {
|
||||
spawnState.labelHash = "";
|
||||
registryMocks.readRegistry.mockResolvedValue({ entries: [] });
|
||||
|
||||
await ensureSandboxContainer({
|
||||
sessionKey: "agent:main:session-1",
|
||||
workspaceDir,
|
||||
agentWorkspaceDir: workspaceDir,
|
||||
cfg,
|
||||
});
|
||||
|
||||
const createCall = spawnState.calls.find(
|
||||
(call) => call.command === "docker" && call.args[0] === "create",
|
||||
);
|
||||
expect(createCall).toBeDefined();
|
||||
expect(createCall?.args).toContain(
|
||||
const createCall = await ensureSandboxCreateCallForTest({ cfg, workspaceDir });
|
||||
expect(createCall.args).toContain(
|
||||
`openclaw.mountFormatVersion=${SANDBOX_MOUNT_FORMAT_VERSION}`,
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user