Skip to content
Merged
104 changes: 104 additions & 0 deletions .github/workflows/e2e-vitest-scenarios.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3457,6 +3457,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,') }}
Expand Down Expand Up @@ -3729,6 +3832,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' }}
Expand Down
157 changes: 157 additions & 0 deletions test/e2e-scenario/live/device-auth-health-helpers.ts
Original file line number Diff line number Diff line change
@@ -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<unknown>): Promise<void> {
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<ShellProbeResult> {
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<void> {
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<ShellProbeResult> {
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<void> {
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<string> },
sandbox: SandboxClient,
): Promise<void> {
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.",
});
}
Loading