From a4b4c2c1ea949117608d0ac1a412f9879c525eae Mon Sep 17 00:00:00 2001 From: Carlos Villela Date: Sun, 9 Aug 2026 11:39:18 -0700 Subject: [PATCH] test(onboard): opt fixtures into required prebuild --- ...oard-extra-provider-reconciliation.test.ts | 1 + test/onboard-installer-restore-intent.test.ts | 1 + test/onboard-messaging.test.ts | 34 +++++++++---------- test/onboard-reservation-recreate.test.ts | 1 + test/onboard-sandbox-build.test.ts | 3 +- test/onboard-sandbox-recreation.test.ts | 10 ++++++ 6 files changed, 32 insertions(+), 18 deletions(-) diff --git a/test/onboard-extra-provider-reconciliation.test.ts b/test/onboard-extra-provider-reconciliation.test.ts index aa92d12a3ba..31d89be9a5f 100644 --- a/test/onboard-extra-provider-reconciliation.test.ts +++ b/test/onboard-extra-provider-reconciliation.test.ts @@ -145,6 +145,7 @@ const { createSandbox } = require(${onboardPath}); PATH: `${fakeBin}:${process.env.PATH || ""}`, NEMOCLAW_NON_INTERACTIVE: "1", NEMOCLAW_TEST_MANAGED_IMAGE_FALLBACK: "1", + NEMOCLAW_SANDBOX_PREBUILD: "1", OPENSHELL_GATEWAY_ENDPOINT: undefined, }, }); diff --git a/test/onboard-installer-restore-intent.test.ts b/test/onboard-installer-restore-intent.test.ts index e00d5238af9..8e5067bb558 100644 --- a/test/onboard-installer-restore-intent.test.ts +++ b/test/onboard-installer-restore-intent.test.ts @@ -184,6 +184,7 @@ const MARKER_SHA = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852 PATH: `${fakeBin}:${process.env.PATH || ""}`, NEMOCLAW_NON_INTERACTIVE: "1", NEMOCLAW_TEST_MANAGED_IMAGE_FALLBACK: "1", + NEMOCLAW_SANDBOX_PREBUILD: "1", }; delete env["NEMOCLAW_RECREATE_SANDBOX"]; const result = spawnSync(process.execPath, [scriptPath], { diff --git a/test/onboard-messaging.test.ts b/test/onboard-messaging.test.ts index 8d71f0130b2..bb973affa9c 100644 --- a/test/onboard-messaging.test.ts +++ b/test/onboard-messaging.test.ts @@ -46,6 +46,7 @@ const onboardScriptMocksPath = JSON.stringify( ); beforeEach(() => { vi.stubEnv("NEMOCLAW_TEST_MANAGED_IMAGE_FALLBACK", "1"); + vi.stubEnv("NEMOCLAW_SANDBOX_PREBUILD", "1"); }); describe("onboard messaging", () => { it("creates providers for messaging tokens and attaches them to the sandbox", { @@ -513,7 +514,7 @@ const childProcess = require("node:child_process"); const { EventEmitter } = require("node:events"); const fs = require("node:fs"); -const commands = []; +const commands = []; let dockerfileContent; const registerCalls = []; registry.registerSandbox({ name: "my-assistant", @@ -556,15 +557,15 @@ childProcess.spawn = (...args) => { child.pid = 4242; const command = _n([args[0], ...(Array.isArray(args[1]) ? args[1] : [])]); const entry = { command, env: args[2]?.env || null }; - const dockerfileMatch = command.match(/--from ([^ ]+Dockerfile)/); + const dockerfileMatch = command.match(/(?:--from|-f) ([^ ]+Dockerfile)/); if (dockerfileMatch) { try { - entry.dockerfileContent = fs.readFileSync(dockerfileMatch[1], "utf-8"); + entry.dockerfileContent = dockerfileContent = fs.readFileSync(dockerfileMatch[1], "utf-8"); } catch (error) { entry.dockerfileReadError = String(error); } } - commands.push(entry); + commands.push({ ...entry, dockerfileContent: entry.dockerfileContent ?? dockerfileContent }); process.nextTick(() => { child.stdout.emit("data", Buffer.from("Created sandbox: my-assistant\n")); child.emit("close", 0); @@ -628,7 +629,6 @@ const { createSandbox } = require(${onboardPath}); assert.match(createCommand.command, /--provider my-assistant-discord-bridge/); assert.match(createCommand.command, /--provider my-assistant-slack-bridge/); assert.match(createCommand.command, /--provider my-assistant-slack-app/); - assert.deepEqual(activeChannelsFromDockerfile(createCommand.dockerfileContent), [ "discord", "slack", @@ -674,7 +674,7 @@ const childProcess = require("node:child_process"); const { EventEmitter } = require("node:events"); const fs = require("node:fs"); -const commands = []; +const commands = []; let dockerfileContent; const registerCalls = []; registry.registerSandbox({ name: "my-assistant", @@ -715,15 +715,15 @@ childProcess.spawn = (...args) => { child.pid = 4242; const command = _n([args[0], ...(Array.isArray(args[1]) ? args[1] : [])]); const entry = { command, env: args[2]?.env || null }; - const dockerfileMatch = command.match(/--from ([^ ]+Dockerfile)/); + const dockerfileMatch = command.match(/(?:--from|-f) ([^ ]+Dockerfile)/); if (dockerfileMatch) { try { - entry.dockerfileContent = fs.readFileSync(dockerfileMatch[1], "utf-8"); + entry.dockerfileContent = dockerfileContent = fs.readFileSync(dockerfileMatch[1], "utf-8"); } catch (error) { entry.dockerfileReadError = String(error); } } - commands.push(entry); + commands.push({ ...entry, dockerfileContent: entry.dockerfileContent ?? dockerfileContent }); process.nextTick(() => { child.stdout.emit("data", Buffer.from("Created sandbox: my-assistant\n")); child.emit("close", 0); @@ -827,7 +827,7 @@ const childProcess = require("node:child_process"); const { EventEmitter } = require("node:events"); const fs = require("node:fs"); -const commands = []; +const commands = []; let dockerfileContent; const registerCalls = []; runner.run = (command, opts = {}) => { const normalized = _n(command); @@ -863,15 +863,15 @@ childProcess.spawn = (...args) => { child.pid = 4242; const command = _n([args[0], ...(Array.isArray(args[1]) ? args[1] : [])]); const entry = { command, env: args[2]?.env || null }; - const dockerfileMatch = command.match(/--from ([^ ]+Dockerfile)/); + const dockerfileMatch = command.match(/(?:--from|-f) ([^ ]+Dockerfile)/); if (dockerfileMatch) { try { - entry.dockerfileContent = fs.readFileSync(dockerfileMatch[1], "utf-8"); + entry.dockerfileContent = dockerfileContent = fs.readFileSync(dockerfileMatch[1], "utf-8"); } catch (error) { entry.dockerfileReadError = String(error); } } - commands.push(entry); + commands.push({ ...entry, dockerfileContent: entry.dockerfileContent ?? dockerfileContent }); process.nextTick(() => { child.stdout.emit("data", Buffer.from("Created sandbox: my-assistant\n")); child.emit("close", 0); @@ -982,7 +982,7 @@ registry.registerSandbox({ messaging: { schemaVersion: 1, plan: ${messagingPlanLiteral(["whatsapp"], ["whatsapp"])} }, }); -const commands = []; +const commands = []; let dockerfileContent; const registerCalls = []; runner.run = (command, opts = {}) => { const normalized = _n(command); @@ -1018,15 +1018,15 @@ childProcess.spawn = (...args) => { child.pid = 4242; const command = _n([args[0], ...(Array.isArray(args[1]) ? args[1] : [])]); const entry = { command, env: args[2]?.env || null }; - const dockerfileMatch = command.match(/--from ([^ ]+Dockerfile)/); + const dockerfileMatch = command.match(/(?:--from|-f) ([^ ]+Dockerfile)/); if (dockerfileMatch) { try { - entry.dockerfileContent = fs.readFileSync(dockerfileMatch[1], "utf-8"); + entry.dockerfileContent = dockerfileContent = fs.readFileSync(dockerfileMatch[1], "utf-8"); } catch (error) { entry.dockerfileReadError = String(error); } } - commands.push(entry); + commands.push({ ...entry, dockerfileContent: entry.dockerfileContent ?? dockerfileContent }); process.nextTick(() => { child.stdout.emit("data", Buffer.from("Created sandbox: my-assistant\n")); child.emit("close", 0); diff --git a/test/onboard-reservation-recreate.test.ts b/test/onboard-reservation-recreate.test.ts index 38d87768f54..8dd7a91c68e 100644 --- a/test/onboard-reservation-recreate.test.ts +++ b/test/onboard-reservation-recreate.test.ts @@ -139,6 +139,7 @@ const { createSandbox } = require(${onboardPath}); env: workspaceEnv(workspace, { NEMOCLAW_NON_INTERACTIVE: "1", NEMOCLAW_TEST_MANAGED_IMAGE_FALLBACK: "1", + NEMOCLAW_SANDBOX_PREBUILD: "1", }), }); diff --git a/test/onboard-sandbox-build.test.ts b/test/onboard-sandbox-build.test.ts index 0c76ed4f408..62b05c567be 100644 --- a/test/onboard-sandbox-build.test.ts +++ b/test/onboard-sandbox-build.test.ts @@ -18,6 +18,7 @@ import { beforeEach(() => { vi.stubEnv("NEMOCLAW_TEST_MANAGED_IMAGE_FALLBACK", "1"); + vi.stubEnv("NEMOCLAW_SANDBOX_PREBUILD", "1"); }); describe("onboard helpers", () => { @@ -448,7 +449,7 @@ sandboxBaseImage.resolveSandboxBaseImage = (options) => { }; }; buildContext.stageOptimizedSandboxBuildContext = () => { - const buildCtx = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-openclaw-build-")); + const buildCtx = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-build-")); const stagedDockerfile = path.join(buildCtx, "Dockerfile"); fs.writeFileSync( stagedDockerfile, diff --git a/test/onboard-sandbox-recreation.test.ts b/test/onboard-sandbox-recreation.test.ts index a8046246878..16b05615715 100644 --- a/test/onboard-sandbox-recreation.test.ts +++ b/test/onboard-sandbox-recreation.test.ts @@ -13,6 +13,7 @@ import { type CommandEntry, onboardScriptMocksPath } from "./helpers/onboard-spl beforeEach(() => { vi.stubEnv("NEMOCLAW_TEST_MANAGED_IMAGE_FALLBACK", "1"); + vi.stubEnv("NEMOCLAW_SANDBOX_PREBUILD", "1"); }); describe("onboard helpers", () => { @@ -1189,6 +1190,9 @@ const { createSandbox } = require(${onboardPath}); const credentialsPath = JSON.stringify( path.join(repoRoot, "src", "lib", "credentials", "store.ts"), ); + const dockerExecPath = JSON.stringify( + path.join(repoRoot, "src", "lib", "adapters", "docker", "exec.ts"), + ); fs.mkdirSync(fakeBin, { recursive: true }); writeOkOpenshell(fakeBin); @@ -1203,6 +1207,12 @@ const preflight = require(${preflightPath}); const credentials = require(${credentialsPath}); const childProcess = require("node:child_process"); const { EventEmitter } = require("node:events"); +const dockerExec = require(${dockerExecPath}); +dockerExec.dockerSpawn = () => { + const child = new EventEmitter(); + process.nextTick(() => child.emit("close", 0)); + return child; +}; const fs = require("node:fs"); const commands = [];