From 4000d3d4512616fdf43b6c4a891901a23961b04d Mon Sep 17 00:00:00 2001 From: Julie Yaunches Date: Wed, 10 Jun 2026 00:35:18 -0400 Subject: [PATCH 1/8] test(onboard): stage 1 retirement plan for test-docker-unreachable-gateway-start (#4355) Ahead of retiring test/e2e/test-docker-unreachable-gateway-start.sh, land the test plan as a stub vitest file and transition the migration inventory entry to bridge-probe so the intent is reviewable before the mocks land. The legacy script is structurally a Node-process unit test of startGateway() with a PATH-shimmed openshell binary, not a sandbox-lifecycle e2e. The unique regression target it protects is the startGatewayWithOptions() call-site contract: docker-unreachable classification short-circuits via pRetry.AbortError before any health-poll loop or post-start status/gateway-info probes. That contract is more faithfully covered by an in-process Vitest integration test next to the existing gateway-start-failure family than by anything the e2e-scenario probe model can express. Stage 2 (follow-up commits on this branch): implement the test bodies, flip the inventory entry to status=retired with deletionReady=true, delete the legacy script, and remove the docker-unreachable-gateway- start-e2e job from regression-e2e.yaml. Refs: #2347, #4355 --- .../gateway-start-failure-integration.test.ts | 88 +++++++++++++++++++ .../migration/legacy-inventory.json | 6 +- 2 files changed, 91 insertions(+), 3 deletions(-) create mode 100644 src/lib/onboard/gateway-start-failure-integration.test.ts diff --git a/src/lib/onboard/gateway-start-failure-integration.test.ts b/src/lib/onboard/gateway-start-failure-integration.test.ts new file mode 100644 index 00000000000..65fc88bee4d --- /dev/null +++ b/src/lib/onboard/gateway-start-failure-integration.test.ts @@ -0,0 +1,88 @@ +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 +// +// Integration test for the docker-unreachable abort path in +// startGatewayWithOptions() (src/lib/onboard.ts:2233). +// +// Replaces test/e2e/test-docker-unreachable-gateway-start.sh, which was +// structurally a Node-process unit test of startGateway() with a PATH- +// shimmed openshell binary, not a sandbox-lifecycle e2e. +// +// Original regression: NemoClaw #2347. +// Owning migration issue: NemoClaw #4355. +// +// STAGE 1 (this commit): test plan committed as it.todo() placeholders so +// the contract is reviewable before the mocks land. The legacy script and +// the regression-e2e job that runs it remain in place until Stage 2. +// +// STAGE 2 (follow-up): implement the test bodies, then in the same PR +// transition the inventory entry to status=retired with deletionReady=true, +// delete test/e2e/test-docker-unreachable-gateway-start.sh, and remove the +// docker-unreachable-gateway-start-e2e job from +// .github/workflows/regression-e2e.yaml (job + Valid: allowlist + the +// includes_job() guard). +// +// Mocking surface (Stage 2): +// - vi.mock("./gateway") → streamGatewayStart returns +// { status: 1, output: "...Failed +// to create Docker client... +// Socket not found: +// /var/run/docker.sock" } +// - vi.mock("../runner") → run, runCapture become spies; +// assert NEVER called with +// ["status"] or +// ["gateway","info",...] after +// streamGatewayStart returns. +// - vi.mock("../adapters/openshell/resolve") → resolveOpenshell returns a +// deterministic stub path so +// getOpenshellBinary() does +// not hit the filesystem. +// +// Process / env shape (Stage 2, mirrors legacy script): +// - vi.spyOn(process, "exit") → throw, so assertions can run after +// handleFinalGatewayStartFailure({dockerUnreachable:true}) calls +// exitProcess(1). Pattern from docker-driver-gateway-failure.test.ts. +// - Object.defineProperty(process, "platform", {value: "darwin"}) per +// test, restored in afterEach. Drive printDockerDaemonRecovery's +// branch selection. +// - process.env.NEMOCLAW_NON_INTERACTIVE = "1" +// - process.env.NEMOCLAW_HEALTH_POLL_COUNT = "5" (a low ceiling so a +// bug that *does* enter the health-poll loop fails the test in +// bounded time instead of hanging.) +// +// Access path: startGateway is exposed via module.exports at the bottom +// of src/lib/onboard.ts (line 6832). Stage 2 will import it via +// `await import("../onboard")` after vi.mock declarations. + +import { describe, it } from "vitest"; + +describe("startGatewayWithOptions docker-unreachable abort (#2347)", () => { + // Assertion 1 (legacy script: NODE_EXIT == 1) + it.todo("aborts with exit 1 when streamGatewayStart returns docker-unreachable signature"); + + // Assertion 2 (legacy script: grep "Docker daemon is not running") + it.todo("prints the Docker recovery guidance with macOS colima hint when platform=darwin"); + + // Coverage extension over legacy: legacy only tested darwin; covering + // the linux branch closes a printDockerDaemonRecovery gap. + it.todo("prints the Linux systemctl hint when platform=linux"); + + // Assertion 4 (legacy script: !grep "Waiting for gateway health") + it.todo("never logs 'Waiting for gateway health...' after docker-unreachable detection"); + + // Assertions 5+6 (legacy script: !grep "HEALTH POLL REACHED" in node + // log AND no post-__GATEWAY_START__ status/gateway-info probes in + // openshell trace log) + it.todo( + "never invokes openshell status or gateway info probes after docker-unreachable detection", + ); + + // Assertion 7 (legacy script: !grep "openshell doctor logs") + it.todo( + "does not collect doctor logs (handleFinalGatewayStartFailure short-circuits on dockerUnreachable=true)", + ); + + // Structural: the pRetry.AbortError must propagate; if a future refactor + // accidentally swallows it and continues retrying, this catches that. + it.todo("does not retry on docker-unreachable (pRetry.AbortError bypasses the outer retries)"); +}); diff --git a/test/e2e-scenario/migration/legacy-inventory.json b/test/e2e-scenario/migration/legacy-inventory.json index e102478d913..ca8b04a5d6d 100644 --- a/test/e2e-scenario/migration/legacy-inventory.json +++ b/test/e2e-scenario/migration/legacy-inventory.json @@ -270,12 +270,12 @@ "legacyScript": "test/e2e/test-docker-unreachable-gateway-start.sh", "domain": "sandbox-lifecycle", "ownerIssue": "#4355", - "status": "not-migrated", - "targetVitestScenarios": [], + "status": "bridge-probe", + "targetVitestScenarios": ["src/lib/onboard/gateway-start-failure-integration.test.ts"], "bridgeProbes": [], "retiredReason": "", "deletionReady": false, - "notes": "Initial completeness row; classify detailed coverage and deletion evidence in the owning migration issue before deleting." + "notes": "Retiring to Vitest integration test, not migrating to e2e-scenario framework. Original script is a Node-process unit test of startGateway() with a PATH-shimmed openshell binary, not a sandbox-lifecycle e2e. Stage 1 (this entry transition + stub test file with it.todo placeholders): see e2e-migrate/test-docker-unreachable-gateway-start branch. Stage 2 will implement the test bodies, flip status to retired with deletionReady=true, and delete the legacy script + the docker-unreachable-gateway-start-e2e job in regression-e2e.yaml. Existing unit-level coverage already in src/lib/onboard/gateway-start-failure.test.ts and docker-driver-gateway-failure.test.ts. Unique regression target is the startGatewayWithOptions call-site contract: docker-unreachable classification short-circuits via pRetry.AbortError before any health-poll loop or post-start status/gateway-info probes." }, { "legacyScript": "test/e2e/test-docs-validation.sh", From 7ca7e4069b4b65b7f8667c4d3d7247a3b8cd8b03 Mon Sep 17 00:00:00 2001 From: Julie Yaunches Date: Wed, 10 Jun 2026 00:46:47 -0400 Subject: [PATCH 2/8] test(onboard): implement docker-unreachable abort coverage (#4355) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace the stage-1 it.todo() placeholders with the full coverage layer described in the migration plan. 13 tests organized in five groups: 1. printDockerDaemonRecovery platform branches (darwin/linux/other) — covers legacy assertions 2-3 (recovery message + colima hint). 2. handleFinalGatewayStartFailure({dockerUnreachable: true}) skips diagnostics + cleanup and exits 1 — covers legacy assertions 1 and 7 (no openshell doctor logs collection). 3. Negative control — handleFinalGatewayStartFailure with dockerUnreachable=false DOES collect diagnostics and clean up. Guards against a future refactor that short-circuits the wrong branch. 4. Composition tests — runs the same helper sequence the call site uses (classify -> handleFinal -> exitProcess(1)) for both the macOS Colima and Linux dockerd signatures, plus a negative control on unrelated start failures. 5. Structural assertions on onboard.ts source proving the call-site wiring is in place: docker_unreachable classification, co-located pRetry.AbortError throw (which is what bypasses the retry loop and prevents any health-poll), and dockerUnreachable forwarded to handleFinalGatewayStartFailure. Catches refactors that drop any link in the chain. Layers 4 and 5 together cover legacy assertions 4 and 5 (no health-poll log; no status/gateway-info probes after gateway-start failure): the AbortError throw is the structural guarantee that the for-loop containing those probes is never reached, and layer 5 ensures the throw stays in place across refactors. Imports the symbol via the compiled dist output (../../../dist/lib/ onboard) — same pattern as preflight.test.ts. handleFinalGatewayStart Failure is exposed only via module.exports at the bottom of onboard.ts, not as a TS export, and the source-level CommonJS require() chain in onboard.ts -> onboard/gateway.ts -> onboard/env.ts does not resolve cleanly under Vitest's TS interpreter without the compiled output. CI runs npm run build:cli before vitest in the CLI coverage shards, so the dist import is satisfied at test time. Verified locally: 13/13 green. Stage 2b (next commit on this branch): flip inventory entry to status=retired with deletionReady=true, delete legacy script, remove the docker-unreachable-gateway-start-e2e job from regression-e2e.yaml. Refs: #2347, #4355 --- .../gateway-start-failure-integration.test.ts | 504 +++++++++++++++--- 1 file changed, 429 insertions(+), 75 deletions(-) diff --git a/src/lib/onboard/gateway-start-failure-integration.test.ts b/src/lib/onboard/gateway-start-failure-integration.test.ts index 65fc88bee4d..574817c8d45 100644 --- a/src/lib/onboard/gateway-start-failure-integration.test.ts +++ b/src/lib/onboard/gateway-start-failure-integration.test.ts @@ -1,88 +1,442 @@ // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // SPDX-License-Identifier: Apache-2.0 // -// Integration test for the docker-unreachable abort path in -// startGatewayWithOptions() (src/lib/onboard.ts:2233). +// Integration tests for the docker-unreachable abort path that +// startGatewayWithOptions() takes when `openshell gateway start` reports +// the Docker daemon is not reachable. See src/lib/onboard.ts:2233. // -// Replaces test/e2e/test-docker-unreachable-gateway-start.sh, which was -// structurally a Node-process unit test of startGateway() with a PATH- -// shimmed openshell binary, not a sandbox-lifecycle e2e. +// This file replaces test/e2e/test-docker-unreachable-gateway-start.sh, +// which was structurally a Node-process unit test of startGateway() with a +// PATH-shimmed openshell binary, not a sandbox-lifecycle e2e. // // Original regression: NemoClaw #2347. // Owning migration issue: NemoClaw #4355. // -// STAGE 1 (this commit): test plan committed as it.todo() placeholders so -// the contract is reviewable before the mocks land. The legacy script and -// the regression-e2e job that runs it remain in place until Stage 2. +// Coverage strategy: instead of mocking the ten-or-so module-internal +// closures inside startGatewayWithOptions (which would produce a brittle +// orchestrator integration test), prove the contract through three layers: // -// STAGE 2 (follow-up): implement the test bodies, then in the same PR -// transition the inventory entry to status=retired with deletionReady=true, -// delete test/e2e/test-docker-unreachable-gateway-start.sh, and remove the -// docker-unreachable-gateway-start-e2e job from -// .github/workflows/regression-e2e.yaml (job + Valid: allowlist + the -// includes_job() guard). -// -// Mocking surface (Stage 2): -// - vi.mock("./gateway") → streamGatewayStart returns -// { status: 1, output: "...Failed -// to create Docker client... -// Socket not found: -// /var/run/docker.sock" } -// - vi.mock("../runner") → run, runCapture become spies; -// assert NEVER called with -// ["status"] or -// ["gateway","info",...] after -// streamGatewayStart returns. -// - vi.mock("../adapters/openshell/resolve") → resolveOpenshell returns a -// deterministic stub path so -// getOpenshellBinary() does -// not hit the filesystem. -// -// Process / env shape (Stage 2, mirrors legacy script): -// - vi.spyOn(process, "exit") → throw, so assertions can run after -// handleFinalGatewayStartFailure({dockerUnreachable:true}) calls -// exitProcess(1). Pattern from docker-driver-gateway-failure.test.ts. -// - Object.defineProperty(process, "platform", {value: "darwin"}) per -// test, restored in afterEach. Drive printDockerDaemonRecovery's -// branch selection. -// - process.env.NEMOCLAW_NON_INTERACTIVE = "1" -// - process.env.NEMOCLAW_HEALTH_POLL_COUNT = "5" (a low ceiling so a -// bug that *does* enter the health-poll loop fails the test in -// bounded time instead of hanging.) -// -// Access path: startGateway is exposed via module.exports at the bottom -// of src/lib/onboard.ts (line 6832). Stage 2 will import it via -// `await import("../onboard")` after vi.mock declarations. +// 1. Unit tests of the already-exported helpers (printDockerDaemonRecovery, +// handleFinalGatewayStartFailure with dockerUnreachable=true). +// 2. A composition test that runs the same helper sequence the call site +// uses (classify → handleFinal → exitProcess(1)). +// 3. A structural assertion against onboard.ts source proving the call-site +// wiring is in place. This catches refactors that accidentally drop the +// pRetry.AbortError throw or skip the dockerUnreachable flag. + +import fs from "node:fs"; +import path from "node:path"; + +import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; +// `handleFinalGatewayStartFailure` is exposed via `module.exports = {...}` at +// the bottom of onboard.ts (it is not a TypeScript `export`). Import the +// compiled output (same approach as preflight.test.ts and other onboard- +// adjacent tests) so the CommonJS `require()` calls in onboard.ts and its +// transitive dependencies resolve cleanly under Vitest. Coverage also lands +// on dist/lib/onboard.js, matching what the coverage ratchet measures. +import onboardExports from "../../../dist/lib/onboard"; +import { classifyGatewayStartFailure } from "../validation"; +import { + printDockerDaemonRecovery, + reportLegacyGatewayStartResultFailure, +} from "./gateway-start-failure"; + +const handleFinalGatewayStartFailure: (opts: { + retries: number; + dockerUnreachable?: boolean; + collectDiagnostics?: () => string; + cleanupGateway?: () => void; + exitProcess?: (code: number) => never; + printError?: (message?: string) => void; +}) => never = (onboardExports as unknown as Record) + .handleFinalGatewayStartFailure as never; -import { describe, it } from "vitest"; +// Real signatures the legacy script's fake openshell binary emitted from +// `gateway start` to simulate Colima-stopped (macOS) and dockerd-stopped +// (Linux). These are the wire format the call site sees from +// streamGatewayStart()'s `output` field. +const DARWIN_DOCKER_UNREACHABLE_OUTPUT = [ + "Error: Failed to create Docker client.", + "Socket not found: /var/run/docker.sock", +].join("\n"); + +const LINUX_DOCKER_UNREACHABLE_OUTPUT = + "Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?"; describe("startGatewayWithOptions docker-unreachable abort (#2347)", () => { - // Assertion 1 (legacy script: NODE_EXIT == 1) - it.todo("aborts with exit 1 when streamGatewayStart returns docker-unreachable signature"); - - // Assertion 2 (legacy script: grep "Docker daemon is not running") - it.todo("prints the Docker recovery guidance with macOS colima hint when platform=darwin"); - - // Coverage extension over legacy: legacy only tested darwin; covering - // the linux branch closes a printDockerDaemonRecovery gap. - it.todo("prints the Linux systemctl hint when platform=linux"); - - // Assertion 4 (legacy script: !grep "Waiting for gateway health") - it.todo("never logs 'Waiting for gateway health...' after docker-unreachable detection"); - - // Assertions 5+6 (legacy script: !grep "HEALTH POLL REACHED" in node - // log AND no post-__GATEWAY_START__ status/gateway-info probes in - // openshell trace log) - it.todo( - "never invokes openshell status or gateway info probes after docker-unreachable detection", - ); - - // Assertion 7 (legacy script: !grep "openshell doctor logs") - it.todo( - "does not collect doctor logs (handleFinalGatewayStartFailure short-circuits on dockerUnreachable=true)", - ); - - // Structural: the pRetry.AbortError must propagate; if a future refactor - // accidentally swallows it and continues retrying, this catches that. - it.todo("does not retry on docker-unreachable (pRetry.AbortError bypasses the outer retries)"); + // ── Layer 1: unit tests of the platform-branching recovery message ──────── + + describe("printDockerDaemonRecovery platform branches", () => { + it("prints the macOS/colima recovery hint when platform=darwin", () => { + const printed: string[] = []; + printDockerDaemonRecovery((message = "") => printed.push(message), "darwin"); + const joined = printed.join("\n"); + expect(joined).toContain("Docker daemon is not running"); + expect(joined).toContain("colima start"); + expect(joined).not.toContain("systemctl"); + }); + + it("prints the Linux/systemctl recovery hint when platform=linux", () => { + const printed: string[] = []; + printDockerDaemonRecovery((message = "") => printed.push(message), "linux"); + const joined = printed.join("\n"); + expect(joined).toContain("Docker daemon is not running"); + expect(joined).toContain("sudo systemctl start docker"); + expect(joined).not.toContain("colima start"); + }); + + it("prints a platform-neutral fallback hint on other platforms", () => { + const printed: string[] = []; + printDockerDaemonRecovery((message = "") => printed.push(message), "win32"); + const joined = printed.join("\n"); + expect(joined).toContain("Docker daemon is not running"); + expect(joined).toContain("Start the Docker daemon"); + expect(joined).not.toContain("colima start"); + expect(joined).not.toContain("systemctl"); + }); + }); + + // ── Layer 1: handleFinalGatewayStartFailure dockerUnreachable branch ───── + // + // Proves three things at once: + // - exitProcess(1) is called → covers the legacy script's NODE_EXIT==1 + // assertion. + // - collectDiagnostics is NEVER called → covers the legacy script's + // `!grep "openshell doctor logs"` assertion (the script's assertion 7). + // - cleanupGateway is NEVER called → covers the legacy script's implicit + // contract that destroyGateway is not invoked on Docker-unreachable + // (preserving any prior good gateway state for the user). + // - printError is invoked with the recovery guidance → composition with + // printDockerDaemonRecovery. + + describe("handleFinalGatewayStartFailure({dockerUnreachable: true})", () => { + it("calls exitProcess(1) and skips diagnostics + cleanup", () => { + const printError = vi.fn(); + const collectDiagnostics = vi.fn(() => "should-never-be-collected"); + const cleanupGateway = vi.fn(); + const exitProcess = vi.fn((code: number) => { + // Throw so the function's `: never` signature is honored from the + // test's perspective without actually terminating the process. + throw new Error(`__exitProcess(${code})`); + }) as (code: number) => never; + + expect(() => + handleFinalGatewayStartFailure({ + retries: 2, + dockerUnreachable: true, + printError, + collectDiagnostics, + cleanupGateway, + exitProcess, + }), + ).toThrow(/__exitProcess\(1\)/); + + expect(exitProcess).toHaveBeenCalledTimes(1); + expect(exitProcess).toHaveBeenCalledWith(1); + // The crucial behavioural difference from the non-Docker-unreachable + // path: no doctor logs are collected and no cleanup is attempted. + expect(collectDiagnostics).not.toHaveBeenCalled(); + expect(cleanupGateway).not.toHaveBeenCalled(); + + const printed = printError.mock.calls.map((c) => String(c[0] ?? "")).join("\n"); + expect(printed).toContain("Docker daemon is not running"); + }); + + it("DOES collect diagnostics and clean up when dockerUnreachable=false (negative control)", () => { + // Guards against a future refactor that accidentally short-circuits the + // non-Docker-unreachable branch as well. + const printError = vi.fn(); + const collectDiagnostics = vi.fn(() => ""); + const cleanupGateway = vi.fn(); + const exitProcess = vi.fn(() => { + throw new Error("__exitProcess"); + }) as (code: number) => never; + + try { + handleFinalGatewayStartFailure({ + retries: 2, + dockerUnreachable: false, + printError, + collectDiagnostics, + cleanupGateway, + exitProcess, + }); + } catch { + // expected — handleFinal still calls exitProcess on the unhealthy + // (non-Docker-unreachable) branch by way of the surrounding caller; + // here the function returns normally if exitProcess does not throw. + } + + expect(collectDiagnostics).toHaveBeenCalled(); + expect(cleanupGateway).toHaveBeenCalled(); + }); + }); + + // ── Layer 2: composition test — the exact sequence the call site uses ──── + // + // startGatewayWithOptions does, on `streamGatewayStart()` failure: + // + // const failure = reportLegacyGatewayStartResultFailure(output, log); + // if (failure.kind === "docker_unreachable") { + // dockerUnreachable = true; + // throw new pRetry.AbortError(...); + // } + // } catch { + // if (exitOnFailure) { + // handleFinalGatewayStartFailure({ retries, dockerUnreachable }); + // } + // throw new Error("Gateway failed to start"); + // } + // + // The composition test exercises the same helpers in the same order and + // confirms the chain bottoms out at exitProcess(1) with the recovery + // message printed. + + describe("composition: classify → handleFinal → exit 1", () => { + let capturedClassifyLog: string[]; + let capturedPrintError: string[]; + + function runComposition(streamGatewayStartOutput: string): { + thrown: unknown; + exitCode: number | null; + } { + capturedClassifyLog = []; + capturedPrintError = []; + + const failure = reportLegacyGatewayStartResultFailure(streamGatewayStartOutput, (m) => + capturedClassifyLog.push(m), + ); + + let dockerUnreachable = false; + if (failure.kind === "docker_unreachable") { + dockerUnreachable = true; + } + + let exitCode: number | null = null; + let thrown: unknown = null; + try { + handleFinalGatewayStartFailure({ + retries: 2, + dockerUnreachable, + printError: (m = "") => capturedPrintError.push(m), + collectDiagnostics: () => { + throw new Error("collectDiagnostics must not be called on docker_unreachable"); + }, + cleanupGateway: () => { + throw new Error("cleanupGateway must not be called on docker_unreachable"); + }, + exitProcess: ((code: number) => { + exitCode = code; + throw new Error(`__exit(${code})`); + }) as (code: number) => never, + }); + } catch (err) { + thrown = err; + } + return { thrown, exitCode }; + } + + it("composes through the docker-unreachable path on the macOS Colima signature", () => { + const { thrown, exitCode } = runComposition(DARWIN_DOCKER_UNREACHABLE_OUTPUT); + expect(thrown).toBeInstanceOf(Error); + expect(exitCode).toBe(1); + expect(capturedPrintError.join("\n")).toContain("Docker daemon is not running"); + // The classification helper logs the original output as a breadcrumb; + // the legacy script asserts on this output too via its `[INFO] node + // exit code` log lines. + expect(capturedClassifyLog.join("\n")).toContain("Gateway start returned before healthy"); + }); + + it("composes through the docker-unreachable path on the Linux dockerd signature", () => { + const { thrown, exitCode } = runComposition(LINUX_DOCKER_UNREACHABLE_OUTPUT); + expect(thrown).toBeInstanceOf(Error); + expect(exitCode).toBe(1); + expect(capturedPrintError.join("\n")).toContain("Docker daemon is not running"); + }); + + it("does NOT trigger the docker-unreachable path on unrelated start output (negative control)", () => { + // A genuinely-broken-but-not-Docker-unreachable failure must still reach + // the regular failure path (which DOES collect diagnostics and clean + // up). If this test ever flips, the call-site classifier has been made + // too aggressive and would silence real gateway failures behind the + // Docker-recovery message. + capturedClassifyLog = []; + capturedPrintError = []; + + const failure = reportLegacyGatewayStartResultFailure( + " k3s: failed to bootstrap helm chart after 90s\n", + (m) => capturedClassifyLog.push(m), + ); + + expect(failure.kind).toBe("unknown"); + + let collectCalls = 0; + let cleanupCalls = 0; + let exitCode: number | null = null; + try { + handleFinalGatewayStartFailure({ + retries: 2, + dockerUnreachable: false, + printError: (m = "") => capturedPrintError.push(m), + collectDiagnostics: () => { + collectCalls += 1; + return ""; + }, + cleanupGateway: () => { + cleanupCalls += 1; + }, + exitProcess: ((code: number) => { + exitCode = code; + throw new Error(`__exit(${code})`); + }) as (code: number) => never, + }); + } catch { + // expected + } + expect(collectCalls).toBeGreaterThan(0); + expect(cleanupCalls).toBeGreaterThan(0); + // The non-Docker-unreachable branch does NOT print the Docker daemon + // recovery message. + expect(capturedPrintError.join("\n")).not.toContain("Docker daemon is not running"); + // exitCode is left null here because the test's exitProcess throws + // and the surrounding handleFinal swallows other branches' exits via + // its caller — the assertion that matters is that diagnostics + cleanup + // happened. + void exitCode; + }); + }); + + // ── Layer 3: structural assertion on the call site ────────────────────── + // + // These tests defend against future refactors that accidentally: + // - skip the `failure.kind === "docker_unreachable"` check, + // - drop the `pRetry.AbortError` throw (causing retries), + // - or fail to forward `dockerUnreachable: true` to handleFinal. + // + // They are deliberately scoped narrowly — they assert only the wiring + // pattern, not exact whitespace — and live next to the unit tests so the + // intent is obvious to reviewers of future onboard.ts changes. + + describe("call-site wiring in startGatewayWithOptions (structural)", () => { + let onboardSource: string; + + beforeEach(() => { + onboardSource = fs.readFileSync(path.resolve(__dirname, "..", "onboard.ts"), "utf8"); + }); + + afterEach(() => { + // free string in long suites + onboardSource = ""; + }); + + it("classifies docker-unreachable inside startGatewayWithOptions", () => { + // The call site reads the failure.kind enum; the literal "docker_unreachable" + // must appear inside the function body. + const startGatewayWithOptionsBody = extractFunctionBody( + onboardSource, + "async function startGatewayWithOptions", + ); + expect(startGatewayWithOptionsBody).toMatch(/failure\.kind\s*===\s*"docker_unreachable"/); + }); + + it("throws pRetry.AbortError on the docker-unreachable branch (no retries)", () => { + const startGatewayWithOptionsBody = extractFunctionBody( + onboardSource, + "async function startGatewayWithOptions", + ); + // The docker_unreachable check and the AbortError throw must be + // co-located. We assert both appear within a small window of each + // other rather than anywhere in the function — guards against a + // refactor that splits them across unrelated branches. + const idx = startGatewayWithOptionsBody.indexOf('"docker_unreachable"'); + expect(idx).toBeGreaterThan(-1); + const window = startGatewayWithOptionsBody.slice(idx, idx + 400); + expect(window).toMatch(/throw new pRetry\.AbortError/); + }); + + it("forwards dockerUnreachable to handleFinalGatewayStartFailure", () => { + const startGatewayWithOptionsBody = extractFunctionBody( + onboardSource, + "async function startGatewayWithOptions", + ); + // Either as a shorthand property or as a key-value — accept both. + expect(startGatewayWithOptionsBody).toMatch( + /handleFinalGatewayStartFailure\(\{[^}]*\bdockerUnreachable\b/s, + ); + }); + }); + + // ── Sanity: classifyGatewayStartFailure recognises both signatures ───── + // (Already covered in gateway-start-failure.test.ts; this is a pinning + // assertion for the two strings the legacy script generated, kept here so + // the retirement leaves no implicit reference to those byte sequences.) + + describe("classifyGatewayStartFailure pinning for legacy-script signatures", () => { + it("classifies the macOS Colima signature as docker_unreachable", () => { + expect(classifyGatewayStartFailure(DARWIN_DOCKER_UNREACHABLE_OUTPUT)).toEqual({ + kind: "docker_unreachable", + }); + }); + + it("classifies the Linux dockerd signature as docker_unreachable", () => { + expect(classifyGatewayStartFailure(LINUX_DOCKER_UNREACHABLE_OUTPUT)).toEqual({ + kind: "docker_unreachable", + }); + }); + }); }); + +/** + * Extract a top-level function body by declaration prefix (e.g. + * "async function startGatewayWithOptions") from the onboard.ts source. + * + * Walks past the signature by balancing parentheses (handles nested types + * like `ReturnType` and inline-destructured parameters + * with their own braces) until reaching the closing `)` of the parameter + * list at depth 0, then finds the function body's opening `{` and balances + * braces to its matching close. Throws if the function is not found or the + * body cannot be parsed; structural tests are useless if they silently match + * an empty string. + */ +function extractFunctionBody(source: string, declarationPrefix: string): string { + const start = source.indexOf(declarationPrefix); + if (start === -1) { + throw new Error(`Could not find '${declarationPrefix}' in onboard.ts`); + } + const sigOpen = source.indexOf("(", start); + if (sigOpen === -1) { + throw new Error(`No '(' after '${declarationPrefix}' in onboard.ts`); + } + // Balance parens through the signature, ignoring any braces that appear + // inside parameter destructuring or generic types. + let parenDepth = 0; + let sigClose = -1; + for (let i = sigOpen; i < source.length; i++) { + const ch = source[i]; + if (ch === "(") parenDepth += 1; + else if (ch === ")") { + parenDepth -= 1; + if (parenDepth === 0) { + sigClose = i; + break; + } + } + } + if (sigClose === -1) { + throw new Error(`Unbalanced '(' in signature of '${declarationPrefix}'`); + } + const bodyOpen = source.indexOf("{", sigClose); + if (bodyOpen === -1) { + throw new Error(`No body '{' after signature of '${declarationPrefix}'`); + } + let depth = 0; + for (let i = bodyOpen; i < source.length; i++) { + const ch = source[i]; + if (ch === "{") depth += 1; + else if (ch === "}") { + depth -= 1; + if (depth === 0) return source.slice(bodyOpen + 1, i); + } + } + throw new Error(`Unbalanced braces while extracting body of '${declarationPrefix}'`); +} From 493f87c973ab1ab4b000bc19607f5ddaf409e163 Mon Sep 17 00:00:00 2001 From: Julie Yaunches Date: Wed, 10 Jun 2026 00:59:09 -0400 Subject: [PATCH 3/8] fix(test): keep inventory entry as not-migrated until atomic Stage 2b flip MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The 'bridge-probe' status carries an invariant in test/e2e-scenario/framework-tests/e2e-migration-inventory.test.ts:130: `record.bridgeProbes.length > 0`. The Stage 1 commit set status to 'bridge-probe' but kept bridgeProbes=[] because this migration is a full retirement, not a partial bridge — there are no bash assertions remaining as bridge probes — so the invariant tripped on cli-test-shards (2). Revert status to 'not-migrated'. The retirement plan, the new test path, and the in-flight branch reference are preserved in the entry's notes field. Status will flip directly 'not-migrated' -> 'retired' in Stage 2b atomically with the legacy script delete and the regression-e2e.yaml job removal, satisfying the deletion-gate test's 'retired' branch (retiredReason non-empty). Verified locally: e2e-migration-inventory.test.ts 8/8 green; gateway-start-failure-integration.test.ts 13/13 still green. Refs: #4355 --- test/e2e-scenario/migration/legacy-inventory.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/e2e-scenario/migration/legacy-inventory.json b/test/e2e-scenario/migration/legacy-inventory.json index ca8b04a5d6d..c4f9fe39560 100644 --- a/test/e2e-scenario/migration/legacy-inventory.json +++ b/test/e2e-scenario/migration/legacy-inventory.json @@ -270,12 +270,12 @@ "legacyScript": "test/e2e/test-docker-unreachable-gateway-start.sh", "domain": "sandbox-lifecycle", "ownerIssue": "#4355", - "status": "bridge-probe", - "targetVitestScenarios": ["src/lib/onboard/gateway-start-failure-integration.test.ts"], + "status": "not-migrated", + "targetVitestScenarios": [], "bridgeProbes": [], "retiredReason": "", "deletionReady": false, - "notes": "Retiring to Vitest integration test, not migrating to e2e-scenario framework. Original script is a Node-process unit test of startGateway() with a PATH-shimmed openshell binary, not a sandbox-lifecycle e2e. Stage 1 (this entry transition + stub test file with it.todo placeholders): see e2e-migrate/test-docker-unreachable-gateway-start branch. Stage 2 will implement the test bodies, flip status to retired with deletionReady=true, and delete the legacy script + the docker-unreachable-gateway-start-e2e job in regression-e2e.yaml. Existing unit-level coverage already in src/lib/onboard/gateway-start-failure.test.ts and docker-driver-gateway-failure.test.ts. Unique regression target is the startGatewayWithOptions call-site contract: docker-unreachable classification short-circuits via pRetry.AbortError before any health-poll loop or post-start status/gateway-info probes." + "notes": "Retirement in flight on branch e2e-migrate/test-docker-unreachable-gateway-start (PR #5109). Migrating to a Vitest integration test at src/lib/onboard/gateway-start-failure-integration.test.ts rather than the e2e-scenario framework: the original script is a Node-process unit test of startGateway() with a PATH-shimmed openshell binary, not a sandbox-lifecycle e2e. Status stays 'not-migrated' until the same PR atomically flips to 'retired' with deletionReady=true and deletes the legacy script + the docker-unreachable-gateway-start-e2e job in regression-e2e.yaml. Existing unit-level coverage in src/lib/onboard/gateway-start-failure.test.ts and src/lib/onboard/docker-driver-gateway-failure.test.ts; unique regression target is the startGatewayWithOptions call-site contract that docker-unreachable classification short-circuits via pRetry.AbortError before any health-poll loop or post-start status/gateway-info probes." }, { "legacyScript": "test/e2e/test-docs-validation.sh", From 7f214fb4a7ca0715968c8f0f6259e85573a34bc3 Mon Sep 17 00:00:00 2001 From: Julie Yaunches Date: Wed, 10 Jun 2026 01:17:33 -0400 Subject: [PATCH 4/8] test(onboard): retire test-docker-unreachable-gateway-start.sh (#4355) Stage 2b: complete the retirement now that the integration test is green in CI. Atomic four-part change: 1. Inventory entry transitions not-migrated -> retired with retiredReason filled, deletionReady=true, and deletionApprovalIssue=#4357 (matching the gate in e2e-migration-inventory.test.ts). 2. test/e2e/test-docker-unreachable-gateway-start.sh is deleted. Its assertions are fully covered by src/lib/onboard/gateway-start-failure-integration.test.ts (landed in the previous commit on this branch). 3. The docker-unreachable-gateway-start-e2e job is removed from .github/workflows/regression-e2e.yaml in three places: the 'Valid:' allowlist in the workflow_dispatch input description, the select_regression_jobs outputs map, the includes_job guard block, and the job definition itself. 4. The migration-inventory invariant test (test/e2e-scenario/framework-tests/e2e-migration-inventory.test.ts) is extended for the first-ever 'retired' entry. Two narrow relaxations, both gated on status === 'retired': - Skip repoPathExists(legacyScript) so a retired entry can keep its legacyScript path for the audit trail after the file is deleted. - Filter retired entries out of the inventory<->filesystem shell-script equality check, since their script no longer exists on disk. Non-retired entries still go through the full check; the relaxation is opt-in by status. Verified locally: 21/21 tests green across the integration test and the inventory test suite. CI on the previous commit was 28/31 green (0 failures, 2 SKIPPED, 1 null artifact); this commit only adds deletion + invariant relaxations and is expected to remain green. Marking PR ready for review in the same flow. Refs: #2347, #4355 --- .github/workflows/regression-e2e.yaml | 47 +---- node_modules | 1 + .../e2e-migration-inventory.test.ts | 13 +- .../migration/legacy-inventory.json | 9 +- .../test-docker-unreachable-gateway-start.sh | 162 ------------------ 5 files changed, 19 insertions(+), 213 deletions(-) create mode 120000 node_modules delete mode 100755 test/e2e/test-docker-unreachable-gateway-start.sh diff --git a/.github/workflows/regression-e2e.yaml b/.github/workflows/regression-e2e.yaml index ec7108b59bc..400ded2bae2 100644 --- a/.github/workflows/regression-e2e.yaml +++ b/.github/workflows/regression-e2e.yaml @@ -21,7 +21,7 @@ on: jobs: description: >- Comma-separated regression job names to run (empty = all). - Valid: dashboard-remote-bind-e2e,gateway-health-honest-e2e,docker-unreachable-gateway-start-e2e,gateway-drift-preflight-e2e,openshell-version-pin-e2e,onboard-inference-smoke-e2e,strict-tool-call-probe-e2e,model-router-provider-routed-inference-e2e,openclaw-plugin-runtime-exdev-e2e,whatsapp-qr-compact-e2e + Valid: dashboard-remote-bind-e2e,gateway-health-honest-e2e,gateway-drift-preflight-e2e,openshell-version-pin-e2e,onboard-inference-smoke-e2e,strict-tool-call-probe-e2e,model-router-provider-routed-inference-e2e,openclaw-plugin-runtime-exdev-e2e,whatsapp-qr-compact-e2e required: false type: string default: "" @@ -46,7 +46,6 @@ jobs: outputs: dashboard: ${{ steps.select.outputs.dashboard }} gateway: ${{ steps.select.outputs.gateway }} - docker_unreachable_gateway_start: ${{ steps.select.outputs.docker_unreachable_gateway_start }} gateway_drift_preflight: ${{ steps.select.outputs.gateway_drift_preflight }} openshell_version_pin: ${{ steps.select.outputs.openshell_version_pin }} onboard_inference_smoke: ${{ steps.select.outputs.onboard_inference_smoke }} @@ -81,12 +80,6 @@ jobs: echo "gateway=false" >> "$GITHUB_OUTPUT" fi - if [ -z "$normalized" ] || includes_job "docker-unreachable-gateway-start-e2e"; then - echo "docker_unreachable_gateway_start=true" >> "$GITHUB_OUTPUT" - else - echo "docker_unreachable_gateway_start=false" >> "$GITHUB_OUTPUT" - fi - if [ -z "$normalized" ] || includes_job "gateway-drift-preflight-e2e"; then echo "gateway_drift_preflight=true" >> "$GITHUB_OUTPUT" else @@ -194,44 +187,6 @@ jobs: /tmp/nemoclaw-e2e-gateway-health-honest-process.log if-no-files-found: ignore - # ── Docker-unreachable gateway-start E2E ─────────────────── - # Coverage guard for #2347's fallback path. Preflight catches Docker - # daemon outages before step [2/8] on the normal path; this focused - # regression simulates Docker dying during `openshell gateway start` and - # verifies onboard exits before health polling with Docker recovery advice. - docker-unreachable-gateway-start-e2e: - needs: select_regression_jobs - if: >- - github.repository == 'NVIDIA/NemoClaw' && - needs.select_regression_jobs.outputs.docker_unreachable_gateway_start == 'true' - runs-on: ubuntu-latest - timeout-minutes: 15 - steps: - - name: Checkout - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 - - - name: Setup Node - uses: actions/setup-node@v6 - with: - node-version: "22" - - - name: Run Docker-unreachable gateway-start E2E test - env: - NEMOCLAW_NON_INTERACTIVE: "1" - NEMOCLAW_ACCEPT_THIRD_PARTY_SOFTWARE: "1" - run: bash test/e2e/test-docker-unreachable-gateway-start.sh - - - name: Upload Docker-unreachable gateway-start logs on failure - if: failure() - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 - with: - name: docker-unreachable-gateway-start-logs - path: | - /tmp/nemoclaw-e2e-docker-unreachable-gateway-start.log - /tmp/nemoclaw-e2e-docker-unreachable-gateway-start-node.log - /tmp/nemoclaw-e2e-docker-unreachable-gateway-start-openshell.log - if-no-files-found: ignore - # ── OpenShell version-pin E2E ────────────────────────────── # Coverage guard for #3474. If a host has sticky OpenShell 0.0.45 on PATH # but this NemoClaw release supports only <=0.0.44, install-openshell.sh diff --git a/node_modules b/node_modules new file mode 120000 index 00000000000..8b4b1610468 --- /dev/null +++ b/node_modules @@ -0,0 +1 @@ +/Users/jyaunches/Development/NemoClaw/node_modules \ No newline at end of file diff --git a/test/e2e-scenario/framework-tests/e2e-migration-inventory.test.ts b/test/e2e-scenario/framework-tests/e2e-migration-inventory.test.ts index 14998a690a5..3a43f6b7c42 100644 --- a/test/e2e-scenario/framework-tests/e2e-migration-inventory.test.ts +++ b/test/e2e-scenario/framework-tests/e2e-migration-inventory.test.ts @@ -162,7 +162,13 @@ describe("E2E migration inventory deletion gates", () => { for (const entry of inventory.entries) { expect(statuses.has(entry.status)).toBe(true); expect(entry.legacyScript).not.toBe(""); - expect(repoPathExists(entry.legacyScript)).toBe(true); + // Retired entries delete the legacy script in the same PR that + // transitions to status="retired" (deletionReady=true unblocks the + // freeze workflow). The script path stays in the inventory for the + // historical audit trail; do not require it to still exist on disk. + if (entry.status !== "retired") { + expect(repoPathExists(entry.legacyScript)).toBe(true); + } expect(legacyScripts.has(entry.legacyScript)).toBe(false); legacyScripts.add(entry.legacyScript); expect(entry.domain).not.toBe(""); @@ -185,7 +191,12 @@ describe("E2E migration inventory deletion gates", () => { it("covers every current direct legacy shell entrypoint", () => { const inventory = loadInventory(); + // Compare against current-on-disk scripts only. Retired entries keep + // their legacyScript path in the inventory for the audit trail even + // after the file has been deleted, so they must not participate in the + // filesystem-equality check. const inventoriedShellScripts = inventory.entries + .filter((entry) => entry.status !== "retired") .map((entry) => entry.legacyScript) .filter((legacyScript) => /^test\/e2e\/test-.+\.sh$/.test(legacyScript)) .sort(); diff --git a/test/e2e-scenario/migration/legacy-inventory.json b/test/e2e-scenario/migration/legacy-inventory.json index c4f9fe39560..96f8a88a29f 100644 --- a/test/e2e-scenario/migration/legacy-inventory.json +++ b/test/e2e-scenario/migration/legacy-inventory.json @@ -270,12 +270,13 @@ "legacyScript": "test/e2e/test-docker-unreachable-gateway-start.sh", "domain": "sandbox-lifecycle", "ownerIssue": "#4355", - "status": "not-migrated", + "status": "retired", "targetVitestScenarios": [], "bridgeProbes": [], - "retiredReason": "", - "deletionReady": false, - "notes": "Retirement in flight on branch e2e-migrate/test-docker-unreachable-gateway-start (PR #5109). Migrating to a Vitest integration test at src/lib/onboard/gateway-start-failure-integration.test.ts rather than the e2e-scenario framework: the original script is a Node-process unit test of startGateway() with a PATH-shimmed openshell binary, not a sandbox-lifecycle e2e. Status stays 'not-migrated' until the same PR atomically flips to 'retired' with deletionReady=true and deletes the legacy script + the docker-unreachable-gateway-start-e2e job in regression-e2e.yaml. Existing unit-level coverage in src/lib/onboard/gateway-start-failure.test.ts and src/lib/onboard/docker-driver-gateway-failure.test.ts; unique regression target is the startGatewayWithOptions call-site contract that docker-unreachable classification short-circuits via pRetry.AbortError before any health-poll loop or post-start status/gateway-info probes." + "retiredReason": "Retired in PR #5109. The original script was structurally a Node-process unit test of startGateway() with a PATH-shimmed openshell binary, not a sandbox-lifecycle e2e (no real openshell, gateway, sandbox, or registry). Coverage moved to src/lib/onboard/gateway-start-failure-integration.test.ts, which proves the docker-unreachable abort contract through three layers: unit tests of printDockerDaemonRecovery and handleFinalGatewayStartFailure({dockerUnreachable:true}); composition tests running the same classify -> handleFinal -> exitProcess(1) sequence the call site uses for both macOS Colima and Linux dockerd signatures; and structural assertions on onboard.ts source proving the call-site wiring (docker_unreachable classification, co-located pRetry.AbortError throw that bypasses the health-poll loop, and dockerUnreachable forwarded to handleFinalGatewayStartFailure). The docker-unreachable-gateway-start-e2e job in regression-e2e.yaml was removed in the same PR. Refs: #2347, #4355.", + "deletionReady": true, + "deletionApprovalIssue": "#4357", + "notes": "Retired in PR #5109. Coverage moved to src/lib/onboard/gateway-start-failure-integration.test.ts. See retiredReason for the full retirement context (why retire vs migrate, three-layer coverage strategy, regression-e2e.yaml job removal). Refs: #2347, #4355." }, { "legacyScript": "test/e2e/test-docs-validation.sh", diff --git a/test/e2e/test-docker-unreachable-gateway-start.sh b/test/e2e/test-docker-unreachable-gateway-start.sh deleted file mode 100755 index bcfee8d3256..00000000000 --- a/test/e2e/test-docker-unreachable-gateway-start.sh +++ /dev/null @@ -1,162 +0,0 @@ -#!/usr/bin/env bash -# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 -# -# Regression E2E for #2347's gateway-start fallback: if `openshell gateway -# start` reports that Docker/Colima is unreachable, onboard must abort before -# gateway health polling and print Docker recovery guidance. - -set -euo pipefail - -LOG_FILE="/tmp/nemoclaw-e2e-docker-unreachable-gateway-start.log" -START_LOG="/tmp/nemoclaw-e2e-docker-unreachable-gateway-start-node.log" -TRACE_LOG="/tmp/nemoclaw-e2e-docker-unreachable-gateway-start-openshell.log" -exec > >(tee "$LOG_FILE") 2>&1 - -RED='\033[0;31m' -GREEN='\033[0;32m' -YELLOW='\033[1;33m' -NC='\033[0m' - -pass() { echo -e "${GREEN}[PASS]${NC} $1"; } -info() { echo -e "${YELLOW}[INFO]${NC} $1"; } -diag() { echo -e "${YELLOW}[DIAG]${NC} $1"; } -fail() { - echo -e "${RED}[FAIL]${NC} $1" >&2 - diag "node log tail:" - tail -120 "$START_LOG" 2>/dev/null || true - diag "fake openshell trace:" - cat "$TRACE_LOG" 2>/dev/null || true - exit 1 -} - -SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)" -REPO_ROOT="$(cd "${SCRIPT_DIR}/../.." && pwd)" -TMP_DIR="$(mktemp -d)" -FAKE_BIN="${TMP_DIR}/bin" -mkdir -p "$FAKE_BIN" -: >"$TRACE_LOG" - -cleanup() { - rm -rf "$TMP_DIR" -} -trap cleanup EXIT - -cd "$REPO_ROOT" - -info "Preparing CLI build" -if [ ! -d node_modules ]; then - npm ci --ignore-scripts -fi -npm run build:cli - -info "Installing fake openshell that reports Docker socket-not-found during gateway start" -cat >"${FAKE_BIN}/openshell" <<'SHIM' -#!/usr/bin/env bash -set -euo pipefail -TRACE_LOG="${NEMOCLAW_FAKE_OPENSHELL_TRACE:?}" -printf '%s\n' "$*" >>"$TRACE_LOG" - -if [[ "$*" == "--version" ]]; then - printf 'openshell 0.0.44\n' - exit 0 -fi - -if [[ "$*" == "gateway --help" ]]; then - printf 'Commands: start select info destroy remove\n' - exit 0 -fi - -if [[ "$*" == *"gateway"*"start"* ]]; then - printf '%s\n' "__GATEWAY_START__" >>"$TRACE_LOG" - printf 'Error: Failed to create Docker client.\n' - printf 'Socket not found: /var/run/docker.sock\n' - exit 1 -fi - -# These probes are allowed before gateway start when startGateway() checks -# reusable gateway state. After __GATEWAY_START__, they prove the regression: -# onboard fell through into health/status polling instead of aborting. -if [[ "$*" == "status" || "$*" == *"gateway"*"info"* ]]; then - printf 'HEALTH POLL REACHED\n' - exit 0 -fi - -if [[ "$*" == *"gateway"*"select"* || "$*" == *"gateway"*"destroy"* || "$*" == *"gateway"*"remove"* ]]; then - exit 0 -fi - -exit 0 -SHIM -chmod 755 "${FAKE_BIN}/openshell" - -info "Invoking legacy startGateway() path with macOS/x64 platform semantics" -set +e -PATH="${FAKE_BIN}:$PATH" \ - HOME="${TMP_DIR}/home" \ - NEMOCLAW_FAKE_OPENSHELL_TRACE="$TRACE_LOG" \ - NEMOCLAW_NON_INTERACTIVE="1" \ - NEMOCLAW_HEALTH_POLL_COUNT="5" \ - node <<'NODE' >"$START_LOG" 2>&1 -Object.defineProperty(process, "platform", { value: "darwin" }); -Object.defineProperty(process, "arch", { value: "x64" }); - -const { startGateway } = require("./dist/lib/onboard"); - -startGateway(null) - .then(() => { - console.log("__startGateway_returned_successfully__"); - process.exit(0); - }) - .catch((error) => { - console.error("__startGateway_threw__"); - console.error(error && error.stack ? error.stack : error); - process.exit(3); - }); -NODE -NODE_EXIT=$? -set -e - -info "node exit code: ${NODE_EXIT}" - -if [ "$NODE_EXIT" -ne 1 ]; then - fail "startGateway should exit 1 when Docker is unreachable, got ${NODE_EXIT}" -fi -pass "startGateway exited 1 on Docker-unreachable gateway-start output" - -if ! grep -q "Docker daemon is not running" "$START_LOG"; then - fail "Docker recovery guidance was not printed" -fi -pass "Docker recovery guidance was printed" - -if ! grep -q "colima start" "$START_LOG"; then - fail "macOS/Colima recovery hint was not printed" -fi -pass "macOS/Colima recovery hint was printed" - -if grep -q "Waiting for gateway health" "$START_LOG"; then - fail "onboard entered gateway health polling after Docker-unreachable gateway-start output" -fi -pass "gateway health polling message was not printed after Docker-unreachable output" - -if grep -q "HEALTH POLL REACHED" "$START_LOG"; then - fail "gateway status/info probe output appeared after Docker-unreachable gateway-start output" -fi -pass "gateway status/info probe output did not appear in user output" - -POST_START_PROBES="$(awk ' - /__GATEWAY_START__/ { seen = 1; next } - seen && ($0 == "status" || $0 ~ /gateway.*info/) { print } -' "$TRACE_LOG")" -if [ -n "$POST_START_PROBES" ]; then - fail "status/gateway-info probes ran after Docker-unreachable gateway start: ${POST_START_PROBES}" -fi -pass "no status/gateway-info probes ran after Docker-unreachable gateway start" - -if grep -q "openshell doctor logs" "$START_LOG"; then - fail "generic OpenShell diagnostics were printed instead of Docker-specific recovery guidance" -fi -pass "generic OpenShell diagnostics were skipped for Docker-unreachable gateway start" - -echo "" -pass "#2347 gateway-start fallback E2E green" From 3bdde69ac1114bae4d62cd21645ae4414834ecca Mon Sep 17 00:00:00 2001 From: Julie Yaunches Date: Wed, 10 Jun 2026 01:17:52 -0400 Subject: [PATCH 5/8] chore: remove accidentally committed node_modules symlink A local-only symlink to the main checkout's node_modules slipped into the previous commit via 'git add -A'. node_modules is in .gitignore; this restores that intent. No source change. --- node_modules | 1 - 1 file changed, 1 deletion(-) delete mode 120000 node_modules diff --git a/node_modules b/node_modules deleted file mode 120000 index 8b4b1610468..00000000000 --- a/node_modules +++ /dev/null @@ -1 +0,0 @@ -/Users/jyaunches/Development/NemoClaw/node_modules \ No newline at end of file From 2f4c473a565307827ecead9e7b7c15692fc0dd9d Mon Sep 17 00:00:00 2001 From: Julie Yaunches Date: Wed, 10 Jun 2026 01:59:38 -0400 Subject: [PATCH 6/8] test(onboard): drop source-shape section, document caller-level gap (#4355) Address PR Review Advisor finding 1 (source-shape budget violation in spirit) and finding 2 (caller-level coverage gap): - Remove the entire 'call-site wiring (structural)' describe block: the three regex assertions reading onboard.ts as text, the beforeEach/afterEach managing the source string, and the extractFunctionBody helper. ci/source-shape-test-budget.json sets maxSourceShapeCases to 0, and the advisor flagged this as source-shape testing in spirit even though source-shape:check's detector did not catch the pattern. - Replace with an explicit 'call-site contracts (caller-level coverage gap)' describe block containing three it.todo entries for the call-site contracts the legacy bash script directly proved (no health-poll on docker-unreachable, no status/info probes after gateway-start failure, dockerUnreachable forwarded to handleFinal). The gap is now visible in test output instead of papered over with structural regexes. - Update the file-level header to a two-layer coverage strategy (unit + composition), document the gap, and explain the two options for closing it: ~10 vi.mock calls or extracting the inner pRetry async body of startGatewayWithOptions into an exported helper that takes streamGatewayStart as a DI parameter. Both are out of scope for this retirement PR; a follow-up issue will track option (b) so the it.todo entries can convert into real assertions. Result: 10 passing tests + 3 documented todo placeholders, no source-shape regexes, file shrinks 442 -> 369 lines. Verified locally: gateway-start-failure-integration.test.ts 10/10 green + 3 todo; e2e-migration-inventory.test.ts 8/8 green. source-shape:check still reports 0 cases. Refs: #2347, #4355 --- .../gateway-start-failure-integration.test.ts | 171 +++++------------- 1 file changed, 49 insertions(+), 122 deletions(-) diff --git a/src/lib/onboard/gateway-start-failure-integration.test.ts b/src/lib/onboard/gateway-start-failure-integration.test.ts index 574817c8d45..769f6ed9ec6 100644 --- a/src/lib/onboard/gateway-start-failure-integration.test.ts +++ b/src/lib/onboard/gateway-start-failure-integration.test.ts @@ -12,22 +12,26 @@ // Original regression: NemoClaw #2347. // Owning migration issue: NemoClaw #4355. // -// Coverage strategy: instead of mocking the ten-or-so module-internal -// closures inside startGatewayWithOptions (which would produce a brittle -// orchestrator integration test), prove the contract through three layers: +// Coverage strategy: prove the contract through two layers: // // 1. Unit tests of the already-exported helpers (printDockerDaemonRecovery, // handleFinalGatewayStartFailure with dockerUnreachable=true). // 2. A composition test that runs the same helper sequence the call site // uses (classify → handleFinal → exitProcess(1)). -// 3. A structural assertion against onboard.ts source proving the call-site -// wiring is in place. This catches refactors that accidentally drop the -// pRetry.AbortError throw or skip the dockerUnreachable flag. - -import fs from "node:fs"; -import path from "node:path"; - -import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; +// +// What this file deliberately DOES NOT cover (gap documented as it.todo +// at the bottom of the suite, with a follow-up issue tracking the +// refactor): direct executable proof that startGatewayWithOptions, on a +// docker-unreachable streamGatewayStart() result, (a) throws +// pRetry.AbortError instead of retrying, (b) never logs "Waiting for +// gateway health...", and (c) never calls openshell `status` or +// `gateway info` probes. Closing that gap requires either mocking the +// ~10 module-internal closures `startGatewayWithOptions` touches before +// reaching streamGatewayStart, or extracting the inner pRetry async body +// into an exported helper that takes streamGatewayStart as a DI +// parameter. Both changes are out of scope for the retirement PR. + +import { describe, expect, it, vi } from "vitest"; // `handleFinalGatewayStartFailure` is exposed via `module.exports = {...}` at // the bottom of onboard.ts (it is not a TypeScript `export`). Import the // compiled output (same approach as preflight.test.ts and other onboard- @@ -306,64 +310,42 @@ describe("startGatewayWithOptions docker-unreachable abort (#2347)", () => { }); }); - // ── Layer 3: structural assertion on the call site ────────────────────── + // ── Documented coverage gap: caller-level contracts that need a + // behavior-level seam (out of scope for this retirement PR) ───────── // - // These tests defend against future refactors that accidentally: - // - skip the `failure.kind === "docker_unreachable"` check, - // - drop the `pRetry.AbortError` throw (causing retries), - // - or fail to forward `dockerUnreachable: true` to handleFinal. + // The legacy bash script directly executed `startGateway()` with a + // PATH-shimmed openshell binary and asserted runtime behavior of the + // call site. The unit + composition tests above cover the same ground + // for everything reachable through already-exported helpers, but three + // call-site contracts cannot be proven without driving the actual + // `startGatewayWithOptions` orchestrator past its ~200 lines of + // gateway-reuse / ssh-keygen / known_hosts / docker-driver-detect + // preamble. Doing that in a focused way requires either: // - // They are deliberately scoped narrowly — they assert only the wiring - // pattern, not exact whitespace — and live next to the unit tests so the - // intent is obvious to reviewers of future onboard.ts changes. - - describe("call-site wiring in startGatewayWithOptions (structural)", () => { - let onboardSource: string; - - beforeEach(() => { - onboardSource = fs.readFileSync(path.resolve(__dirname, "..", "onboard.ts"), "utf8"); - }); - - afterEach(() => { - // free string in long suites - onboardSource = ""; - }); - - it("classifies docker-unreachable inside startGatewayWithOptions", () => { - // The call site reads the failure.kind enum; the literal "docker_unreachable" - // must appear inside the function body. - const startGatewayWithOptionsBody = extractFunctionBody( - onboardSource, - "async function startGatewayWithOptions", - ); - expect(startGatewayWithOptionsBody).toMatch(/failure\.kind\s*===\s*"docker_unreachable"/); - }); - - it("throws pRetry.AbortError on the docker-unreachable branch (no retries)", () => { - const startGatewayWithOptionsBody = extractFunctionBody( - onboardSource, - "async function startGatewayWithOptions", - ); - // The docker_unreachable check and the AbortError throw must be - // co-located. We assert both appear within a small window of each - // other rather than anywhere in the function — guards against a - // refactor that splits them across unrelated branches. - const idx = startGatewayWithOptionsBody.indexOf('"docker_unreachable"'); - expect(idx).toBeGreaterThan(-1); - const window = startGatewayWithOptionsBody.slice(idx, idx + 400); - expect(window).toMatch(/throw new pRetry\.AbortError/); - }); - - it("forwards dockerUnreachable to handleFinalGatewayStartFailure", () => { - const startGatewayWithOptionsBody = extractFunctionBody( - onboardSource, - "async function startGatewayWithOptions", - ); - // Either as a shorthand property or as a key-value — accept both. - expect(startGatewayWithOptionsBody).toMatch( - /handleFinalGatewayStartFailure\(\{[^}]*\bdockerUnreachable\b/s, - ); - }); + // (a) ~10 vi.mock() calls on module-internal closures inside + // onboard.ts (brittle), or + // (b) a small refactor extracting the inner pRetry async body of + // startGatewayWithOptions into an exported helper that takes + // streamGatewayStart as a DI parameter. + // + // Both are out of scope for this retirement PR. The follow-up issue + // (TODO: link once filed) tracks landing option (b) and converting + // these `it.todo` placeholders into real assertions. Until then, the + // primary safety net for these contracts is code review on + // src/lib/onboard.ts:startGatewayWithOptions plus the existing + // classifyGatewayStartFailure / printDockerDaemonRecovery / + // handleFinalGatewayStartFailure unit tests above. + + describe("call-site contracts (caller-level coverage gap)", () => { + it.todo( + "startGateway aborts via pRetry.AbortError without entering health-poll loop on docker-unreachable streamGatewayStart output", + ); + it.todo( + "startGateway never invokes openshell `status` or `gateway info` after docker-unreachable streamGatewayStart output", + ); + it.todo( + "startGateway forwards dockerUnreachable=true to handleFinalGatewayStartFailure (no doctor logs collection, no destroyGateway cleanup) when streamGatewayStart returns docker-unreachable signature", + ); }); // ── Sanity: classifyGatewayStartFailure recognises both signatures ───── @@ -385,58 +367,3 @@ describe("startGatewayWithOptions docker-unreachable abort (#2347)", () => { }); }); }); - -/** - * Extract a top-level function body by declaration prefix (e.g. - * "async function startGatewayWithOptions") from the onboard.ts source. - * - * Walks past the signature by balancing parentheses (handles nested types - * like `ReturnType` and inline-destructured parameters - * with their own braces) until reaching the closing `)` of the parameter - * list at depth 0, then finds the function body's opening `{` and balances - * braces to its matching close. Throws if the function is not found or the - * body cannot be parsed; structural tests are useless if they silently match - * an empty string. - */ -function extractFunctionBody(source: string, declarationPrefix: string): string { - const start = source.indexOf(declarationPrefix); - if (start === -1) { - throw new Error(`Could not find '${declarationPrefix}' in onboard.ts`); - } - const sigOpen = source.indexOf("(", start); - if (sigOpen === -1) { - throw new Error(`No '(' after '${declarationPrefix}' in onboard.ts`); - } - // Balance parens through the signature, ignoring any braces that appear - // inside parameter destructuring or generic types. - let parenDepth = 0; - let sigClose = -1; - for (let i = sigOpen; i < source.length; i++) { - const ch = source[i]; - if (ch === "(") parenDepth += 1; - else if (ch === ")") { - parenDepth -= 1; - if (parenDepth === 0) { - sigClose = i; - break; - } - } - } - if (sigClose === -1) { - throw new Error(`Unbalanced '(' in signature of '${declarationPrefix}'`); - } - const bodyOpen = source.indexOf("{", sigClose); - if (bodyOpen === -1) { - throw new Error(`No body '{' after signature of '${declarationPrefix}'`); - } - let depth = 0; - for (let i = bodyOpen; i < source.length; i++) { - const ch = source[i]; - if (ch === "{") depth += 1; - else if (ch === "}") { - depth -= 1; - if (depth === 0) return source.slice(bodyOpen + 1, i); - } - } - throw new Error(`Unbalanced braces while extracting body of '${declarationPrefix}'`); -} From d85c7b344ab0244fd6848d66e823c2a6f13b1f1b Mon Sep 17 00:00:00 2001 From: Julie Yaunches Date: Wed, 10 Jun 2026 02:15:58 -0400 Subject: [PATCH 7/8] fix(test): align retiredReason + TODO link with actual coverage shape Address PR Review Advisor's new finding 'Inventory retiredReason claims structural coverage that no longer exists' and the related 'TODO: link once filed' staleness. - retiredReason previously claimed the replacement test included 'structural assertions on onboard.ts source proving the call-site wiring'. That section was removed in commit 2f4c473a (advisor finding 1, source-shape budget). Updated retiredReason to describe the actual two-layer strategy (helper unit tests + composition tests) and explicitly call out the three caller-level contracts that remain as it.todo placeholders. - Inventory notes field similarly tightened. - Test file's '(TODO: link once filed)' replaced with concrete reference to follow-up issue #5113 (Extract attemptGatewayStart helper from startGatewayWithOptions for caller-level testability). This does not close the caller-level coverage gap itself \u2014 the advisor's larger 'Needs attention' findings about the missing caller-level proof remain. See PR description's 'Coverage gap (acknowledged)' section. Refs: #2347, #4355, #5113 --- src/lib/onboard/gateway-start-failure-integration.test.ts | 7 ++++--- test/e2e-scenario/migration/legacy-inventory.json | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/lib/onboard/gateway-start-failure-integration.test.ts b/src/lib/onboard/gateway-start-failure-integration.test.ts index 769f6ed9ec6..60410ebee50 100644 --- a/src/lib/onboard/gateway-start-failure-integration.test.ts +++ b/src/lib/onboard/gateway-start-failure-integration.test.ts @@ -328,9 +328,10 @@ describe("startGatewayWithOptions docker-unreachable abort (#2347)", () => { // startGatewayWithOptions into an exported helper that takes // streamGatewayStart as a DI parameter. // - // Both are out of scope for this retirement PR. The follow-up issue - // (TODO: link once filed) tracks landing option (b) and converting - // these `it.todo` placeholders into real assertions. Until then, the + // Both are out of scope for this retirement PR. Follow-up issue + // [#5113](https://github.com/NVIDIA/NemoClaw/issues/5113) tracks + // landing option (b) and converting these `it.todo` placeholders into + // real assertions. Until then, the // primary safety net for these contracts is code review on // src/lib/onboard.ts:startGatewayWithOptions plus the existing // classifyGatewayStartFailure / printDockerDaemonRecovery / diff --git a/test/e2e-scenario/migration/legacy-inventory.json b/test/e2e-scenario/migration/legacy-inventory.json index 96f8a88a29f..fecbcf5e015 100644 --- a/test/e2e-scenario/migration/legacy-inventory.json +++ b/test/e2e-scenario/migration/legacy-inventory.json @@ -273,10 +273,10 @@ "status": "retired", "targetVitestScenarios": [], "bridgeProbes": [], - "retiredReason": "Retired in PR #5109. The original script was structurally a Node-process unit test of startGateway() with a PATH-shimmed openshell binary, not a sandbox-lifecycle e2e (no real openshell, gateway, sandbox, or registry). Coverage moved to src/lib/onboard/gateway-start-failure-integration.test.ts, which proves the docker-unreachable abort contract through three layers: unit tests of printDockerDaemonRecovery and handleFinalGatewayStartFailure({dockerUnreachable:true}); composition tests running the same classify -> handleFinal -> exitProcess(1) sequence the call site uses for both macOS Colima and Linux dockerd signatures; and structural assertions on onboard.ts source proving the call-site wiring (docker_unreachable classification, co-located pRetry.AbortError throw that bypasses the health-poll loop, and dockerUnreachable forwarded to handleFinalGatewayStartFailure). The docker-unreachable-gateway-start-e2e job in regression-e2e.yaml was removed in the same PR. Refs: #2347, #4355.", + "retiredReason": "Retired in PR #5109. The original script was structurally a Node-process unit test of startGateway() with a PATH-shimmed openshell binary, not a sandbox-lifecycle e2e (no real openshell, gateway, sandbox, or registry). Coverage moved to src/lib/onboard/gateway-start-failure-integration.test.ts, which uses a two-layer strategy: (1) unit tests of printDockerDaemonRecovery platform branches and handleFinalGatewayStartFailure({dockerUnreachable:true}) skip-diagnostics-and-cleanup behavior, plus a negative control on the dockerUnreachable=false branch and a classifier pinning suite for both macOS Colima and Linux dockerd signatures; (2) composition tests running the same classify -> handleFinal -> exitProcess(1) sequence the call site uses, with a negative control on unrelated start-failure output. Three caller-level contracts (no health-poll loop entry, no openshell status/gateway-info probes after gateway-start failure, dockerUnreachable forwarded to handleFinalGatewayStartFailure) are documented as it.todo placeholders pending the seam refactor in follow-up issue #5113. The docker-unreachable-gateway-start-e2e job in regression-e2e.yaml was removed in the same PR. Refs: #2347, #4355, #5113.", "deletionReady": true, "deletionApprovalIssue": "#4357", - "notes": "Retired in PR #5109. Coverage moved to src/lib/onboard/gateway-start-failure-integration.test.ts. See retiredReason for the full retirement context (why retire vs migrate, three-layer coverage strategy, regression-e2e.yaml job removal). Refs: #2347, #4355." + "notes": "Retired in PR #5109. Coverage moved to src/lib/onboard/gateway-start-failure-integration.test.ts (two-layer strategy: helper unit tests + composition test). Three caller-level contracts remain as it.todo placeholders pending the seam refactor in follow-up issue #5113. Refs: #2347, #4355, #5113." }, { "legacyScript": "test/e2e/test-docs-validation.sh", From 00817c1f818610ab4a1aaa424f036f1a007e0c98 Mon Sep 17 00:00:00 2001 From: Julie Yaunches Date: Wed, 10 Jun 2026 02:28:46 -0400 Subject: [PATCH 8/8] revert: defer full retirement of test-docker-unreachable-gateway-start.sh per advisor PR Review Advisor's escalated finding (3rd cycle, 'Needs attention' items still apply): caller-level coverage of the #2347 contracts (no health-poll loop entry, no openshell status/gateway info probes after docker-unreachable gateway-start failure, dockerUnreachable forwarded to handleFinalGatewayStartFailure) is not proven by the helper-level tests in this PR. The advisor explicitly recommended either landing that coverage in this PR or not marking the script fully retired until it exists. Choosing the latter: defer the full retirement to a follow-up PR after issue #5113 (extract attemptGatewayStart helper) lands, so the caller-level contracts can be exercised through a behavior-level seam. This commit reverts Stage 2b's deletions while keeping the helper-level Vitest coverage from earlier commits: - Restore test/e2e/test-docker-unreachable-gateway-start.sh (the legacy regression script). - Restore the docker-unreachable-gateway-start-e2e job in .github/workflows/regression-e2e.yaml (Valid: allowlist, select_regression_jobs outputs map, includes_job guard, full job definition). - Restore .../e2e-migration-inventory.test.ts to its origin/main shape; the status==='retired' relaxations are not needed yet and will land with the future deletion PR (their first user). - Inventory entry: status not-migrated -> not-migrated (no change), retiredReason cleared, deletionReady false, notes updated to describe the helper coverage that DID land plus the deferred-retirement plan and the #5113 follow-up. What this PR still delivers: - src/lib/onboard/gateway-start-failure-integration.test.ts: helper-level coverage of printDockerDaemonRecovery platform branches (darwin/linux/win32) + handleFinalGatewayStartFailure skip-diagnostics-and-cleanup behavior on dockerUnreachable=true + composition tests of the call-site helper sequence + classifier pinning for both signatures + 3 it.todo placeholders documenting the caller-level gap. - Inventory notes documenting the partial coverage and the follow-up plan. Refs: #2347, #4355, #5113 --- .github/workflows/regression-e2e.yaml | 47 ++++- .../e2e-migration-inventory.test.ts | 13 +- .../migration/legacy-inventory.json | 9 +- .../test-docker-unreachable-gateway-start.sh | 162 ++++++++++++++++++ 4 files changed, 213 insertions(+), 18 deletions(-) create mode 100755 test/e2e/test-docker-unreachable-gateway-start.sh diff --git a/.github/workflows/regression-e2e.yaml b/.github/workflows/regression-e2e.yaml index 400ded2bae2..ec7108b59bc 100644 --- a/.github/workflows/regression-e2e.yaml +++ b/.github/workflows/regression-e2e.yaml @@ -21,7 +21,7 @@ on: jobs: description: >- Comma-separated regression job names to run (empty = all). - Valid: dashboard-remote-bind-e2e,gateway-health-honest-e2e,gateway-drift-preflight-e2e,openshell-version-pin-e2e,onboard-inference-smoke-e2e,strict-tool-call-probe-e2e,model-router-provider-routed-inference-e2e,openclaw-plugin-runtime-exdev-e2e,whatsapp-qr-compact-e2e + Valid: dashboard-remote-bind-e2e,gateway-health-honest-e2e,docker-unreachable-gateway-start-e2e,gateway-drift-preflight-e2e,openshell-version-pin-e2e,onboard-inference-smoke-e2e,strict-tool-call-probe-e2e,model-router-provider-routed-inference-e2e,openclaw-plugin-runtime-exdev-e2e,whatsapp-qr-compact-e2e required: false type: string default: "" @@ -46,6 +46,7 @@ jobs: outputs: dashboard: ${{ steps.select.outputs.dashboard }} gateway: ${{ steps.select.outputs.gateway }} + docker_unreachable_gateway_start: ${{ steps.select.outputs.docker_unreachable_gateway_start }} gateway_drift_preflight: ${{ steps.select.outputs.gateway_drift_preflight }} openshell_version_pin: ${{ steps.select.outputs.openshell_version_pin }} onboard_inference_smoke: ${{ steps.select.outputs.onboard_inference_smoke }} @@ -80,6 +81,12 @@ jobs: echo "gateway=false" >> "$GITHUB_OUTPUT" fi + if [ -z "$normalized" ] || includes_job "docker-unreachable-gateway-start-e2e"; then + echo "docker_unreachable_gateway_start=true" >> "$GITHUB_OUTPUT" + else + echo "docker_unreachable_gateway_start=false" >> "$GITHUB_OUTPUT" + fi + if [ -z "$normalized" ] || includes_job "gateway-drift-preflight-e2e"; then echo "gateway_drift_preflight=true" >> "$GITHUB_OUTPUT" else @@ -187,6 +194,44 @@ jobs: /tmp/nemoclaw-e2e-gateway-health-honest-process.log if-no-files-found: ignore + # ── Docker-unreachable gateway-start E2E ─────────────────── + # Coverage guard for #2347's fallback path. Preflight catches Docker + # daemon outages before step [2/8] on the normal path; this focused + # regression simulates Docker dying during `openshell gateway start` and + # verifies onboard exits before health polling with Docker recovery advice. + docker-unreachable-gateway-start-e2e: + needs: select_regression_jobs + if: >- + github.repository == 'NVIDIA/NemoClaw' && + needs.select_regression_jobs.outputs.docker_unreachable_gateway_start == 'true' + runs-on: ubuntu-latest + timeout-minutes: 15 + steps: + - name: Checkout + uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 + + - name: Setup Node + uses: actions/setup-node@v6 + with: + node-version: "22" + + - name: Run Docker-unreachable gateway-start E2E test + env: + NEMOCLAW_NON_INTERACTIVE: "1" + NEMOCLAW_ACCEPT_THIRD_PARTY_SOFTWARE: "1" + run: bash test/e2e/test-docker-unreachable-gateway-start.sh + + - name: Upload Docker-unreachable gateway-start logs on failure + if: failure() + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 + with: + name: docker-unreachable-gateway-start-logs + path: | + /tmp/nemoclaw-e2e-docker-unreachable-gateway-start.log + /tmp/nemoclaw-e2e-docker-unreachable-gateway-start-node.log + /tmp/nemoclaw-e2e-docker-unreachable-gateway-start-openshell.log + if-no-files-found: ignore + # ── OpenShell version-pin E2E ────────────────────────────── # Coverage guard for #3474. If a host has sticky OpenShell 0.0.45 on PATH # but this NemoClaw release supports only <=0.0.44, install-openshell.sh diff --git a/test/e2e-scenario/framework-tests/e2e-migration-inventory.test.ts b/test/e2e-scenario/framework-tests/e2e-migration-inventory.test.ts index 3a43f6b7c42..14998a690a5 100644 --- a/test/e2e-scenario/framework-tests/e2e-migration-inventory.test.ts +++ b/test/e2e-scenario/framework-tests/e2e-migration-inventory.test.ts @@ -162,13 +162,7 @@ describe("E2E migration inventory deletion gates", () => { for (const entry of inventory.entries) { expect(statuses.has(entry.status)).toBe(true); expect(entry.legacyScript).not.toBe(""); - // Retired entries delete the legacy script in the same PR that - // transitions to status="retired" (deletionReady=true unblocks the - // freeze workflow). The script path stays in the inventory for the - // historical audit trail; do not require it to still exist on disk. - if (entry.status !== "retired") { - expect(repoPathExists(entry.legacyScript)).toBe(true); - } + expect(repoPathExists(entry.legacyScript)).toBe(true); expect(legacyScripts.has(entry.legacyScript)).toBe(false); legacyScripts.add(entry.legacyScript); expect(entry.domain).not.toBe(""); @@ -191,12 +185,7 @@ describe("E2E migration inventory deletion gates", () => { it("covers every current direct legacy shell entrypoint", () => { const inventory = loadInventory(); - // Compare against current-on-disk scripts only. Retired entries keep - // their legacyScript path in the inventory for the audit trail even - // after the file has been deleted, so they must not participate in the - // filesystem-equality check. const inventoriedShellScripts = inventory.entries - .filter((entry) => entry.status !== "retired") .map((entry) => entry.legacyScript) .filter((legacyScript) => /^test\/e2e\/test-.+\.sh$/.test(legacyScript)) .sort(); diff --git a/test/e2e-scenario/migration/legacy-inventory.json b/test/e2e-scenario/migration/legacy-inventory.json index fecbcf5e015..187ea8b009f 100644 --- a/test/e2e-scenario/migration/legacy-inventory.json +++ b/test/e2e-scenario/migration/legacy-inventory.json @@ -270,13 +270,12 @@ "legacyScript": "test/e2e/test-docker-unreachable-gateway-start.sh", "domain": "sandbox-lifecycle", "ownerIssue": "#4355", - "status": "retired", + "status": "not-migrated", "targetVitestScenarios": [], "bridgeProbes": [], - "retiredReason": "Retired in PR #5109. The original script was structurally a Node-process unit test of startGateway() with a PATH-shimmed openshell binary, not a sandbox-lifecycle e2e (no real openshell, gateway, sandbox, or registry). Coverage moved to src/lib/onboard/gateway-start-failure-integration.test.ts, which uses a two-layer strategy: (1) unit tests of printDockerDaemonRecovery platform branches and handleFinalGatewayStartFailure({dockerUnreachable:true}) skip-diagnostics-and-cleanup behavior, plus a negative control on the dockerUnreachable=false branch and a classifier pinning suite for both macOS Colima and Linux dockerd signatures; (2) composition tests running the same classify -> handleFinal -> exitProcess(1) sequence the call site uses, with a negative control on unrelated start-failure output. Three caller-level contracts (no health-poll loop entry, no openshell status/gateway-info probes after gateway-start failure, dockerUnreachable forwarded to handleFinalGatewayStartFailure) are documented as it.todo placeholders pending the seam refactor in follow-up issue #5113. The docker-unreachable-gateway-start-e2e job in regression-e2e.yaml was removed in the same PR. Refs: #2347, #4355, #5113.", - "deletionReady": true, - "deletionApprovalIssue": "#4357", - "notes": "Retired in PR #5109. Coverage moved to src/lib/onboard/gateway-start-failure-integration.test.ts (two-layer strategy: helper unit tests + composition test). Three caller-level contracts remain as it.todo placeholders pending the seam refactor in follow-up issue #5113. Refs: #2347, #4355, #5113." + "retiredReason": "", + "deletionReady": false, + "notes": "PR #5109 added Vitest helper coverage at src/lib/onboard/gateway-start-failure-integration.test.ts (two-layer strategy: unit tests of printDockerDaemonRecovery + handleFinalGatewayStartFailure, plus a composition test running the same classify -> handleFinal -> exitProcess(1) sequence the call site uses). Full retirement (delete this script + remove the docker-unreachable-gateway-start-e2e job in regression-e2e.yaml) was deferred per PR Review Advisor feedback because three caller-level contracts (no health-poll loop entry, no openshell status/gateway-info probes after gateway-start failure, dockerUnreachable forwarded to handleFinalGatewayStartFailure) are not directly proven without a behavior-level seam in startGatewayWithOptions. Follow-up issue #5113 tracks extracting attemptGatewayStart and converting the three it.todo placeholders into real assertions; deletion + retirement happen in a follow-up PR after that lands. Refs: #2347, #4355, #5113." }, { "legacyScript": "test/e2e/test-docs-validation.sh", diff --git a/test/e2e/test-docker-unreachable-gateway-start.sh b/test/e2e/test-docker-unreachable-gateway-start.sh new file mode 100755 index 00000000000..bcfee8d3256 --- /dev/null +++ b/test/e2e/test-docker-unreachable-gateway-start.sh @@ -0,0 +1,162 @@ +#!/usr/bin/env bash +# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 +# +# Regression E2E for #2347's gateway-start fallback: if `openshell gateway +# start` reports that Docker/Colima is unreachable, onboard must abort before +# gateway health polling and print Docker recovery guidance. + +set -euo pipefail + +LOG_FILE="/tmp/nemoclaw-e2e-docker-unreachable-gateway-start.log" +START_LOG="/tmp/nemoclaw-e2e-docker-unreachable-gateway-start-node.log" +TRACE_LOG="/tmp/nemoclaw-e2e-docker-unreachable-gateway-start-openshell.log" +exec > >(tee "$LOG_FILE") 2>&1 + +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +NC='\033[0m' + +pass() { echo -e "${GREEN}[PASS]${NC} $1"; } +info() { echo -e "${YELLOW}[INFO]${NC} $1"; } +diag() { echo -e "${YELLOW}[DIAG]${NC} $1"; } +fail() { + echo -e "${RED}[FAIL]${NC} $1" >&2 + diag "node log tail:" + tail -120 "$START_LOG" 2>/dev/null || true + diag "fake openshell trace:" + cat "$TRACE_LOG" 2>/dev/null || true + exit 1 +} + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)" +REPO_ROOT="$(cd "${SCRIPT_DIR}/../.." && pwd)" +TMP_DIR="$(mktemp -d)" +FAKE_BIN="${TMP_DIR}/bin" +mkdir -p "$FAKE_BIN" +: >"$TRACE_LOG" + +cleanup() { + rm -rf "$TMP_DIR" +} +trap cleanup EXIT + +cd "$REPO_ROOT" + +info "Preparing CLI build" +if [ ! -d node_modules ]; then + npm ci --ignore-scripts +fi +npm run build:cli + +info "Installing fake openshell that reports Docker socket-not-found during gateway start" +cat >"${FAKE_BIN}/openshell" <<'SHIM' +#!/usr/bin/env bash +set -euo pipefail +TRACE_LOG="${NEMOCLAW_FAKE_OPENSHELL_TRACE:?}" +printf '%s\n' "$*" >>"$TRACE_LOG" + +if [[ "$*" == "--version" ]]; then + printf 'openshell 0.0.44\n' + exit 0 +fi + +if [[ "$*" == "gateway --help" ]]; then + printf 'Commands: start select info destroy remove\n' + exit 0 +fi + +if [[ "$*" == *"gateway"*"start"* ]]; then + printf '%s\n' "__GATEWAY_START__" >>"$TRACE_LOG" + printf 'Error: Failed to create Docker client.\n' + printf 'Socket not found: /var/run/docker.sock\n' + exit 1 +fi + +# These probes are allowed before gateway start when startGateway() checks +# reusable gateway state. After __GATEWAY_START__, they prove the regression: +# onboard fell through into health/status polling instead of aborting. +if [[ "$*" == "status" || "$*" == *"gateway"*"info"* ]]; then + printf 'HEALTH POLL REACHED\n' + exit 0 +fi + +if [[ "$*" == *"gateway"*"select"* || "$*" == *"gateway"*"destroy"* || "$*" == *"gateway"*"remove"* ]]; then + exit 0 +fi + +exit 0 +SHIM +chmod 755 "${FAKE_BIN}/openshell" + +info "Invoking legacy startGateway() path with macOS/x64 platform semantics" +set +e +PATH="${FAKE_BIN}:$PATH" \ + HOME="${TMP_DIR}/home" \ + NEMOCLAW_FAKE_OPENSHELL_TRACE="$TRACE_LOG" \ + NEMOCLAW_NON_INTERACTIVE="1" \ + NEMOCLAW_HEALTH_POLL_COUNT="5" \ + node <<'NODE' >"$START_LOG" 2>&1 +Object.defineProperty(process, "platform", { value: "darwin" }); +Object.defineProperty(process, "arch", { value: "x64" }); + +const { startGateway } = require("./dist/lib/onboard"); + +startGateway(null) + .then(() => { + console.log("__startGateway_returned_successfully__"); + process.exit(0); + }) + .catch((error) => { + console.error("__startGateway_threw__"); + console.error(error && error.stack ? error.stack : error); + process.exit(3); + }); +NODE +NODE_EXIT=$? +set -e + +info "node exit code: ${NODE_EXIT}" + +if [ "$NODE_EXIT" -ne 1 ]; then + fail "startGateway should exit 1 when Docker is unreachable, got ${NODE_EXIT}" +fi +pass "startGateway exited 1 on Docker-unreachable gateway-start output" + +if ! grep -q "Docker daemon is not running" "$START_LOG"; then + fail "Docker recovery guidance was not printed" +fi +pass "Docker recovery guidance was printed" + +if ! grep -q "colima start" "$START_LOG"; then + fail "macOS/Colima recovery hint was not printed" +fi +pass "macOS/Colima recovery hint was printed" + +if grep -q "Waiting for gateway health" "$START_LOG"; then + fail "onboard entered gateway health polling after Docker-unreachable gateway-start output" +fi +pass "gateway health polling message was not printed after Docker-unreachable output" + +if grep -q "HEALTH POLL REACHED" "$START_LOG"; then + fail "gateway status/info probe output appeared after Docker-unreachable gateway-start output" +fi +pass "gateway status/info probe output did not appear in user output" + +POST_START_PROBES="$(awk ' + /__GATEWAY_START__/ { seen = 1; next } + seen && ($0 == "status" || $0 ~ /gateway.*info/) { print } +' "$TRACE_LOG")" +if [ -n "$POST_START_PROBES" ]; then + fail "status/gateway-info probes ran after Docker-unreachable gateway start: ${POST_START_PROBES}" +fi +pass "no status/gateway-info probes ran after Docker-unreachable gateway start" + +if grep -q "openshell doctor logs" "$START_LOG"; then + fail "generic OpenShell diagnostics were printed instead of Docker-specific recovery guidance" +fi +pass "generic OpenShell diagnostics were skipped for Docker-unreachable gateway start" + +echo "" +pass "#2347 gateway-start fallback E2E green"