From 679b7b350268fab17f33a2af39d88642359c7bf3 Mon Sep 17 00:00:00 2001 From: Carlos Villela Date: Wed, 17 Jun 2026 19:18:48 -0700 Subject: [PATCH 1/6] test(e2e): migrate device auth health to vitest Signed-off-by: Carlos Villela --- .github/workflows/e2e-vitest-scenarios.yaml | 104 +++++++ .../live/device-auth-health.test.ts | 258 ++++++++++++++++++ 2 files changed, 362 insertions(+) create mode 100644 test/e2e-scenario/live/device-auth-health.test.ts diff --git a/.github/workflows/e2e-vitest-scenarios.yaml b/.github/workflows/e2e-vitest-scenarios.yaml index d270a3b670b..6f02cb824a0 100644 --- a/.github/workflows/e2e-vitest-scenarios.yaml +++ b/.github/workflows/e2e-vitest-scenarios.yaml @@ -3352,6 +3352,109 @@ jobs: if-no-files-found: ignore retention-days: 14 + device-auth-health-vitest: + needs: generate-matrix + if: ${{ (inputs.jobs == '' && inputs.scenarios == '') || contains(format(',{0},', inputs.jobs), ',device-auth-health-vitest,') || contains(format(',{0},', inputs.scenarios), ',device-auth-health,') }} + runs-on: ubuntu-latest + timeout-minutes: 40 + env: + FREE_STANDING_VITEST_JOB: "1" + FREE_STANDING_SCENARIO_ID: "device-auth-health" + E2E_ARTIFACT_DIR: ${{ github.workspace }}/e2e-artifacts/vitest/device-auth-health + NEMOCLAW_CLI_BIN: ${{ github.workspace }}/bin/nemoclaw.js + NEMOCLAW_RUN_E2E_SCENARIOS: "1" + NEMOCLAW_NON_INTERACTIVE: "1" + NEMOCLAW_ACCEPT_THIRD_PARTY_SOFTWARE: "1" + NEMOCLAW_SANDBOX_NAME: "e2e-health-auth" + NEMOCLAW_DASHBOARD_PORT: "18789" + OPENSHELL_GATEWAY: "nemoclaw" + steps: + - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 + with: + persist-credentials: false + + - name: Configure isolated Docker auth directory + run: echo "DOCKER_CONFIG=${RUNNER_TEMP}/docker-config-device-auth-health" >> "$GITHUB_ENV" + + - name: Authenticate to Docker Hub + env: + DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} + DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} + shell: bash + run: | + set -euo pipefail + if [[ -z "${DOCKERHUB_USERNAME}" || -z "${DOCKERHUB_TOKEN}" ]]; then + echo "::notice::Docker Hub credentials not configured; continuing with anonymous pulls." + exit 0 + fi + mkdir -p "${DOCKER_CONFIG}" + chmod 700 "${DOCKER_CONFIG}" + login_succeeded=0 + for attempt in 1 2 3; do + if echo "${DOCKERHUB_TOKEN}" | timeout 30s docker login docker.io --username "${DOCKERHUB_USERNAME}" --password-stdin; then + login_succeeded=1 + break + fi + if [[ "$attempt" -lt 3 ]]; then + echo "::warning::Docker Hub login attempt ${attempt} failed; retrying." + sleep 5 + fi + done + if [[ "$login_succeeded" -ne 1 ]]; then + echo "::warning::Docker Hub login failed after 3 attempts; continuing with anonymous pulls." + fi + + - name: Set up Node + uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.0.0 + with: + node-version: 22 + cache: npm + + - name: Install root dependencies + run: npm ci --ignore-scripts + + - name: Build CLI + run: npm run build:cli + + - name: Install OpenShell CLI + run: bash scripts/install-openshell.sh + + - name: Run device auth health live Vitest test + env: + NVIDIA_INFERENCE_API_KEY: ${{ secrets.NVIDIA_INFERENCE_API_KEY }} + run: | + set -euo pipefail + export PATH="$HOME/.local/bin:$HOME/.npm-global/bin:$PATH" + if command -v openshell >/dev/null 2>&1; then + OPENSHELL_BIN="$(command -v openshell)" + elif [ -x "$HOME/.local/bin/openshell" ]; then + OPENSHELL_BIN="$HOME/.local/bin/openshell" + else + echo "::error::OpenShell CLI not found after install" + ls -la /usr/local/bin/openshell "$HOME/.local/bin/openshell" 2>&1 || true + exit 1 + fi + export OPENSHELL_BIN + "$OPENSHELL_BIN" --version + npx vitest run --project e2e-scenarios-live test/e2e-scenario/live/device-auth-health.test.ts --silent=false --reporter=default + + - name: Upload device auth health artifacts + if: always() + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 + with: + name: e2e-vitest-scenarios-device-auth-health + path: e2e-artifacts/vitest/device-auth-health/ + include-hidden-files: false + if-no-files-found: ignore + retention-days: 14 + + - name: Clean up Docker auth + if: always() + run: | + set -euo pipefail + docker logout docker.io || true + rm -rf "${DOCKER_CONFIG}" + channels-add-remove-vitest: needs: generate-matrix if: ${{ (inputs.jobs == '' && inputs.scenarios == '') || contains(format(',{0},', inputs.jobs), ',channels-add-remove-vitest,') || contains(format(',{0},', inputs.scenarios), ',channels-add-remove,') }} @@ -3622,6 +3725,7 @@ jobs: bedrock-runtime-compatible-anthropic-vitest, issue-2478-crash-loop-recovery-vitest, gateway-health-honest-vitest, + device-auth-health-vitest, channels-add-remove-vitest, ] if: ${{ always() && github.event_name == 'workflow_dispatch' }} diff --git a/test/e2e-scenario/live/device-auth-health.test.ts b/test/e2e-scenario/live/device-auth-health.test.ts new file mode 100644 index 00000000000..f1fb91fd2b3 --- /dev/null +++ b/test/e2e-scenario/live/device-auth-health.test.ts @@ -0,0 +1,258 @@ +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +/** + * Live Vitest replacement for test/e2e/test-device-auth-health.sh. + * + * Preserves the legacy #2342 contract with real install/onboard, sandbox HTTP + * probes, `nemoclaw status`, host port-forward checks, and gateway recovery: + * device-auth 401 responses must not be misreported as Health Offline. + */ + +import fs from "node:fs"; +import path from "node:path"; + +import { buildAvailabilityProbeEnv } from "../fixtures/availability-env.ts"; +import { resultText } from "../fixtures/clients/index.ts"; +import { + type SandboxClient, + trustedSandboxShellScript, + validateSandboxName, +} from "../fixtures/clients/sandbox.ts"; +import { expect, test } from "../fixtures/e2e-test.ts"; +import { shouldRunLiveE2EScenarios } from "../fixtures/live-project-gate.ts"; +import type { ShellProbeResult } from "../fixtures/shell-probe.ts"; +import { isTransientProviderValidationFailure } from "./network-policy-transient-provider.ts"; + +const REPO_ROOT = path.resolve(import.meta.dirname, "../../.."); +const SANDBOX_NAME = process.env.NEMOCLAW_SANDBOX_NAME ?? "e2e-health-auth"; +validateSandboxName(SANDBOX_NAME); +const DASHBOARD_PORT = process.env.NEMOCLAW_DASHBOARD_PORT ?? "18789"; +const INSTALL_ATTEMPTS = process.env.CI === "true" || process.env.GITHUB_ACTIONS === "true" ? 3 : 1; +const LIVE_TIMEOUT_MS = 30 * 60_000; + +function commandEnv(apiKey?: string): NodeJS.ProcessEnv { + const env: NodeJS.ProcessEnv = { + ...buildAvailabilityProbeEnv(), + NEMOCLAW_ACCEPT_THIRD_PARTY_SOFTWARE: "1", + NEMOCLAW_DASHBOARD_PORT: DASHBOARD_PORT, + NEMOCLAW_NON_INTERACTIVE: "1", + NEMOCLAW_RECREATE_SANDBOX: "1", + NEMOCLAW_SANDBOX_NAME: SANDBOX_NAME, + OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY ?? "nemoclaw", + }; + if (apiKey) { + env.NVIDIA_INFERENCE_API_KEY = apiKey; + env.NVIDIA_API_KEY = apiKey; + } + return env; +} + +async function bestEffort(run: () => Promise): Promise { + try { + await run(); + } catch { + // Best-effort cleanup/recovery probes should not hide primary failures. + } +} + +function assertStatusNotOffline(output: string, context: string): void { + expect(output, `${context} must not report the #2342 false Health Offline state`).not.toMatch( + /offline/i, + ); +} + +async function httpCodeFromSandbox( + sandbox: SandboxClient, + urlPath: string, + artifactName: string, +): Promise { + return await sandbox.execShell( + SANDBOX_NAME, + trustedSandboxShellScript( + `curl -so /dev/null -w '%{http_code}' --max-time 3 http://localhost:${DASHBOARD_PORT}${urlPath}`, + ), + { + artifactName, + env: commandEnv(), + timeoutMs: 30_000, + }, + ); +} + +test.skipIf(!shouldRunLiveE2EScenarios())( + "device auth health probes treat 401 as live instead of offline (#2342)", + { timeout: LIVE_TIMEOUT_MS }, + async ({ artifacts, cleanup, host, sandbox, secrets, skip }) => { + const apiKey = secrets.required("NVIDIA_INFERENCE_API_KEY"); + const installLog = artifacts.pathFor("phase-1-install-device-auth-health.log"); + + await artifacts.writeJson("scenario.json", { + id: "device-auth-health", + runner: "vitest", + legacySource: "test/e2e/test-device-auth-health.sh", + boundary: "install.sh + OpenShell sandbox exec + NemoClaw status + host curl", + sandboxName: SANDBOX_NAME, + dashboardPort: DASHBOARD_PORT, + contracts: [ + "onboard succeeds with device auth enabled", + "/health is reachable from inside the sandbox", + "the authenticated dashboard root may return 401 without being treated as offline", + "nemoclaw status reports the gateway as live, not Health Offline", + "status remains non-offline after a gateway kill/recovery attempt", + ], + }); + + const dockerInfo = await host.command("docker", ["info"], { + artifactName: "phase-0-docker-info", + env: buildAvailabilityProbeEnv(), + timeoutMs: 30_000, + }); + if (dockerInfo.exitCode !== 0) { + if (process.env.GITHUB_ACTIONS === "true") { + throw new Error(`Docker is required for device auth health E2E: ${resultText(dockerInfo)}`); + } + skip(`Docker is required for device auth health E2E: ${resultText(dockerInfo)}`); + } + + cleanup.add(`destroy device-auth sandbox ${SANDBOX_NAME}`, async () => { + await bestEffort(() => + host.nemoclaw([SANDBOX_NAME, "destroy", "--yes"], { + artifactName: "cleanup-nemoclaw-destroy-device-auth-health", + env: commandEnv(), + timeoutMs: 120_000, + }), + ); + await bestEffort(() => + sandbox.openshell(["sandbox", "delete", SANDBOX_NAME], { + artifactName: "cleanup-openshell-delete-device-auth-health", + env: commandEnv(), + timeoutMs: 60_000, + }), + ); + }); + + await bestEffort(() => + host.nemoclaw([SANDBOX_NAME, "destroy", "--yes"], { + artifactName: "pre-cleanup-nemoclaw-destroy-device-auth-health", + env: commandEnv(), + timeoutMs: 120_000, + }), + ); + await bestEffort(() => + sandbox.openshell(["sandbox", "delete", SANDBOX_NAME], { + artifactName: "pre-cleanup-openshell-delete-device-auth-health", + env: commandEnv(), + timeoutMs: 60_000, + }), + ); + + let install: ShellProbeResult | undefined; + for (let attempt = 1; attempt <= INSTALL_ATTEMPTS; attempt += 1) { + install = await host.command("bash", ["install.sh", "--non-interactive"], { + artifactName: + attempt === 1 + ? "phase-1-install-device-auth-health" + : `phase-1-install-device-auth-health-attempt-${attempt}`, + cwd: REPO_ROOT, + env: commandEnv(apiKey), + redactionValues: [apiKey], + timeoutMs: 20 * 60_000, + }); + fs.writeFileSync(installLog, resultText(install)); + if (install.exitCode === 0) break; + if (isTransientProviderValidationFailure(install) && attempt < INSTALL_ATTEMPTS) { + await new Promise((resolve) => setTimeout(resolve, 10_000 * attempt)); + continue; + } + break; + } + expect(install, "install command must run").toBeDefined(); + expect(install?.exitCode, resultText(install as ShellProbeResult)).toBe(0); + + await host.expectListed(SANDBOX_NAME, { + artifactName: "phase-1-nemoclaw-list-device-auth-health", + env: commandEnv(), + timeoutMs: 60_000, + }); + + const health = await httpCodeFromSandbox(sandbox, "/health", "phase-2-sandbox-health-code"); + expect(health.exitCode, resultText(health)).toBe(0); + expect(health.stdout.trim()).toBe("200"); + + const root = await httpCodeFromSandbox(sandbox, "/", "phase-2-sandbox-root-code"); + expect(root.exitCode, resultText(root)).toBe(0); + expect(["200", "401"], `dashboard root returned ${root.stdout.trim()}`).toContain( + root.stdout.trim(), + ); + + const status = await host.nemoclaw([SANDBOX_NAME, "status"], { + artifactName: "phase-3-nemoclaw-status-device-auth-health", + env: commandEnv(), + timeoutMs: 120_000, + }); + expect(status.exitCode, resultText(status)).toBe(0); + assertStatusNotOffline(resultText(status), "initial status"); + expect(resultText(status)).toMatch(/running|online|healthy|OpenClaw|Ready/i); + + const hostHealth = await host.command( + "curl", + [ + "-so", + "/dev/null", + "-w", + "%{http_code}", + "--max-time", + "5", + `http://127.0.0.1:${DASHBOARD_PORT}/health`, + ], + { + artifactName: "phase-4-host-health-code", + env: buildAvailabilityProbeEnv(), + timeoutMs: 30_000, + }, + ); + if (hostHealth.stdout.trim() && hostHealth.stdout.trim() !== "000") { + expect( + ["200", "401"], + `host dashboard health returned ${hostHealth.stdout.trim()}`, + ).toContain(hostHealth.stdout.trim()); + } + + await sandbox.execShell( + SANDBOX_NAME, + trustedSandboxShellScript("pkill -f 'openclaw.*gateway' 2>/dev/null || true"), + { + artifactName: "phase-5-kill-gateway-process", + env: commandEnv(), + timeoutMs: 30_000, + }, + ); + await new Promise((resolve) => setTimeout(resolve, 3_000)); + + const recoveryStatus = await host.nemoclaw([SANDBOX_NAME, "status"], { + artifactName: "phase-5-nemoclaw-status-after-gateway-kill", + env: commandEnv(), + timeoutMs: 120_000, + }); + assertStatusNotOffline(resultText(recoveryStatus), "recovery status"); + + for (let attempt = 1; attempt <= 30; attempt += 1) { + const recoveredHealth = await httpCodeFromSandbox( + sandbox, + "/health", + `phase-5-recovery-health-code-attempt-${attempt}`, + ); + const code = recoveredHealth.stdout.trim(); + if (code === "200" || code === "401") { + await artifacts.writeJson("gateway-recovered.json", { attempt, code }); + return; + } + await new Promise((resolve) => setTimeout(resolve, 5_000)); + } + + await artifacts.writeJson("gateway-recovery-inconclusive.json", { + reason: "Gateway did not recover within 150s; legacy shell treated this as optional.", + }); + }, +); From c1d070d791c5eb8a40c6fcdd0aa4eb05ed128f4f Mon Sep 17 00:00:00 2001 From: Carlos Villela Date: Fri, 19 Jun 2026 14:40:06 -0700 Subject: [PATCH 2/6] test(e2e): assert device auth recovery status Signed-off-by: Carlos Villela --- test/e2e-scenario/live/device-auth-health.test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/test/e2e-scenario/live/device-auth-health.test.ts b/test/e2e-scenario/live/device-auth-health.test.ts index f1fb91fd2b3..676b8c687a7 100644 --- a/test/e2e-scenario/live/device-auth-health.test.ts +++ b/test/e2e-scenario/live/device-auth-health.test.ts @@ -235,6 +235,7 @@ test.skipIf(!shouldRunLiveE2EScenarios())( env: commandEnv(), timeoutMs: 120_000, }); + expect(recoveryStatus.exitCode, resultText(recoveryStatus)).toBe(0); assertStatusNotOffline(resultText(recoveryStatus), "recovery status"); for (let attempt = 1; attempt <= 30; attempt += 1) { From 370db91336bcc42f16bc2723f4f49c7b536a4c47 Mon Sep 17 00:00:00 2001 From: Carlos Villela Date: Fri, 19 Jun 2026 14:49:53 -0700 Subject: [PATCH 3/6] test(e2e): relax workflow inventory timeout Signed-off-by: Carlos Villela --- .../support-tests/e2e-scenarios-workflow.test.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/test/e2e-scenario/support-tests/e2e-scenarios-workflow.test.ts b/test/e2e-scenario/support-tests/e2e-scenarios-workflow.test.ts index 2e3e22e0a7c..c812fb20caa 100644 --- a/test/e2e-scenario/support-tests/e2e-scenarios-workflow.test.ts +++ b/test/e2e-scenario/support-tests/e2e-scenarios-workflow.test.ts @@ -8,14 +8,13 @@ import path from "node:path"; import { describe, expect, it } from "vitest"; import YAML from "yaml"; - -import { testTimeoutOptions } from "../../helpers/timeouts"; import { evaluateE2eVitestWorkflowDispatchSelectors, readFreeStandingJobsInventory, validateE2eVitestScenariosWorkflowBoundary, validateFreeStandingWorkflowInventory, } from "../../../tools/e2e-scenarios/workflow-boundary.mts"; +import { testTimeoutOptions } from "../../helpers/timeouts"; function readWorkflow(): Record { return YAML.parse( @@ -565,7 +564,7 @@ describe("e2e-vitest-scenarios workflow boundary", () => { }, ); - it("derives the free-standing inventory from workflow job metadata", () => { + it("derives the free-standing inventory from workflow job metadata", { timeout: 60_000 }, () => { const inventory = readFreeStandingJobsInventory(); expect(validateFreeStandingWorkflowInventory()).toEqual([]); expect(inventory.allowedJobs).toContain("openshell-version-pin-vitest"); From 16750b84d501f1dd06b8df2f4d38d3e234ffcd40 Mon Sep 17 00:00:00 2001 From: Carlos Villela Date: Sat, 20 Jun 2026 08:53:37 -0700 Subject: [PATCH 4/6] test(e2e): move scenario logic out of test wrapper Signed-off-by: Carlos Villela --- .../live/device-auth-health.scenario.ts | 259 ++++++++++++++++++ .../live/device-auth-health.test.ts | 257 +---------------- 2 files changed, 260 insertions(+), 256 deletions(-) create mode 100644 test/e2e-scenario/live/device-auth-health.scenario.ts diff --git a/test/e2e-scenario/live/device-auth-health.scenario.ts b/test/e2e-scenario/live/device-auth-health.scenario.ts new file mode 100644 index 00000000000..676b8c687a7 --- /dev/null +++ b/test/e2e-scenario/live/device-auth-health.scenario.ts @@ -0,0 +1,259 @@ +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +/** + * Live Vitest replacement for test/e2e/test-device-auth-health.sh. + * + * Preserves the legacy #2342 contract with real install/onboard, sandbox HTTP + * probes, `nemoclaw status`, host port-forward checks, and gateway recovery: + * device-auth 401 responses must not be misreported as Health Offline. + */ + +import fs from "node:fs"; +import path from "node:path"; + +import { buildAvailabilityProbeEnv } from "../fixtures/availability-env.ts"; +import { resultText } from "../fixtures/clients/index.ts"; +import { + type SandboxClient, + trustedSandboxShellScript, + validateSandboxName, +} from "../fixtures/clients/sandbox.ts"; +import { expect, test } from "../fixtures/e2e-test.ts"; +import { shouldRunLiveE2EScenarios } from "../fixtures/live-project-gate.ts"; +import type { ShellProbeResult } from "../fixtures/shell-probe.ts"; +import { isTransientProviderValidationFailure } from "./network-policy-transient-provider.ts"; + +const REPO_ROOT = path.resolve(import.meta.dirname, "../../.."); +const SANDBOX_NAME = process.env.NEMOCLAW_SANDBOX_NAME ?? "e2e-health-auth"; +validateSandboxName(SANDBOX_NAME); +const DASHBOARD_PORT = process.env.NEMOCLAW_DASHBOARD_PORT ?? "18789"; +const INSTALL_ATTEMPTS = process.env.CI === "true" || process.env.GITHUB_ACTIONS === "true" ? 3 : 1; +const LIVE_TIMEOUT_MS = 30 * 60_000; + +function commandEnv(apiKey?: string): NodeJS.ProcessEnv { + const env: NodeJS.ProcessEnv = { + ...buildAvailabilityProbeEnv(), + NEMOCLAW_ACCEPT_THIRD_PARTY_SOFTWARE: "1", + NEMOCLAW_DASHBOARD_PORT: DASHBOARD_PORT, + NEMOCLAW_NON_INTERACTIVE: "1", + NEMOCLAW_RECREATE_SANDBOX: "1", + NEMOCLAW_SANDBOX_NAME: SANDBOX_NAME, + OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY ?? "nemoclaw", + }; + if (apiKey) { + env.NVIDIA_INFERENCE_API_KEY = apiKey; + env.NVIDIA_API_KEY = apiKey; + } + return env; +} + +async function bestEffort(run: () => Promise): Promise { + try { + await run(); + } catch { + // Best-effort cleanup/recovery probes should not hide primary failures. + } +} + +function assertStatusNotOffline(output: string, context: string): void { + expect(output, `${context} must not report the #2342 false Health Offline state`).not.toMatch( + /offline/i, + ); +} + +async function httpCodeFromSandbox( + sandbox: SandboxClient, + urlPath: string, + artifactName: string, +): Promise { + return await sandbox.execShell( + SANDBOX_NAME, + trustedSandboxShellScript( + `curl -so /dev/null -w '%{http_code}' --max-time 3 http://localhost:${DASHBOARD_PORT}${urlPath}`, + ), + { + artifactName, + env: commandEnv(), + timeoutMs: 30_000, + }, + ); +} + +test.skipIf(!shouldRunLiveE2EScenarios())( + "device auth health probes treat 401 as live instead of offline (#2342)", + { timeout: LIVE_TIMEOUT_MS }, + async ({ artifacts, cleanup, host, sandbox, secrets, skip }) => { + const apiKey = secrets.required("NVIDIA_INFERENCE_API_KEY"); + const installLog = artifacts.pathFor("phase-1-install-device-auth-health.log"); + + await artifacts.writeJson("scenario.json", { + id: "device-auth-health", + runner: "vitest", + legacySource: "test/e2e/test-device-auth-health.sh", + boundary: "install.sh + OpenShell sandbox exec + NemoClaw status + host curl", + sandboxName: SANDBOX_NAME, + dashboardPort: DASHBOARD_PORT, + contracts: [ + "onboard succeeds with device auth enabled", + "/health is reachable from inside the sandbox", + "the authenticated dashboard root may return 401 without being treated as offline", + "nemoclaw status reports the gateway as live, not Health Offline", + "status remains non-offline after a gateway kill/recovery attempt", + ], + }); + + const dockerInfo = await host.command("docker", ["info"], { + artifactName: "phase-0-docker-info", + env: buildAvailabilityProbeEnv(), + timeoutMs: 30_000, + }); + if (dockerInfo.exitCode !== 0) { + if (process.env.GITHUB_ACTIONS === "true") { + throw new Error(`Docker is required for device auth health E2E: ${resultText(dockerInfo)}`); + } + skip(`Docker is required for device auth health E2E: ${resultText(dockerInfo)}`); + } + + cleanup.add(`destroy device-auth sandbox ${SANDBOX_NAME}`, async () => { + await bestEffort(() => + host.nemoclaw([SANDBOX_NAME, "destroy", "--yes"], { + artifactName: "cleanup-nemoclaw-destroy-device-auth-health", + env: commandEnv(), + timeoutMs: 120_000, + }), + ); + await bestEffort(() => + sandbox.openshell(["sandbox", "delete", SANDBOX_NAME], { + artifactName: "cleanup-openshell-delete-device-auth-health", + env: commandEnv(), + timeoutMs: 60_000, + }), + ); + }); + + await bestEffort(() => + host.nemoclaw([SANDBOX_NAME, "destroy", "--yes"], { + artifactName: "pre-cleanup-nemoclaw-destroy-device-auth-health", + env: commandEnv(), + timeoutMs: 120_000, + }), + ); + await bestEffort(() => + sandbox.openshell(["sandbox", "delete", SANDBOX_NAME], { + artifactName: "pre-cleanup-openshell-delete-device-auth-health", + env: commandEnv(), + timeoutMs: 60_000, + }), + ); + + let install: ShellProbeResult | undefined; + for (let attempt = 1; attempt <= INSTALL_ATTEMPTS; attempt += 1) { + install = await host.command("bash", ["install.sh", "--non-interactive"], { + artifactName: + attempt === 1 + ? "phase-1-install-device-auth-health" + : `phase-1-install-device-auth-health-attempt-${attempt}`, + cwd: REPO_ROOT, + env: commandEnv(apiKey), + redactionValues: [apiKey], + timeoutMs: 20 * 60_000, + }); + fs.writeFileSync(installLog, resultText(install)); + if (install.exitCode === 0) break; + if (isTransientProviderValidationFailure(install) && attempt < INSTALL_ATTEMPTS) { + await new Promise((resolve) => setTimeout(resolve, 10_000 * attempt)); + continue; + } + break; + } + expect(install, "install command must run").toBeDefined(); + expect(install?.exitCode, resultText(install as ShellProbeResult)).toBe(0); + + await host.expectListed(SANDBOX_NAME, { + artifactName: "phase-1-nemoclaw-list-device-auth-health", + env: commandEnv(), + timeoutMs: 60_000, + }); + + const health = await httpCodeFromSandbox(sandbox, "/health", "phase-2-sandbox-health-code"); + expect(health.exitCode, resultText(health)).toBe(0); + expect(health.stdout.trim()).toBe("200"); + + const root = await httpCodeFromSandbox(sandbox, "/", "phase-2-sandbox-root-code"); + expect(root.exitCode, resultText(root)).toBe(0); + expect(["200", "401"], `dashboard root returned ${root.stdout.trim()}`).toContain( + root.stdout.trim(), + ); + + const status = await host.nemoclaw([SANDBOX_NAME, "status"], { + artifactName: "phase-3-nemoclaw-status-device-auth-health", + env: commandEnv(), + timeoutMs: 120_000, + }); + expect(status.exitCode, resultText(status)).toBe(0); + assertStatusNotOffline(resultText(status), "initial status"); + expect(resultText(status)).toMatch(/running|online|healthy|OpenClaw|Ready/i); + + const hostHealth = await host.command( + "curl", + [ + "-so", + "/dev/null", + "-w", + "%{http_code}", + "--max-time", + "5", + `http://127.0.0.1:${DASHBOARD_PORT}/health`, + ], + { + artifactName: "phase-4-host-health-code", + env: buildAvailabilityProbeEnv(), + timeoutMs: 30_000, + }, + ); + if (hostHealth.stdout.trim() && hostHealth.stdout.trim() !== "000") { + expect( + ["200", "401"], + `host dashboard health returned ${hostHealth.stdout.trim()}`, + ).toContain(hostHealth.stdout.trim()); + } + + await sandbox.execShell( + SANDBOX_NAME, + trustedSandboxShellScript("pkill -f 'openclaw.*gateway' 2>/dev/null || true"), + { + artifactName: "phase-5-kill-gateway-process", + env: commandEnv(), + timeoutMs: 30_000, + }, + ); + await new Promise((resolve) => setTimeout(resolve, 3_000)); + + const recoveryStatus = await host.nemoclaw([SANDBOX_NAME, "status"], { + artifactName: "phase-5-nemoclaw-status-after-gateway-kill", + env: commandEnv(), + timeoutMs: 120_000, + }); + expect(recoveryStatus.exitCode, resultText(recoveryStatus)).toBe(0); + assertStatusNotOffline(resultText(recoveryStatus), "recovery status"); + + for (let attempt = 1; attempt <= 30; attempt += 1) { + const recoveredHealth = await httpCodeFromSandbox( + sandbox, + "/health", + `phase-5-recovery-health-code-attempt-${attempt}`, + ); + const code = recoveredHealth.stdout.trim(); + if (code === "200" || code === "401") { + await artifacts.writeJson("gateway-recovered.json", { attempt, code }); + return; + } + await new Promise((resolve) => setTimeout(resolve, 5_000)); + } + + await artifacts.writeJson("gateway-recovery-inconclusive.json", { + reason: "Gateway did not recover within 150s; legacy shell treated this as optional.", + }); + }, +); diff --git a/test/e2e-scenario/live/device-auth-health.test.ts b/test/e2e-scenario/live/device-auth-health.test.ts index 676b8c687a7..1e054939fe8 100644 --- a/test/e2e-scenario/live/device-auth-health.test.ts +++ b/test/e2e-scenario/live/device-auth-health.test.ts @@ -1,259 +1,4 @@ // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // SPDX-License-Identifier: Apache-2.0 -/** - * Live Vitest replacement for test/e2e/test-device-auth-health.sh. - * - * Preserves the legacy #2342 contract with real install/onboard, sandbox HTTP - * probes, `nemoclaw status`, host port-forward checks, and gateway recovery: - * device-auth 401 responses must not be misreported as Health Offline. - */ - -import fs from "node:fs"; -import path from "node:path"; - -import { buildAvailabilityProbeEnv } from "../fixtures/availability-env.ts"; -import { resultText } from "../fixtures/clients/index.ts"; -import { - type SandboxClient, - trustedSandboxShellScript, - validateSandboxName, -} from "../fixtures/clients/sandbox.ts"; -import { expect, test } from "../fixtures/e2e-test.ts"; -import { shouldRunLiveE2EScenarios } from "../fixtures/live-project-gate.ts"; -import type { ShellProbeResult } from "../fixtures/shell-probe.ts"; -import { isTransientProviderValidationFailure } from "./network-policy-transient-provider.ts"; - -const REPO_ROOT = path.resolve(import.meta.dirname, "../../.."); -const SANDBOX_NAME = process.env.NEMOCLAW_SANDBOX_NAME ?? "e2e-health-auth"; -validateSandboxName(SANDBOX_NAME); -const DASHBOARD_PORT = process.env.NEMOCLAW_DASHBOARD_PORT ?? "18789"; -const INSTALL_ATTEMPTS = process.env.CI === "true" || process.env.GITHUB_ACTIONS === "true" ? 3 : 1; -const LIVE_TIMEOUT_MS = 30 * 60_000; - -function commandEnv(apiKey?: string): NodeJS.ProcessEnv { - const env: NodeJS.ProcessEnv = { - ...buildAvailabilityProbeEnv(), - NEMOCLAW_ACCEPT_THIRD_PARTY_SOFTWARE: "1", - NEMOCLAW_DASHBOARD_PORT: DASHBOARD_PORT, - NEMOCLAW_NON_INTERACTIVE: "1", - NEMOCLAW_RECREATE_SANDBOX: "1", - NEMOCLAW_SANDBOX_NAME: SANDBOX_NAME, - OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY ?? "nemoclaw", - }; - if (apiKey) { - env.NVIDIA_INFERENCE_API_KEY = apiKey; - env.NVIDIA_API_KEY = apiKey; - } - return env; -} - -async function bestEffort(run: () => Promise): Promise { - try { - await run(); - } catch { - // Best-effort cleanup/recovery probes should not hide primary failures. - } -} - -function assertStatusNotOffline(output: string, context: string): void { - expect(output, `${context} must not report the #2342 false Health Offline state`).not.toMatch( - /offline/i, - ); -} - -async function httpCodeFromSandbox( - sandbox: SandboxClient, - urlPath: string, - artifactName: string, -): Promise { - return await sandbox.execShell( - SANDBOX_NAME, - trustedSandboxShellScript( - `curl -so /dev/null -w '%{http_code}' --max-time 3 http://localhost:${DASHBOARD_PORT}${urlPath}`, - ), - { - artifactName, - env: commandEnv(), - timeoutMs: 30_000, - }, - ); -} - -test.skipIf(!shouldRunLiveE2EScenarios())( - "device auth health probes treat 401 as live instead of offline (#2342)", - { timeout: LIVE_TIMEOUT_MS }, - async ({ artifacts, cleanup, host, sandbox, secrets, skip }) => { - const apiKey = secrets.required("NVIDIA_INFERENCE_API_KEY"); - const installLog = artifacts.pathFor("phase-1-install-device-auth-health.log"); - - await artifacts.writeJson("scenario.json", { - id: "device-auth-health", - runner: "vitest", - legacySource: "test/e2e/test-device-auth-health.sh", - boundary: "install.sh + OpenShell sandbox exec + NemoClaw status + host curl", - sandboxName: SANDBOX_NAME, - dashboardPort: DASHBOARD_PORT, - contracts: [ - "onboard succeeds with device auth enabled", - "/health is reachable from inside the sandbox", - "the authenticated dashboard root may return 401 without being treated as offline", - "nemoclaw status reports the gateway as live, not Health Offline", - "status remains non-offline after a gateway kill/recovery attempt", - ], - }); - - const dockerInfo = await host.command("docker", ["info"], { - artifactName: "phase-0-docker-info", - env: buildAvailabilityProbeEnv(), - timeoutMs: 30_000, - }); - if (dockerInfo.exitCode !== 0) { - if (process.env.GITHUB_ACTIONS === "true") { - throw new Error(`Docker is required for device auth health E2E: ${resultText(dockerInfo)}`); - } - skip(`Docker is required for device auth health E2E: ${resultText(dockerInfo)}`); - } - - cleanup.add(`destroy device-auth sandbox ${SANDBOX_NAME}`, async () => { - await bestEffort(() => - host.nemoclaw([SANDBOX_NAME, "destroy", "--yes"], { - artifactName: "cleanup-nemoclaw-destroy-device-auth-health", - env: commandEnv(), - timeoutMs: 120_000, - }), - ); - await bestEffort(() => - sandbox.openshell(["sandbox", "delete", SANDBOX_NAME], { - artifactName: "cleanup-openshell-delete-device-auth-health", - env: commandEnv(), - timeoutMs: 60_000, - }), - ); - }); - - await bestEffort(() => - host.nemoclaw([SANDBOX_NAME, "destroy", "--yes"], { - artifactName: "pre-cleanup-nemoclaw-destroy-device-auth-health", - env: commandEnv(), - timeoutMs: 120_000, - }), - ); - await bestEffort(() => - sandbox.openshell(["sandbox", "delete", SANDBOX_NAME], { - artifactName: "pre-cleanup-openshell-delete-device-auth-health", - env: commandEnv(), - timeoutMs: 60_000, - }), - ); - - let install: ShellProbeResult | undefined; - for (let attempt = 1; attempt <= INSTALL_ATTEMPTS; attempt += 1) { - install = await host.command("bash", ["install.sh", "--non-interactive"], { - artifactName: - attempt === 1 - ? "phase-1-install-device-auth-health" - : `phase-1-install-device-auth-health-attempt-${attempt}`, - cwd: REPO_ROOT, - env: commandEnv(apiKey), - redactionValues: [apiKey], - timeoutMs: 20 * 60_000, - }); - fs.writeFileSync(installLog, resultText(install)); - if (install.exitCode === 0) break; - if (isTransientProviderValidationFailure(install) && attempt < INSTALL_ATTEMPTS) { - await new Promise((resolve) => setTimeout(resolve, 10_000 * attempt)); - continue; - } - break; - } - expect(install, "install command must run").toBeDefined(); - expect(install?.exitCode, resultText(install as ShellProbeResult)).toBe(0); - - await host.expectListed(SANDBOX_NAME, { - artifactName: "phase-1-nemoclaw-list-device-auth-health", - env: commandEnv(), - timeoutMs: 60_000, - }); - - const health = await httpCodeFromSandbox(sandbox, "/health", "phase-2-sandbox-health-code"); - expect(health.exitCode, resultText(health)).toBe(0); - expect(health.stdout.trim()).toBe("200"); - - const root = await httpCodeFromSandbox(sandbox, "/", "phase-2-sandbox-root-code"); - expect(root.exitCode, resultText(root)).toBe(0); - expect(["200", "401"], `dashboard root returned ${root.stdout.trim()}`).toContain( - root.stdout.trim(), - ); - - const status = await host.nemoclaw([SANDBOX_NAME, "status"], { - artifactName: "phase-3-nemoclaw-status-device-auth-health", - env: commandEnv(), - timeoutMs: 120_000, - }); - expect(status.exitCode, resultText(status)).toBe(0); - assertStatusNotOffline(resultText(status), "initial status"); - expect(resultText(status)).toMatch(/running|online|healthy|OpenClaw|Ready/i); - - const hostHealth = await host.command( - "curl", - [ - "-so", - "/dev/null", - "-w", - "%{http_code}", - "--max-time", - "5", - `http://127.0.0.1:${DASHBOARD_PORT}/health`, - ], - { - artifactName: "phase-4-host-health-code", - env: buildAvailabilityProbeEnv(), - timeoutMs: 30_000, - }, - ); - if (hostHealth.stdout.trim() && hostHealth.stdout.trim() !== "000") { - expect( - ["200", "401"], - `host dashboard health returned ${hostHealth.stdout.trim()}`, - ).toContain(hostHealth.stdout.trim()); - } - - await sandbox.execShell( - SANDBOX_NAME, - trustedSandboxShellScript("pkill -f 'openclaw.*gateway' 2>/dev/null || true"), - { - artifactName: "phase-5-kill-gateway-process", - env: commandEnv(), - timeoutMs: 30_000, - }, - ); - await new Promise((resolve) => setTimeout(resolve, 3_000)); - - const recoveryStatus = await host.nemoclaw([SANDBOX_NAME, "status"], { - artifactName: "phase-5-nemoclaw-status-after-gateway-kill", - env: commandEnv(), - timeoutMs: 120_000, - }); - expect(recoveryStatus.exitCode, resultText(recoveryStatus)).toBe(0); - assertStatusNotOffline(resultText(recoveryStatus), "recovery status"); - - for (let attempt = 1; attempt <= 30; attempt += 1) { - const recoveredHealth = await httpCodeFromSandbox( - sandbox, - "/health", - `phase-5-recovery-health-code-attempt-${attempt}`, - ); - const code = recoveredHealth.stdout.trim(); - if (code === "200" || code === "401") { - await artifacts.writeJson("gateway-recovered.json", { attempt, code }); - return; - } - await new Promise((resolve) => setTimeout(resolve, 5_000)); - } - - await artifacts.writeJson("gateway-recovery-inconclusive.json", { - reason: "Gateway did not recover within 150s; legacy shell treated this as optional.", - }); - }, -); +import "./device-auth-health.scenario.ts"; From 2adb4aad321dd43ae09f8415a651995d9c97aa30 Mon Sep 17 00:00:00 2001 From: Carlos Villela Date: Sat, 20 Jun 2026 09:28:01 -0700 Subject: [PATCH 5/6] test(e2e): restore scenario logic to test file Signed-off-by: Carlos Villela --- .../live/device-auth-health.scenario.ts | 259 ------------------ .../live/device-auth-health.test.ts | 257 ++++++++++++++++- 2 files changed, 256 insertions(+), 260 deletions(-) delete mode 100644 test/e2e-scenario/live/device-auth-health.scenario.ts diff --git a/test/e2e-scenario/live/device-auth-health.scenario.ts b/test/e2e-scenario/live/device-auth-health.scenario.ts deleted file mode 100644 index 676b8c687a7..00000000000 --- a/test/e2e-scenario/live/device-auth-health.scenario.ts +++ /dev/null @@ -1,259 +0,0 @@ -// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. -// SPDX-License-Identifier: Apache-2.0 - -/** - * Live Vitest replacement for test/e2e/test-device-auth-health.sh. - * - * Preserves the legacy #2342 contract with real install/onboard, sandbox HTTP - * probes, `nemoclaw status`, host port-forward checks, and gateway recovery: - * device-auth 401 responses must not be misreported as Health Offline. - */ - -import fs from "node:fs"; -import path from "node:path"; - -import { buildAvailabilityProbeEnv } from "../fixtures/availability-env.ts"; -import { resultText } from "../fixtures/clients/index.ts"; -import { - type SandboxClient, - trustedSandboxShellScript, - validateSandboxName, -} from "../fixtures/clients/sandbox.ts"; -import { expect, test } from "../fixtures/e2e-test.ts"; -import { shouldRunLiveE2EScenarios } from "../fixtures/live-project-gate.ts"; -import type { ShellProbeResult } from "../fixtures/shell-probe.ts"; -import { isTransientProviderValidationFailure } from "./network-policy-transient-provider.ts"; - -const REPO_ROOT = path.resolve(import.meta.dirname, "../../.."); -const SANDBOX_NAME = process.env.NEMOCLAW_SANDBOX_NAME ?? "e2e-health-auth"; -validateSandboxName(SANDBOX_NAME); -const DASHBOARD_PORT = process.env.NEMOCLAW_DASHBOARD_PORT ?? "18789"; -const INSTALL_ATTEMPTS = process.env.CI === "true" || process.env.GITHUB_ACTIONS === "true" ? 3 : 1; -const LIVE_TIMEOUT_MS = 30 * 60_000; - -function commandEnv(apiKey?: string): NodeJS.ProcessEnv { - const env: NodeJS.ProcessEnv = { - ...buildAvailabilityProbeEnv(), - NEMOCLAW_ACCEPT_THIRD_PARTY_SOFTWARE: "1", - NEMOCLAW_DASHBOARD_PORT: DASHBOARD_PORT, - NEMOCLAW_NON_INTERACTIVE: "1", - NEMOCLAW_RECREATE_SANDBOX: "1", - NEMOCLAW_SANDBOX_NAME: SANDBOX_NAME, - OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY ?? "nemoclaw", - }; - if (apiKey) { - env.NVIDIA_INFERENCE_API_KEY = apiKey; - env.NVIDIA_API_KEY = apiKey; - } - return env; -} - -async function bestEffort(run: () => Promise): Promise { - try { - await run(); - } catch { - // Best-effort cleanup/recovery probes should not hide primary failures. - } -} - -function assertStatusNotOffline(output: string, context: string): void { - expect(output, `${context} must not report the #2342 false Health Offline state`).not.toMatch( - /offline/i, - ); -} - -async function httpCodeFromSandbox( - sandbox: SandboxClient, - urlPath: string, - artifactName: string, -): Promise { - return await sandbox.execShell( - SANDBOX_NAME, - trustedSandboxShellScript( - `curl -so /dev/null -w '%{http_code}' --max-time 3 http://localhost:${DASHBOARD_PORT}${urlPath}`, - ), - { - artifactName, - env: commandEnv(), - timeoutMs: 30_000, - }, - ); -} - -test.skipIf(!shouldRunLiveE2EScenarios())( - "device auth health probes treat 401 as live instead of offline (#2342)", - { timeout: LIVE_TIMEOUT_MS }, - async ({ artifacts, cleanup, host, sandbox, secrets, skip }) => { - const apiKey = secrets.required("NVIDIA_INFERENCE_API_KEY"); - const installLog = artifacts.pathFor("phase-1-install-device-auth-health.log"); - - await artifacts.writeJson("scenario.json", { - id: "device-auth-health", - runner: "vitest", - legacySource: "test/e2e/test-device-auth-health.sh", - boundary: "install.sh + OpenShell sandbox exec + NemoClaw status + host curl", - sandboxName: SANDBOX_NAME, - dashboardPort: DASHBOARD_PORT, - contracts: [ - "onboard succeeds with device auth enabled", - "/health is reachable from inside the sandbox", - "the authenticated dashboard root may return 401 without being treated as offline", - "nemoclaw status reports the gateway as live, not Health Offline", - "status remains non-offline after a gateway kill/recovery attempt", - ], - }); - - const dockerInfo = await host.command("docker", ["info"], { - artifactName: "phase-0-docker-info", - env: buildAvailabilityProbeEnv(), - timeoutMs: 30_000, - }); - if (dockerInfo.exitCode !== 0) { - if (process.env.GITHUB_ACTIONS === "true") { - throw new Error(`Docker is required for device auth health E2E: ${resultText(dockerInfo)}`); - } - skip(`Docker is required for device auth health E2E: ${resultText(dockerInfo)}`); - } - - cleanup.add(`destroy device-auth sandbox ${SANDBOX_NAME}`, async () => { - await bestEffort(() => - host.nemoclaw([SANDBOX_NAME, "destroy", "--yes"], { - artifactName: "cleanup-nemoclaw-destroy-device-auth-health", - env: commandEnv(), - timeoutMs: 120_000, - }), - ); - await bestEffort(() => - sandbox.openshell(["sandbox", "delete", SANDBOX_NAME], { - artifactName: "cleanup-openshell-delete-device-auth-health", - env: commandEnv(), - timeoutMs: 60_000, - }), - ); - }); - - await bestEffort(() => - host.nemoclaw([SANDBOX_NAME, "destroy", "--yes"], { - artifactName: "pre-cleanup-nemoclaw-destroy-device-auth-health", - env: commandEnv(), - timeoutMs: 120_000, - }), - ); - await bestEffort(() => - sandbox.openshell(["sandbox", "delete", SANDBOX_NAME], { - artifactName: "pre-cleanup-openshell-delete-device-auth-health", - env: commandEnv(), - timeoutMs: 60_000, - }), - ); - - let install: ShellProbeResult | undefined; - for (let attempt = 1; attempt <= INSTALL_ATTEMPTS; attempt += 1) { - install = await host.command("bash", ["install.sh", "--non-interactive"], { - artifactName: - attempt === 1 - ? "phase-1-install-device-auth-health" - : `phase-1-install-device-auth-health-attempt-${attempt}`, - cwd: REPO_ROOT, - env: commandEnv(apiKey), - redactionValues: [apiKey], - timeoutMs: 20 * 60_000, - }); - fs.writeFileSync(installLog, resultText(install)); - if (install.exitCode === 0) break; - if (isTransientProviderValidationFailure(install) && attempt < INSTALL_ATTEMPTS) { - await new Promise((resolve) => setTimeout(resolve, 10_000 * attempt)); - continue; - } - break; - } - expect(install, "install command must run").toBeDefined(); - expect(install?.exitCode, resultText(install as ShellProbeResult)).toBe(0); - - await host.expectListed(SANDBOX_NAME, { - artifactName: "phase-1-nemoclaw-list-device-auth-health", - env: commandEnv(), - timeoutMs: 60_000, - }); - - const health = await httpCodeFromSandbox(sandbox, "/health", "phase-2-sandbox-health-code"); - expect(health.exitCode, resultText(health)).toBe(0); - expect(health.stdout.trim()).toBe("200"); - - const root = await httpCodeFromSandbox(sandbox, "/", "phase-2-sandbox-root-code"); - expect(root.exitCode, resultText(root)).toBe(0); - expect(["200", "401"], `dashboard root returned ${root.stdout.trim()}`).toContain( - root.stdout.trim(), - ); - - const status = await host.nemoclaw([SANDBOX_NAME, "status"], { - artifactName: "phase-3-nemoclaw-status-device-auth-health", - env: commandEnv(), - timeoutMs: 120_000, - }); - expect(status.exitCode, resultText(status)).toBe(0); - assertStatusNotOffline(resultText(status), "initial status"); - expect(resultText(status)).toMatch(/running|online|healthy|OpenClaw|Ready/i); - - const hostHealth = await host.command( - "curl", - [ - "-so", - "/dev/null", - "-w", - "%{http_code}", - "--max-time", - "5", - `http://127.0.0.1:${DASHBOARD_PORT}/health`, - ], - { - artifactName: "phase-4-host-health-code", - env: buildAvailabilityProbeEnv(), - timeoutMs: 30_000, - }, - ); - if (hostHealth.stdout.trim() && hostHealth.stdout.trim() !== "000") { - expect( - ["200", "401"], - `host dashboard health returned ${hostHealth.stdout.trim()}`, - ).toContain(hostHealth.stdout.trim()); - } - - await sandbox.execShell( - SANDBOX_NAME, - trustedSandboxShellScript("pkill -f 'openclaw.*gateway' 2>/dev/null || true"), - { - artifactName: "phase-5-kill-gateway-process", - env: commandEnv(), - timeoutMs: 30_000, - }, - ); - await new Promise((resolve) => setTimeout(resolve, 3_000)); - - const recoveryStatus = await host.nemoclaw([SANDBOX_NAME, "status"], { - artifactName: "phase-5-nemoclaw-status-after-gateway-kill", - env: commandEnv(), - timeoutMs: 120_000, - }); - expect(recoveryStatus.exitCode, resultText(recoveryStatus)).toBe(0); - assertStatusNotOffline(resultText(recoveryStatus), "recovery status"); - - for (let attempt = 1; attempt <= 30; attempt += 1) { - const recoveredHealth = await httpCodeFromSandbox( - sandbox, - "/health", - `phase-5-recovery-health-code-attempt-${attempt}`, - ); - const code = recoveredHealth.stdout.trim(); - if (code === "200" || code === "401") { - await artifacts.writeJson("gateway-recovered.json", { attempt, code }); - return; - } - await new Promise((resolve) => setTimeout(resolve, 5_000)); - } - - await artifacts.writeJson("gateway-recovery-inconclusive.json", { - reason: "Gateway did not recover within 150s; legacy shell treated this as optional.", - }); - }, -); diff --git a/test/e2e-scenario/live/device-auth-health.test.ts b/test/e2e-scenario/live/device-auth-health.test.ts index 1e054939fe8..676b8c687a7 100644 --- a/test/e2e-scenario/live/device-auth-health.test.ts +++ b/test/e2e-scenario/live/device-auth-health.test.ts @@ -1,4 +1,259 @@ // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // SPDX-License-Identifier: Apache-2.0 -import "./device-auth-health.scenario.ts"; +/** + * Live Vitest replacement for test/e2e/test-device-auth-health.sh. + * + * Preserves the legacy #2342 contract with real install/onboard, sandbox HTTP + * probes, `nemoclaw status`, host port-forward checks, and gateway recovery: + * device-auth 401 responses must not be misreported as Health Offline. + */ + +import fs from "node:fs"; +import path from "node:path"; + +import { buildAvailabilityProbeEnv } from "../fixtures/availability-env.ts"; +import { resultText } from "../fixtures/clients/index.ts"; +import { + type SandboxClient, + trustedSandboxShellScript, + validateSandboxName, +} from "../fixtures/clients/sandbox.ts"; +import { expect, test } from "../fixtures/e2e-test.ts"; +import { shouldRunLiveE2EScenarios } from "../fixtures/live-project-gate.ts"; +import type { ShellProbeResult } from "../fixtures/shell-probe.ts"; +import { isTransientProviderValidationFailure } from "./network-policy-transient-provider.ts"; + +const REPO_ROOT = path.resolve(import.meta.dirname, "../../.."); +const SANDBOX_NAME = process.env.NEMOCLAW_SANDBOX_NAME ?? "e2e-health-auth"; +validateSandboxName(SANDBOX_NAME); +const DASHBOARD_PORT = process.env.NEMOCLAW_DASHBOARD_PORT ?? "18789"; +const INSTALL_ATTEMPTS = process.env.CI === "true" || process.env.GITHUB_ACTIONS === "true" ? 3 : 1; +const LIVE_TIMEOUT_MS = 30 * 60_000; + +function commandEnv(apiKey?: string): NodeJS.ProcessEnv { + const env: NodeJS.ProcessEnv = { + ...buildAvailabilityProbeEnv(), + NEMOCLAW_ACCEPT_THIRD_PARTY_SOFTWARE: "1", + NEMOCLAW_DASHBOARD_PORT: DASHBOARD_PORT, + NEMOCLAW_NON_INTERACTIVE: "1", + NEMOCLAW_RECREATE_SANDBOX: "1", + NEMOCLAW_SANDBOX_NAME: SANDBOX_NAME, + OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY ?? "nemoclaw", + }; + if (apiKey) { + env.NVIDIA_INFERENCE_API_KEY = apiKey; + env.NVIDIA_API_KEY = apiKey; + } + return env; +} + +async function bestEffort(run: () => Promise): Promise { + try { + await run(); + } catch { + // Best-effort cleanup/recovery probes should not hide primary failures. + } +} + +function assertStatusNotOffline(output: string, context: string): void { + expect(output, `${context} must not report the #2342 false Health Offline state`).not.toMatch( + /offline/i, + ); +} + +async function httpCodeFromSandbox( + sandbox: SandboxClient, + urlPath: string, + artifactName: string, +): Promise { + return await sandbox.execShell( + SANDBOX_NAME, + trustedSandboxShellScript( + `curl -so /dev/null -w '%{http_code}' --max-time 3 http://localhost:${DASHBOARD_PORT}${urlPath}`, + ), + { + artifactName, + env: commandEnv(), + timeoutMs: 30_000, + }, + ); +} + +test.skipIf(!shouldRunLiveE2EScenarios())( + "device auth health probes treat 401 as live instead of offline (#2342)", + { timeout: LIVE_TIMEOUT_MS }, + async ({ artifacts, cleanup, host, sandbox, secrets, skip }) => { + const apiKey = secrets.required("NVIDIA_INFERENCE_API_KEY"); + const installLog = artifacts.pathFor("phase-1-install-device-auth-health.log"); + + await artifacts.writeJson("scenario.json", { + id: "device-auth-health", + runner: "vitest", + legacySource: "test/e2e/test-device-auth-health.sh", + boundary: "install.sh + OpenShell sandbox exec + NemoClaw status + host curl", + sandboxName: SANDBOX_NAME, + dashboardPort: DASHBOARD_PORT, + contracts: [ + "onboard succeeds with device auth enabled", + "/health is reachable from inside the sandbox", + "the authenticated dashboard root may return 401 without being treated as offline", + "nemoclaw status reports the gateway as live, not Health Offline", + "status remains non-offline after a gateway kill/recovery attempt", + ], + }); + + const dockerInfo = await host.command("docker", ["info"], { + artifactName: "phase-0-docker-info", + env: buildAvailabilityProbeEnv(), + timeoutMs: 30_000, + }); + if (dockerInfo.exitCode !== 0) { + if (process.env.GITHUB_ACTIONS === "true") { + throw new Error(`Docker is required for device auth health E2E: ${resultText(dockerInfo)}`); + } + skip(`Docker is required for device auth health E2E: ${resultText(dockerInfo)}`); + } + + cleanup.add(`destroy device-auth sandbox ${SANDBOX_NAME}`, async () => { + await bestEffort(() => + host.nemoclaw([SANDBOX_NAME, "destroy", "--yes"], { + artifactName: "cleanup-nemoclaw-destroy-device-auth-health", + env: commandEnv(), + timeoutMs: 120_000, + }), + ); + await bestEffort(() => + sandbox.openshell(["sandbox", "delete", SANDBOX_NAME], { + artifactName: "cleanup-openshell-delete-device-auth-health", + env: commandEnv(), + timeoutMs: 60_000, + }), + ); + }); + + await bestEffort(() => + host.nemoclaw([SANDBOX_NAME, "destroy", "--yes"], { + artifactName: "pre-cleanup-nemoclaw-destroy-device-auth-health", + env: commandEnv(), + timeoutMs: 120_000, + }), + ); + await bestEffort(() => + sandbox.openshell(["sandbox", "delete", SANDBOX_NAME], { + artifactName: "pre-cleanup-openshell-delete-device-auth-health", + env: commandEnv(), + timeoutMs: 60_000, + }), + ); + + let install: ShellProbeResult | undefined; + for (let attempt = 1; attempt <= INSTALL_ATTEMPTS; attempt += 1) { + install = await host.command("bash", ["install.sh", "--non-interactive"], { + artifactName: + attempt === 1 + ? "phase-1-install-device-auth-health" + : `phase-1-install-device-auth-health-attempt-${attempt}`, + cwd: REPO_ROOT, + env: commandEnv(apiKey), + redactionValues: [apiKey], + timeoutMs: 20 * 60_000, + }); + fs.writeFileSync(installLog, resultText(install)); + if (install.exitCode === 0) break; + if (isTransientProviderValidationFailure(install) && attempt < INSTALL_ATTEMPTS) { + await new Promise((resolve) => setTimeout(resolve, 10_000 * attempt)); + continue; + } + break; + } + expect(install, "install command must run").toBeDefined(); + expect(install?.exitCode, resultText(install as ShellProbeResult)).toBe(0); + + await host.expectListed(SANDBOX_NAME, { + artifactName: "phase-1-nemoclaw-list-device-auth-health", + env: commandEnv(), + timeoutMs: 60_000, + }); + + const health = await httpCodeFromSandbox(sandbox, "/health", "phase-2-sandbox-health-code"); + expect(health.exitCode, resultText(health)).toBe(0); + expect(health.stdout.trim()).toBe("200"); + + const root = await httpCodeFromSandbox(sandbox, "/", "phase-2-sandbox-root-code"); + expect(root.exitCode, resultText(root)).toBe(0); + expect(["200", "401"], `dashboard root returned ${root.stdout.trim()}`).toContain( + root.stdout.trim(), + ); + + const status = await host.nemoclaw([SANDBOX_NAME, "status"], { + artifactName: "phase-3-nemoclaw-status-device-auth-health", + env: commandEnv(), + timeoutMs: 120_000, + }); + expect(status.exitCode, resultText(status)).toBe(0); + assertStatusNotOffline(resultText(status), "initial status"); + expect(resultText(status)).toMatch(/running|online|healthy|OpenClaw|Ready/i); + + const hostHealth = await host.command( + "curl", + [ + "-so", + "/dev/null", + "-w", + "%{http_code}", + "--max-time", + "5", + `http://127.0.0.1:${DASHBOARD_PORT}/health`, + ], + { + artifactName: "phase-4-host-health-code", + env: buildAvailabilityProbeEnv(), + timeoutMs: 30_000, + }, + ); + if (hostHealth.stdout.trim() && hostHealth.stdout.trim() !== "000") { + expect( + ["200", "401"], + `host dashboard health returned ${hostHealth.stdout.trim()}`, + ).toContain(hostHealth.stdout.trim()); + } + + await sandbox.execShell( + SANDBOX_NAME, + trustedSandboxShellScript("pkill -f 'openclaw.*gateway' 2>/dev/null || true"), + { + artifactName: "phase-5-kill-gateway-process", + env: commandEnv(), + timeoutMs: 30_000, + }, + ); + await new Promise((resolve) => setTimeout(resolve, 3_000)); + + const recoveryStatus = await host.nemoclaw([SANDBOX_NAME, "status"], { + artifactName: "phase-5-nemoclaw-status-after-gateway-kill", + env: commandEnv(), + timeoutMs: 120_000, + }); + expect(recoveryStatus.exitCode, resultText(recoveryStatus)).toBe(0); + assertStatusNotOffline(resultText(recoveryStatus), "recovery status"); + + for (let attempt = 1; attempt <= 30; attempt += 1) { + const recoveredHealth = await httpCodeFromSandbox( + sandbox, + "/health", + `phase-5-recovery-health-code-attempt-${attempt}`, + ); + const code = recoveredHealth.stdout.trim(); + if (code === "200" || code === "401") { + await artifacts.writeJson("gateway-recovered.json", { attempt, code }); + return; + } + await new Promise((resolve) => setTimeout(resolve, 5_000)); + } + + await artifacts.writeJson("gateway-recovery-inconclusive.json", { + reason: "Gateway did not recover within 150s; legacy shell treated this as optional.", + }); + }, +); From b8d45e7bf3f282eb6a5bf77bd43c3f062f595f08 Mon Sep 17 00:00:00 2001 From: Carlos Villela Date: Sat, 20 Jun 2026 09:43:57 -0700 Subject: [PATCH 6/6] test(e2e): move device auth setup branches to helpers Signed-off-by: Carlos Villela --- .../live/device-auth-health-helpers.ts | 157 +++++++++++++++++ .../live/device-auth-health.test.ts | 163 +++--------------- 2 files changed, 180 insertions(+), 140 deletions(-) create mode 100644 test/e2e-scenario/live/device-auth-health-helpers.ts diff --git a/test/e2e-scenario/live/device-auth-health-helpers.ts b/test/e2e-scenario/live/device-auth-health-helpers.ts new file mode 100644 index 00000000000..bc809a6d810 --- /dev/null +++ b/test/e2e-scenario/live/device-auth-health-helpers.ts @@ -0,0 +1,157 @@ +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +import fs from "node:fs"; +import path from "node:path"; + +import { buildAvailabilityProbeEnv } from "../fixtures/availability-env.ts"; +import type { HostCliClient } from "../fixtures/clients/host.ts"; +import { resultText } from "../fixtures/clients/index.ts"; +import { + type SandboxClient, + trustedSandboxShellScript, + validateSandboxName, +} from "../fixtures/clients/sandbox.ts"; +import type { ShellProbeResult } from "../fixtures/shell-probe.ts"; +import { isTransientProviderValidationFailure } from "./network-policy-transient-provider.ts"; + +const REPO_ROOT = path.resolve(import.meta.dirname, "../../.."); +export const SANDBOX_NAME = process.env.NEMOCLAW_SANDBOX_NAME ?? "e2e-health-auth"; +validateSandboxName(SANDBOX_NAME); +export const DASHBOARD_PORT = process.env.NEMOCLAW_DASHBOARD_PORT ?? "18789"; +const INSTALL_ATTEMPTS = process.env.CI === "true" || process.env.GITHUB_ACTIONS === "true" ? 3 : 1; + +export function commandEnv(apiKey?: string): NodeJS.ProcessEnv { + const env: NodeJS.ProcessEnv = { + ...buildAvailabilityProbeEnv(), + NEMOCLAW_ACCEPT_THIRD_PARTY_SOFTWARE: "1", + NEMOCLAW_DASHBOARD_PORT: DASHBOARD_PORT, + NEMOCLAW_NON_INTERACTIVE: "1", + NEMOCLAW_RECREATE_SANDBOX: "1", + NEMOCLAW_SANDBOX_NAME: SANDBOX_NAME, + OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY ?? "nemoclaw", + }; + apiKey && Object.assign(env, { NVIDIA_INFERENCE_API_KEY: apiKey, NVIDIA_API_KEY: apiKey }); + return env; +} + +export async function bestEffort(run: () => Promise): Promise { + try { + await run(); + } catch { + // Best-effort cleanup/recovery probes should not hide primary failures. + } +} + +export function assertDockerAvailable( + result: ShellProbeResult, + skip: (note?: string) => never, +): void { + result.exitCode === 0 || process.env.GITHUB_ACTIONS === "true" + ? undefined + : skip(`Docker is required for device auth health E2E: ${resultText(result)}`); + result.exitCode === 0 || + process.env.GITHUB_ACTIONS !== "true" || + (() => { + throw new Error(`Docker is required for device auth health E2E: ${resultText(result)}`); + })(); +} + +export async function httpCodeFromSandbox( + sandbox: SandboxClient, + urlPath: string, + artifactName: string, +): Promise { + return await sandbox.execShell( + SANDBOX_NAME, + trustedSandboxShellScript( + `curl -so /dev/null -w '%{http_code}' --max-time 3 http://localhost:${DASHBOARD_PORT}${urlPath}`, + ), + { + artifactName, + env: commandEnv(), + timeoutMs: 30_000, + }, + ); +} + +export async function cleanupDeviceAuthSandbox( + host: HostCliClient, + sandbox: SandboxClient, +): Promise { + await bestEffort(() => + host.nemoclaw([SANDBOX_NAME, "destroy", "--yes"], { + artifactName: "cleanup-nemoclaw-destroy-device-auth-health", + env: commandEnv(), + timeoutMs: 120_000, + }), + ); + await bestEffort(() => + sandbox.openshell(["sandbox", "delete", SANDBOX_NAME], { + artifactName: "cleanup-openshell-delete-device-auth-health", + env: commandEnv(), + timeoutMs: 60_000, + }), + ); +} + +export async function installDeviceAuthSandbox( + host: HostCliClient, + apiKey: string, + installLog: string, +): Promise { + let install: ShellProbeResult | undefined; + for (let attempt = 1; attempt <= INSTALL_ATTEMPTS; attempt += 1) { + install = await host.command("bash", ["install.sh", "--non-interactive"], { + artifactName: + attempt === 1 + ? "phase-1-install-device-auth-health" + : `phase-1-install-device-auth-health-attempt-${attempt}`, + cwd: REPO_ROOT, + env: commandEnv(apiKey), + redactionValues: [apiKey], + timeoutMs: 20 * 60_000, + }); + fs.writeFileSync(installLog, resultText(install)); + const shouldRetry = + install.exitCode !== 0 && + isTransientProviderValidationFailure(install) && + attempt < INSTALL_ATTEMPTS; + install.exitCode === 0 && (attempt = INSTALL_ATTEMPTS + 1); + shouldRetry && (await new Promise((resolve) => setTimeout(resolve, 10_000 * attempt))); + !shouldRetry && install.exitCode !== 0 && (attempt = INSTALL_ATTEMPTS + 1); + } + if (!install) throw new Error("install command did not run"); + return install; +} + +export async function maybeWriteHostHealthExpectation( + hostHealth: ShellProbeResult, + expectCode: (codes: string[], message: string, actual: string) => void, +): Promise { + const code = hostHealth.stdout.trim(); + code && + code !== "000" && + expectCode(["200", "401"], `host dashboard health returned ${code}`, code); +} + +export async function waitForRecoveryArtifact( + artifacts: { writeJson(path: string, value: unknown): Promise }, + sandbox: SandboxClient, +): Promise { + for (let attempt = 1; attempt <= 30; attempt += 1) { + const recoveredHealth = await httpCodeFromSandbox( + sandbox, + "/health", + `phase-5-recovery-health-code-attempt-${attempt}`, + ); + const code = recoveredHealth.stdout.trim(); + const recovered = code === "200" || code === "401"; + recovered && (await artifacts.writeJson("gateway-recovered.json", { attempt, code })); + if (recovered) return; + await new Promise((resolve) => setTimeout(resolve, 5_000)); + } + await artifacts.writeJson("gateway-recovery-inconclusive.json", { + reason: "Gateway did not recover within 150s; legacy shell treated this as optional.", + }); +} diff --git a/test/e2e-scenario/live/device-auth-health.test.ts b/test/e2e-scenario/live/device-auth-health.test.ts index 676b8c687a7..c6de3431c28 100644 --- a/test/e2e-scenario/live/device-auth-health.test.ts +++ b/test/e2e-scenario/live/device-auth-health.test.ts @@ -9,77 +9,32 @@ * device-auth 401 responses must not be misreported as Health Offline. */ -import fs from "node:fs"; -import path from "node:path"; - import { buildAvailabilityProbeEnv } from "../fixtures/availability-env.ts"; import { resultText } from "../fixtures/clients/index.ts"; -import { - type SandboxClient, - trustedSandboxShellScript, - validateSandboxName, -} from "../fixtures/clients/sandbox.ts"; +import { trustedSandboxShellScript } from "../fixtures/clients/sandbox.ts"; import { expect, test } from "../fixtures/e2e-test.ts"; import { shouldRunLiveE2EScenarios } from "../fixtures/live-project-gate.ts"; -import type { ShellProbeResult } from "../fixtures/shell-probe.ts"; -import { isTransientProviderValidationFailure } from "./network-policy-transient-provider.ts"; +import { + assertDockerAvailable, + bestEffort, + cleanupDeviceAuthSandbox, + commandEnv, + DASHBOARD_PORT, + httpCodeFromSandbox, + installDeviceAuthSandbox, + maybeWriteHostHealthExpectation, + SANDBOX_NAME, + waitForRecoveryArtifact, +} from "./device-auth-health-helpers.ts"; -const REPO_ROOT = path.resolve(import.meta.dirname, "../../.."); -const SANDBOX_NAME = process.env.NEMOCLAW_SANDBOX_NAME ?? "e2e-health-auth"; -validateSandboxName(SANDBOX_NAME); -const DASHBOARD_PORT = process.env.NEMOCLAW_DASHBOARD_PORT ?? "18789"; -const INSTALL_ATTEMPTS = process.env.CI === "true" || process.env.GITHUB_ACTIONS === "true" ? 3 : 1; const LIVE_TIMEOUT_MS = 30 * 60_000; -function commandEnv(apiKey?: string): NodeJS.ProcessEnv { - const env: NodeJS.ProcessEnv = { - ...buildAvailabilityProbeEnv(), - NEMOCLAW_ACCEPT_THIRD_PARTY_SOFTWARE: "1", - NEMOCLAW_DASHBOARD_PORT: DASHBOARD_PORT, - NEMOCLAW_NON_INTERACTIVE: "1", - NEMOCLAW_RECREATE_SANDBOX: "1", - NEMOCLAW_SANDBOX_NAME: SANDBOX_NAME, - OPENSHELL_GATEWAY: process.env.OPENSHELL_GATEWAY ?? "nemoclaw", - }; - if (apiKey) { - env.NVIDIA_INFERENCE_API_KEY = apiKey; - env.NVIDIA_API_KEY = apiKey; - } - return env; -} - -async function bestEffort(run: () => Promise): Promise { - try { - await run(); - } catch { - // Best-effort cleanup/recovery probes should not hide primary failures. - } -} - function assertStatusNotOffline(output: string, context: string): void { expect(output, `${context} must not report the #2342 false Health Offline state`).not.toMatch( /offline/i, ); } -async function httpCodeFromSandbox( - sandbox: SandboxClient, - urlPath: string, - artifactName: string, -): Promise { - return await sandbox.execShell( - SANDBOX_NAME, - trustedSandboxShellScript( - `curl -so /dev/null -w '%{http_code}' --max-time 3 http://localhost:${DASHBOARD_PORT}${urlPath}`, - ), - { - artifactName, - env: commandEnv(), - timeoutMs: 30_000, - }, - ); -} - test.skipIf(!shouldRunLiveE2EScenarios())( "device auth health probes treat 401 as live instead of offline (#2342)", { timeout: LIVE_TIMEOUT_MS }, @@ -108,67 +63,15 @@ test.skipIf(!shouldRunLiveE2EScenarios())( env: buildAvailabilityProbeEnv(), timeoutMs: 30_000, }); - if (dockerInfo.exitCode !== 0) { - if (process.env.GITHUB_ACTIONS === "true") { - throw new Error(`Docker is required for device auth health E2E: ${resultText(dockerInfo)}`); - } - skip(`Docker is required for device auth health E2E: ${resultText(dockerInfo)}`); - } - - cleanup.add(`destroy device-auth sandbox ${SANDBOX_NAME}`, async () => { - await bestEffort(() => - host.nemoclaw([SANDBOX_NAME, "destroy", "--yes"], { - artifactName: "cleanup-nemoclaw-destroy-device-auth-health", - env: commandEnv(), - timeoutMs: 120_000, - }), - ); - await bestEffort(() => - sandbox.openshell(["sandbox", "delete", SANDBOX_NAME], { - artifactName: "cleanup-openshell-delete-device-auth-health", - env: commandEnv(), - timeoutMs: 60_000, - }), - ); - }); + assertDockerAvailable(dockerInfo, skip); - await bestEffort(() => - host.nemoclaw([SANDBOX_NAME, "destroy", "--yes"], { - artifactName: "pre-cleanup-nemoclaw-destroy-device-auth-health", - env: commandEnv(), - timeoutMs: 120_000, - }), - ); - await bestEffort(() => - sandbox.openshell(["sandbox", "delete", SANDBOX_NAME], { - artifactName: "pre-cleanup-openshell-delete-device-auth-health", - env: commandEnv(), - timeoutMs: 60_000, - }), + cleanup.add(`destroy device-auth sandbox ${SANDBOX_NAME}`, () => + cleanupDeviceAuthSandbox(host, sandbox), ); + await bestEffort(() => cleanupDeviceAuthSandbox(host, sandbox)); - let install: ShellProbeResult | undefined; - for (let attempt = 1; attempt <= INSTALL_ATTEMPTS; attempt += 1) { - install = await host.command("bash", ["install.sh", "--non-interactive"], { - artifactName: - attempt === 1 - ? "phase-1-install-device-auth-health" - : `phase-1-install-device-auth-health-attempt-${attempt}`, - cwd: REPO_ROOT, - env: commandEnv(apiKey), - redactionValues: [apiKey], - timeoutMs: 20 * 60_000, - }); - fs.writeFileSync(installLog, resultText(install)); - if (install.exitCode === 0) break; - if (isTransientProviderValidationFailure(install) && attempt < INSTALL_ATTEMPTS) { - await new Promise((resolve) => setTimeout(resolve, 10_000 * attempt)); - continue; - } - break; - } - expect(install, "install command must run").toBeDefined(); - expect(install?.exitCode, resultText(install as ShellProbeResult)).toBe(0); + const install = await installDeviceAuthSandbox(host, apiKey, installLog); + expect(install.exitCode, resultText(install)).toBe(0); await host.expectListed(SANDBOX_NAME, { artifactName: "phase-1-nemoclaw-list-device-auth-health", @@ -212,12 +115,9 @@ test.skipIf(!shouldRunLiveE2EScenarios())( timeoutMs: 30_000, }, ); - if (hostHealth.stdout.trim() && hostHealth.stdout.trim() !== "000") { - expect( - ["200", "401"], - `host dashboard health returned ${hostHealth.stdout.trim()}`, - ).toContain(hostHealth.stdout.trim()); - } + await maybeWriteHostHealthExpectation(hostHealth, (codes, message, actual) => + expect(codes, message).toContain(actual), + ); await sandbox.execShell( SANDBOX_NAME, @@ -237,23 +137,6 @@ test.skipIf(!shouldRunLiveE2EScenarios())( }); expect(recoveryStatus.exitCode, resultText(recoveryStatus)).toBe(0); assertStatusNotOffline(resultText(recoveryStatus), "recovery status"); - - for (let attempt = 1; attempt <= 30; attempt += 1) { - const recoveredHealth = await httpCodeFromSandbox( - sandbox, - "/health", - `phase-5-recovery-health-code-attempt-${attempt}`, - ); - const code = recoveredHealth.stdout.trim(); - if (code === "200" || code === "401") { - await artifacts.writeJson("gateway-recovered.json", { attempt, code }); - return; - } - await new Promise((resolve) => setTimeout(resolve, 5_000)); - } - - await artifacts.writeJson("gateway-recovery-inconclusive.json", { - reason: "Gateway did not recover within 150s; legacy shell treated this as optional.", - }); + await waitForRecoveryArtifact(artifacts, sandbox); }, );