diff --git a/.github/workflows/nightly-e2e.yaml b/.github/workflows/nightly-e2e.yaml index b47644dff88..4c4052f2569 100644 --- a/.github/workflows/nightly-e2e.yaml +++ b/.github/workflows/nightly-e2e.yaml @@ -1880,29 +1880,19 @@ jobs: - *target-ref-checkout - *dockerhub-auth-step - - name: Install NemoClaw - env: - NVIDIA_INFERENCE_API_KEY: ${{ (github.event_name != 'workflow_dispatch' || inputs.target_ref == '') && secrets.NVIDIA_INFERENCE_API_KEY || '' }} - NEMOCLAW_E2E_USE_HOSTED_INFERENCE: "1" - NEMOCLAW_PROVIDER: custom - NEMOCLAW_ENDPOINT_URL: https://inference-api.nvidia.com/v1 - NEMOCLAW_MODEL: nvidia/nvidia/nemotron-3-ultra - NEMOCLAW_COMPAT_MODEL: nvidia/nvidia/nemotron-3-ultra - NEMOCLAW_PREFERRED_API: openai-completions - COMPATIBLE_API_KEY: ${{ (github.event_name != 'workflow_dispatch' || inputs.target_ref == '') && secrets.NVIDIA_INFERENCE_API_KEY || '' }} - NEMOCLAW_NON_INTERACTIVE: "1" - NEMOCLAW_ACCEPT_THIRD_PARTY_SOFTWARE: "1" - run: bash install.sh --non-interactive --yes-i-accept-third-party-software + - 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: env -u DOCKER_CONFIG -u DOCKERHUB_USERNAME -u DOCKERHUB_TOKEN -u NVIDIA_INFERENCE_API_KEY -u GITHUB_TOKEN bash scripts/install-openshell.sh - name: Run onboard resume E2E test env: - NVIDIA_INFERENCE_API_KEY: ${{ (github.event_name != 'workflow_dispatch' || inputs.target_ref == '') && secrets.NVIDIA_INFERENCE_API_KEY || '' }} - NEMOCLAW_E2E_USE_HOSTED_INFERENCE: "1" - NEMOCLAW_PROVIDER: custom - NEMOCLAW_ENDPOINT_URL: https://inference-api.nvidia.com/v1 - NEMOCLAW_MODEL: nvidia/nvidia/nemotron-3-ultra - NEMOCLAW_COMPAT_MODEL: nvidia/nvidia/nemotron-3-ultra - NEMOCLAW_PREFERRED_API: openai-completions - COMPATIBLE_API_KEY: ${{ (github.event_name != 'workflow_dispatch' || inputs.target_ref == '') && secrets.NVIDIA_INFERENCE_API_KEY || '' }} NEMOCLAW_NON_INTERACTIVE: "1" NEMOCLAW_ACCEPT_THIRD_PARTY_SOFTWARE: "1" run: | diff --git a/test/e2e-script-workflow.test.ts b/test/e2e-script-workflow.test.ts index f966b53f988..519e338b19d 100644 --- a/test/e2e-script-workflow.test.ts +++ b/test/e2e-script-workflow.test.ts @@ -981,8 +981,6 @@ describe("E2E reusable workflow contract", () => { "credential-migration-e2e:Run credential migration Vitest test", "onboard-repair-e2e:Install NemoClaw", "onboard-repair-e2e:Run onboard repair E2E test", - "onboard-resume-e2e:Install NemoClaw", - "onboard-resume-e2e:Run onboard resume E2E test", "onboard-negative-paths-e2e:Install NemoClaw", "onboard-negative-paths-e2e:Run onboard negative-path E2E test", "runtime-overrides-e2e:Install NemoClaw", @@ -993,7 +991,7 @@ describe("E2E reusable workflow contract", () => { ]), ); - expect(directSecretSteps.length).toBeGreaterThanOrEqual(17); + expect(directSecretSteps.length).toBeGreaterThanOrEqual(15); for (const { jobName, step } of directSecretSteps) { const stepKey = `${jobName}:${step.name ?? ""}`; expect(step.env?.NVIDIA_INFERENCE_API_KEY, stepKey).toBe(GUARDED_HOSTED_INFERENCE_SECRET); @@ -1020,6 +1018,50 @@ describe("E2E reusable workflow contract", () => { expect(script).toContain("nemoclaw_e2e_configure_compatible_inference"); }); + it("keeps onboard-resume hermetic and off hosted inference secrets", () => { + const job = nightlyWorkflow.jobs["onboard-resume-e2e"]; + const setupNodeStep = job.steps?.find((step) => + String(step.uses ?? "").startsWith("actions/setup-node@"), + ); + const installDepsStep = job.steps?.find((step) => step.name === "Install root dependencies"); + const buildStep = job.steps?.find((step) => step.name === "Build CLI"); + const installOpenShellStep = job.steps?.find((step) => step.name === "Install OpenShell CLI"); + const runStep = job.steps?.find((step) => step.name === "Run onboard resume E2E test"); + + expect(setupNodeStep?.uses).toMatch(/^actions\/setup-node@[0-9a-f]{40}$/); + expect(setupNodeStep?.with?.cache).toBe("npm"); + expect(installDepsStep?.run).toBe("npm ci --ignore-scripts"); + expect(buildStep?.run).toBe("npm run build:cli"); + expect(installOpenShellStep?.run).toContain("scripts/install-openshell.sh"); + expect(installOpenShellStep?.run).toContain("-u NVIDIA_INFERENCE_API_KEY"); + expect(installOpenShellStep?.run).toContain("-u GITHUB_TOKEN"); + expect(runStep?.env?.NVIDIA_INFERENCE_API_KEY).toBeUndefined(); + expect(runStep?.env?.COMPATIBLE_API_KEY).toBeUndefined(); + expect(runStep?.env?.NEMOCLAW_ENDPOINT_URL).toBeUndefined(); + expect(runStep?.env?.NEMOCLAW_PROVIDER).toBeUndefined(); + expect(runStep?.env?.NEMOCLAW_E2E_USE_HOSTED_INFERENCE).toBeUndefined(); + expect(runStep?.env?.NEMOCLAW_MODEL).toBeUndefined(); + expect(runStep?.env?.NEMOCLAW_COMPAT_MODEL).toBeUndefined(); + expect(runStep?.env?.NEMOCLAW_PREFERRED_API).toBeUndefined(); + + const script = readFileSync(new URL("./e2e/test-onboard-resume.sh", import.meta.url), "utf8"); + const helper = readFileSync( + new URL("./e2e/lib/hermetic-compatible-inference.sh", import.meta.url), + "utf8", + ); + expect(script).toContain("lib/hermetic-compatible-inference.sh"); + expect(script).toContain("nemoclaw_e2e_start_hermetic_compatible_inference"); + expect(script).toContain("nemoclaw_e2e_assert_hermetic_compatible_inference_used"); + expect(script).not.toContain("lib/ci-compatible-inference.sh"); + expect(helper).toContain("openai-compatible-api-proof.sh"); + expect(helper).toContain("NEMOCLAW_PROVIDER=custom"); + expect(helper).toContain('NEMOCLAW_ENDPOINT_URL="$FAKE_OPENAI_BASE_URL"'); + expect(helper).toContain("unset NVIDIA_INFERENCE_API_KEY NEMOCLAW_E2E_USE_HOSTED_INFERENCE"); + expect(helper).toContain('COMPATIBLE_API_KEY="$fake_key"'); + expect(helper).toContain("FAKE_OPENAI_REQUIRE_AUTH=1"); + expect(helper).not.toContain('FAKE_OPENAI_REQUIRE_AUTH="${FAKE_OPENAI_REQUIRE_AUTH:-1}"'); + }); + it("keeps converted jobs dispatchable through the reusable workflow", () => { const cloudJob = nightlyWorkflow.jobs["cloud-e2e"]; diff --git a/test/e2e/README.md b/test/e2e/README.md index c514941a5be..5024619a289 100644 --- a/test/e2e/README.md +++ b/test/e2e/README.md @@ -3,6 +3,22 @@ # NemoClaw E2E CI +## Hermetic Compatible Inference for Direct Bash Jobs + +Direct bash E2E jobs that need onboarding inference, but do not need the live NVIDIA hosted service, should use `test/e2e/lib/hermetic-compatible-inference.sh` instead of `test/e2e/lib/ci-compatible-inference.sh` or workflow-injected hosted inference secrets. + +This pattern supports issue #5747 conversions: + +1. Source `lib/hermetic-compatible-inference.sh` from the test script. +2. Call `nemoclaw_e2e_start_hermetic_compatible_inference` during prerequisites. +3. Run the onboarding behavior under test normally; the helper exports a fake `custom` OpenAI-compatible endpoint and fake `COMPATIBLE_API_KEY`. +4. Assert the endpoint was actually used with `nemoclaw_e2e_assert_hermetic_compatible_inference_used`. +5. Stop it from the test cleanup trap with `nemoclaw_e2e_stop_hermetic_compatible_inference`. +6. In `.github/workflows/nightly-e2e.yaml`, install/build only the CLI and OpenShell needed by the script; do not inject `NVIDIA_INFERENCE_API_KEY`, `COMPATIBLE_API_KEY`, `NEMOCLAW_E2E_USE_HOSTED_INFERENCE`, or hosted model/env knobs into the converted job. +7. Add/update workflow contract coverage in `test/e2e-script-workflow.test.ts` so the job cannot regress back to hosted inference secrets. + +Use the lower-level `openai-compatible-api-proof.sh` directly only when a test needs raw fake-server lifecycle control without NemoClaw onboarding environment exports. + ## Nightly Onboard Trace Timing The GitHub Actions workflow `.github/workflows/nightly-e2e.yaml` enables NemoClaw tracing for the `cloud-onboard-e2e` lane. diff --git a/test/e2e/lib/hermetic-compatible-inference.sh b/test/e2e/lib/hermetic-compatible-inference.sh new file mode 100755 index 00000000000..c3f5d7137ef --- /dev/null +++ b/test/e2e/lib/hermetic-compatible-inference.sh @@ -0,0 +1,97 @@ +#!/usr/bin/env bash +# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +# Shared pattern for direct bash E2E jobs that need NemoClaw inference during +# onboarding but must not consume hosted NVIDIA inference secrets. This wraps the +# raw fake OpenAI-compatible server lifecycle with NemoClaw-specific environment +# exports that point onboarding at a sandbox-reachable local compatible endpoint. + +# shellcheck source=test/e2e/lib/openai-compatible-api-proof.sh +. "$(dirname "${BASH_SOURCE[0]}")/openai-compatible-api-proof.sh" + +nemoclaw_e2e_host_ip_for_sandbox() { + local ip_addr + if command -v ip >/dev/null 2>&1; then + ip_addr="$(ip route get 1.1.1.1 2>/dev/null | awk '{for (i=1;i<=NF;i++) if ($i=="src") {print $(i+1); exit}}')" + if [ -n "$ip_addr" ]; then + echo "$ip_addr" + return + fi + fi + + if command -v hostname >/dev/null 2>&1; then + for ip_addr in $(hostname -I 2>/dev/null); do + case "$ip_addr" in + 127.* | ::1) ;; + *) + echo "$ip_addr" + return + ;; + esac + done + fi + + echo "127.0.0.1" +} + +nemoclaw_e2e_start_hermetic_compatible_inference() { + local fake_key + fake_key="${NEMOCLAW_E2E_COMPATIBLE_API_KEY:-e2e-compatible-key}" + + export FAKE_OPENAI_LOG="${FAKE_OPENAI_LOG:-$(mktemp)}" + export FAKE_OPENAI_REQUESTS_FILE="${FAKE_OPENAI_REQUESTS_FILE:-$(mktemp)}" + export FAKE_OPENAI_PORT="${FAKE_OPENAI_PORT:-0}" + export FAKE_OPENAI_HOST="${FAKE_OPENAI_HOST:-0.0.0.0}" + export FAKE_OPENAI_READY_HOST="${FAKE_OPENAI_READY_HOST:-127.0.0.1}" + export FAKE_OPENAI_PUBLIC_HOST="${FAKE_OPENAI_PUBLIC_HOST:-$(nemoclaw_e2e_host_ip_for_sandbox)}" + export FAKE_OPENAI_MODEL="${FAKE_OPENAI_MODEL:-${NEMOCLAW_E2E_COMPATIBLE_MODEL:-test-model}}" + export FAKE_OPENAI_API_KEY="$fake_key" + export FAKE_OPENAI_REQUIRE_AUTH=1 + export NEMOCLAW_FAKE_OPENAI_REQUESTS_FILE="$FAKE_OPENAI_REQUESTS_FILE" + + if ! start_fake_openai_compatible_api; then + return 1 + fi + + unset NVIDIA_INFERENCE_API_KEY NEMOCLAW_E2E_USE_HOSTED_INFERENCE + export NEMOCLAW_PROVIDER=custom + export NEMOCLAW_ENDPOINT_URL="$FAKE_OPENAI_BASE_URL" + export NEMOCLAW_MODEL="$FAKE_OPENAI_MODEL" + export NEMOCLAW_COMPAT_MODEL="$FAKE_OPENAI_MODEL" + export NEMOCLAW_PREFERRED_API="${NEMOCLAW_E2E_PREFERRED_API:-openai-completions}" + export COMPATIBLE_API_KEY="$fake_key" +} + +nemoclaw_e2e_stop_hermetic_compatible_inference() { + stop_fake_openai_compatible_api +} + +nemoclaw_e2e_assert_hermetic_compatible_inference_used() { + node - "${FAKE_OPENAI_REQUESTS_FILE:-}" <<'NODE' +const fs = require("fs"); +const requestsFile = process.argv[2]; +if (!requestsFile || !fs.existsSync(requestsFile)) { + throw new Error(`request log missing: ${requestsFile || ""}`); +} +const entries = fs.readFileSync(requestsFile, "utf8") + .split(/\n+/) + .filter(Boolean) + .map((line) => JSON.parse(line)); +const inferencePosts = entries.filter((entry) => + entry.method === "POST" && + ["/v1/chat/completions", "/chat/completions", "/v1/responses", "/responses"].includes(entry.path), +); +if (inferencePosts.length === 0) { + throw new Error(`expected at least one fake inference POST, got ${JSON.stringify(entries)}`); +} +const missingAuth = entries.filter((entry) => entry.auth === "missing"); +if (missingAuth.length > 0) { + throw new Error(`fake endpoint saw missing auth: ${JSON.stringify(missingAuth)}`); +} +const unauthenticated = inferencePosts.filter((entry) => entry.auth !== "ok"); +if (unauthenticated.length > 0) { + throw new Error(`fake inference POST had missing auth: ${JSON.stringify(unauthenticated)}`); +} +NODE +} diff --git a/test/e2e/test-onboard-resume.sh b/test/e2e/test-onboard-resume.sh index f93a7c7e1ae..b61b381f8fc 100755 --- a/test/e2e/test-onboard-resume.sh +++ b/test/e2e/test-onboard-resume.sh @@ -15,10 +15,10 @@ # - Docker running # - openshell CLI installed # - Node.js available -# - NVIDIA_INFERENCE_API_KEY set before starting the test +# - local fake OpenAI-compatible endpoint reachable from host and sandbox # # Usage: -# NVIDIA_INFERENCE_API_KEY=... bash test/e2e/test-onboard-resume.sh +# bash test/e2e/test-onboard-resume.sh set -uo pipefail @@ -77,13 +77,19 @@ fi # shellcheck source=test/e2e/lib/sandbox-teardown.sh . "$(dirname "${BASH_SOURCE[0]}")/lib/sandbox-teardown.sh" -# shellcheck source=test/e2e/lib/ci-compatible-inference.sh -. "$(dirname "${BASH_SOURCE[0]}")/lib/ci-compatible-inference.sh" +# shellcheck source=test/e2e/lib/hermetic-compatible-inference.sh +. "$(dirname "${BASH_SOURCE[0]}")/lib/hermetic-compatible-inference.sh" register_sandbox_for_teardown "$SANDBOX_NAME" +cleanup_on_exit() { + nemoclaw_e2e_stop_hermetic_compatible_inference + _nemoclaw_sandbox_teardown +} +trap cleanup_on_exit EXIT + SESSION_FILE="$HOME/.nemoclaw/onboard-session.json" REGISTRY="$HOME/.nemoclaw/sandboxes.json" -RESTORE_API_KEY="${NVIDIA_INFERENCE_API_KEY:-}" +EXPECTED_PROVIDER="compatible-endpoint" # ══════════════════════════════════════════════════════════════════ # Phase 0: Pre-cleanup @@ -123,26 +129,21 @@ else exit 1 fi -if [[ -z "$RESTORE_API_KEY" ]]; then - fail "NVIDIA_INFERENCE_API_KEY not set or invalid — required for resume completion" +if nemoclaw_e2e_start_hermetic_compatible_inference; then + pass "Configured onboard resume test for hermetic compatible-endpoint inference at ${FAKE_OPENAI_BASE_URL}" +else + fail "Fake OpenAI-compatible endpoint failed to start" + sed 's/^/ /' "${FAKE_OPENAI_LOG:-/dev/null}" 2>/dev/null || true exit 1 fi -pass "NVIDIA_INFERENCE_API_KEY is set" - -export NVIDIA_INFERENCE_API_KEY="$RESTORE_API_KEY" -nemoclaw_e2e_configure_compatible_inference || exit 1 -HOSTED_INFERENCE_BASE_URL="$(nemoclaw_e2e_hosted_inference_base_url)" -EXPECTED_PROVIDER="$(nemoclaw_e2e_expected_route_provider)" -if nemoclaw_e2e_probe_hosted_inference; then - pass "Network access to ${HOSTED_INFERENCE_BASE_URL}" +if curl -sf "${FAKE_OPENAI_BASE_URL}/models" >/dev/null 2>&1; then + pass "Network access to fake OpenAI-compatible endpoint" else - fail "Cannot reach ${HOSTED_INFERENCE_BASE_URL}" + fail "Cannot reach fake OpenAI-compatible endpoint at ${FAKE_OPENAI_BASE_URL}" exit 1 fi -pass "Exported NVIDIA_INFERENCE_API_KEY for the resume run (host writes nothing to disk; OpenShell gateway is the system of record)" - # ══════════════════════════════════════════════════════════════════ # Phase 2: First onboard (forced failure after sandbox creation) # ══════════════════════════════════════════════════════════════════ @@ -210,6 +211,13 @@ case $? in *) fail "Session file did not record the expected interrupted state" ;; esac +if nemoclaw_e2e_assert_hermetic_compatible_inference_used; then + pass "Fake OpenAI-compatible endpoint handled authenticated inference" +else + fail "Fake OpenAI-compatible endpoint did not record authenticated inference" + sed 's/^/ /' "$FAKE_OPENAI_REQUESTS_FILE" 2>/dev/null || true +fi + # ══════════════════════════════════════════════════════════════════ # Phase 3: Resume and complete # ══════════════════════════════════════════════════════════════════