From 92e88a033be72f2411604b5a3a9998ce48c66846 Mon Sep 17 00:00:00 2001 From: Julie Yaunches Date: Tue, 23 Jun 2026 20:28:22 -0400 Subject: [PATCH 1/4] test(e2e): hermeticize onboard resume --- .github/workflows/nightly-e2e.yaml | 32 +++++-------- test/e2e-script-workflow.test.ts | 32 +++++++++++-- test/e2e/test-onboard-resume.sh | 72 +++++++++++++++++++++++------- 3 files changed, 95 insertions(+), 41 deletions(-) diff --git a/.github/workflows/nightly-e2e.yaml b/.github/workflows/nightly-e2e.yaml index db76a3cf1bf..e8c1b6beba6 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-super-v3 - NEMOCLAW_COMPAT_MODEL: nvidia/nvidia/nemotron-3-super-v3 - 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-super-v3 - NEMOCLAW_COMPAT_MODEL: nvidia/nvidia/nemotron-3-super-v3 - 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 1da46728c7b..b685bf4a4a3 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,34 @@ 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(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(); + + const script = readFileSync(new URL("./e2e/test-onboard-resume.sh", import.meta.url), "utf8"); + expect(script).toContain("lib/openai-compatible-api-proof.sh"); + expect(script).toContain("start_fake_openai_compatible_api"); + expect(script).toContain('NEMOCLAW_ENDPOINT_URL="$FAKE_OPENAI_BASE_URL"'); + expect(script).not.toContain("lib/ci-compatible-inference.sh"); + }); + it("keeps converted jobs dispatchable through the reusable workflow", () => { const cloudJob = nightlyWorkflow.jobs["cloud-e2e"]; diff --git a/test/e2e/test-onboard-resume.sh b/test/e2e/test-onboard-resume.sh index f93a7c7e1ae..9116c34742a 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,28 @@ 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/openai-compatible-api-proof.sh +. "$(dirname "${BASH_SOURCE[0]}")/lib/openai-compatible-api-proof.sh" register_sandbox_for_teardown "$SANDBOX_NAME" +cleanup_on_exit() { + stop_fake_openai_compatible_api + _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:-}" +RESTORE_API_KEY="${COMPATIBLE_API_KEY:-${NVIDIA_INFERENCE_API_KEY:-e2e-compatible-key}}" +EXPECTED_PROVIDER="compatible-endpoint" +FAKE_OPENAI_LOG="${FAKE_OPENAI_LOG:-$(mktemp)}" +FAKE_OPENAI_PORT="${FAKE_OPENAI_PORT:-0}" +FAKE_OPENAI_HOST="${FAKE_OPENAI_HOST:-0.0.0.0}" +FAKE_OPENAI_READY_HOST="${FAKE_OPENAI_READY_HOST:-127.0.0.1}" +FAKE_OPENAI_MODEL="${FAKE_OPENAI_MODEL:-test-model}" +FAKE_OPENAI_API_KEY="$RESTORE_API_KEY" +FAKE_OPENAI_REQUIRE_AUTH="${FAKE_OPENAI_REQUIRE_AUTH:-1}" +export FAKE_OPENAI_LOG FAKE_OPENAI_PORT FAKE_OPENAI_HOST FAKE_OPENAI_READY_HOST FAKE_OPENAI_MODEL FAKE_OPENAI_API_KEY FAKE_OPENAI_REQUIRE_AUTH # ══════════════════════════════════════════════════════════════════ # Phase 0: Pre-cleanup @@ -123,25 +138,48 @@ else exit 1 fi -if [[ -z "$RESTORE_API_KEY" ]]; then - fail "NVIDIA_INFERENCE_API_KEY not set or invalid — required for resume completion" +pass "Compatible endpoint credential is staged for the first onboard run" + +host_ip_for_sandbox() { + local ip_addr + 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 + ip_addr="$(hostname -I 2>/dev/null | awk '{print $1}')" + if [ -n "$ip_addr" ]; then + echo "$ip_addr" + return + fi + echo "127.0.0.1" +} + +FAKE_OPENAI_PUBLIC_HOST="${FAKE_OPENAI_PUBLIC_HOST:-$(host_ip_for_sandbox)}" +if start_fake_openai_compatible_api; then + pass "Fake OpenAI-compatible endpoint started at ${FAKE_OPENAI_BASE_URL}" +else + fail "Fake OpenAI-compatible endpoint failed to start" + sed 's/^/ /' "$FAKE_OPENAI_LOG" 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)" +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=openai-completions +export COMPATIBLE_API_KEY="$RESTORE_API_KEY" +unset NEMOCLAW_E2E_USE_HOSTED_INFERENCE + +pass "Configured onboard resume test for hermetic compatible-endpoint inference" # ══════════════════════════════════════════════════════════════════ # Phase 2: First onboard (forced failure after sandbox creation) From fe81c5e8e868864bf75b06e45e45d78113c8ddd9 Mon Sep 17 00:00:00 2001 From: Julie Yaunches Date: Wed, 24 Jun 2026 12:34:37 -0400 Subject: [PATCH 2/4] test(e2e): assert resume fake inference Signed-off-by: Julie Yaunches --- test/e2e-script-workflow.test.ts | 6 +++++ test/e2e/test-onboard-resume.sh | 40 +++++++++++++++++++++++++++++++- 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/test/e2e-script-workflow.test.ts b/test/e2e-script-workflow.test.ts index b685bf4a4a3..b793cd1df88 100644 --- a/test/e2e-script-workflow.test.ts +++ b/test/e2e-script-workflow.test.ts @@ -1034,15 +1034,21 @@ describe("E2E reusable workflow contract", () => { 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"); expect(script).toContain("lib/openai-compatible-api-proof.sh"); expect(script).toContain("start_fake_openai_compatible_api"); expect(script).toContain('NEMOCLAW_ENDPOINT_URL="$FAKE_OPENAI_BASE_URL"'); + expect(script).toContain("assert_fake_openai_authenticated_inference"); expect(script).not.toContain("lib/ci-compatible-inference.sh"); }); diff --git a/test/e2e/test-onboard-resume.sh b/test/e2e/test-onboard-resume.sh index 9116c34742a..89910b9b2a7 100755 --- a/test/e2e/test-onboard-resume.sh +++ b/test/e2e/test-onboard-resume.sh @@ -92,13 +92,15 @@ REGISTRY="$HOME/.nemoclaw/sandboxes.json" RESTORE_API_KEY="${COMPATIBLE_API_KEY:-${NVIDIA_INFERENCE_API_KEY:-e2e-compatible-key}}" EXPECTED_PROVIDER="compatible-endpoint" FAKE_OPENAI_LOG="${FAKE_OPENAI_LOG:-$(mktemp)}" +FAKE_OPENAI_REQUESTS_FILE="${FAKE_OPENAI_REQUESTS_FILE:-$(mktemp)}" FAKE_OPENAI_PORT="${FAKE_OPENAI_PORT:-0}" FAKE_OPENAI_HOST="${FAKE_OPENAI_HOST:-0.0.0.0}" FAKE_OPENAI_READY_HOST="${FAKE_OPENAI_READY_HOST:-127.0.0.1}" FAKE_OPENAI_MODEL="${FAKE_OPENAI_MODEL:-test-model}" FAKE_OPENAI_API_KEY="$RESTORE_API_KEY" FAKE_OPENAI_REQUIRE_AUTH="${FAKE_OPENAI_REQUIRE_AUTH:-1}" -export FAKE_OPENAI_LOG FAKE_OPENAI_PORT FAKE_OPENAI_HOST FAKE_OPENAI_READY_HOST FAKE_OPENAI_MODEL FAKE_OPENAI_API_KEY FAKE_OPENAI_REQUIRE_AUTH +NEMOCLAW_FAKE_OPENAI_REQUESTS_FILE="$FAKE_OPENAI_REQUESTS_FILE" +export FAKE_OPENAI_LOG FAKE_OPENAI_REQUESTS_FILE FAKE_OPENAI_PORT FAKE_OPENAI_HOST FAKE_OPENAI_READY_HOST FAKE_OPENAI_MODEL FAKE_OPENAI_API_KEY FAKE_OPENAI_REQUIRE_AUTH NEMOCLAW_FAKE_OPENAI_REQUESTS_FILE # ══════════════════════════════════════════════════════════════════ # Phase 0: Pre-cleanup @@ -181,6 +183,35 @@ unset NEMOCLAW_E2E_USE_HOSTED_INFERENCE pass "Configured onboard resume test for hermetic compatible-endpoint inference" +assert_fake_openai_authenticated_inference() { + node - "$FAKE_OPENAI_REQUESTS_FILE" <<'NODE' +const fs = require("fs"); +const requestsFile = process.argv[2]; +if (!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", "/v1/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 +} + # ══════════════════════════════════════════════════════════════════ # Phase 2: First onboard (forced failure after sandbox creation) # ══════════════════════════════════════════════════════════════════ @@ -248,6 +279,13 @@ case $? in *) fail "Session file did not record the expected interrupted state" ;; esac +if assert_fake_openai_authenticated_inference; 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 # ══════════════════════════════════════════════════════════════════ From 396d731ab187d732b26be4ddc022717631b0133a Mon Sep 17 00:00:00 2001 From: Julie Yaunches Date: Wed, 24 Jun 2026 13:03:07 -0400 Subject: [PATCH 3/4] test(e2e): add hermetic inference helper --- test/e2e-script-workflow.test.ts | 16 ++- test/e2e/README.md | 16 +++ test/e2e/lib/hermetic-compatible-inference.sh | 97 +++++++++++++++++++ test/e2e/test-onboard-resume.sh | 82 ++-------------- 4 files changed, 132 insertions(+), 79 deletions(-) create mode 100755 test/e2e/lib/hermetic-compatible-inference.sh diff --git a/test/e2e-script-workflow.test.ts b/test/e2e-script-workflow.test.ts index b793cd1df88..75f14638a9e 100644 --- a/test/e2e-script-workflow.test.ts +++ b/test/e2e-script-workflow.test.ts @@ -1045,11 +1045,19 @@ describe("E2E reusable workflow contract", () => { expect(runStep?.env?.NEMOCLAW_PREFERRED_API).toBeUndefined(); const script = readFileSync(new URL("./e2e/test-onboard-resume.sh", import.meta.url), "utf8"); - expect(script).toContain("lib/openai-compatible-api-proof.sh"); - expect(script).toContain("start_fake_openai_compatible_api"); - expect(script).toContain('NEMOCLAW_ENDPOINT_URL="$FAKE_OPENAI_BASE_URL"'); - expect(script).toContain("assert_fake_openai_authenticated_inference"); + 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"'); }); it("keeps converted jobs dispatchable through the reusable workflow", () => { 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..08407eaea62 --- /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="${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 89910b9b2a7..b61b381f8fc 100755 --- a/test/e2e/test-onboard-resume.sh +++ b/test/e2e/test-onboard-resume.sh @@ -77,30 +77,19 @@ fi # shellcheck source=test/e2e/lib/sandbox-teardown.sh . "$(dirname "${BASH_SOURCE[0]}")/lib/sandbox-teardown.sh" -# shellcheck source=test/e2e/lib/openai-compatible-api-proof.sh -. "$(dirname "${BASH_SOURCE[0]}")/lib/openai-compatible-api-proof.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() { - stop_fake_openai_compatible_api + 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="${COMPATIBLE_API_KEY:-${NVIDIA_INFERENCE_API_KEY:-e2e-compatible-key}}" EXPECTED_PROVIDER="compatible-endpoint" -FAKE_OPENAI_LOG="${FAKE_OPENAI_LOG:-$(mktemp)}" -FAKE_OPENAI_REQUESTS_FILE="${FAKE_OPENAI_REQUESTS_FILE:-$(mktemp)}" -FAKE_OPENAI_PORT="${FAKE_OPENAI_PORT:-0}" -FAKE_OPENAI_HOST="${FAKE_OPENAI_HOST:-0.0.0.0}" -FAKE_OPENAI_READY_HOST="${FAKE_OPENAI_READY_HOST:-127.0.0.1}" -FAKE_OPENAI_MODEL="${FAKE_OPENAI_MODEL:-test-model}" -FAKE_OPENAI_API_KEY="$RESTORE_API_KEY" -FAKE_OPENAI_REQUIRE_AUTH="${FAKE_OPENAI_REQUIRE_AUTH:-1}" -NEMOCLAW_FAKE_OPENAI_REQUESTS_FILE="$FAKE_OPENAI_REQUESTS_FILE" -export FAKE_OPENAI_LOG FAKE_OPENAI_REQUESTS_FILE FAKE_OPENAI_PORT FAKE_OPENAI_HOST FAKE_OPENAI_READY_HOST FAKE_OPENAI_MODEL FAKE_OPENAI_API_KEY FAKE_OPENAI_REQUIRE_AUTH NEMOCLAW_FAKE_OPENAI_REQUESTS_FILE # ══════════════════════════════════════════════════════════════════ # Phase 0: Pre-cleanup @@ -140,29 +129,11 @@ else exit 1 fi -pass "Compatible endpoint credential is staged for the first onboard run" - -host_ip_for_sandbox() { - local ip_addr - 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 - ip_addr="$(hostname -I 2>/dev/null | awk '{print $1}')" - if [ -n "$ip_addr" ]; then - echo "$ip_addr" - return - fi - echo "127.0.0.1" -} - -FAKE_OPENAI_PUBLIC_HOST="${FAKE_OPENAI_PUBLIC_HOST:-$(host_ip_for_sandbox)}" -if start_fake_openai_compatible_api; then - pass "Fake OpenAI-compatible endpoint started at ${FAKE_OPENAI_BASE_URL}" +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" 2>/dev/null || true + sed 's/^/ /' "${FAKE_OPENAI_LOG:-/dev/null}" 2>/dev/null || true exit 1 fi @@ -173,45 +144,6 @@ else exit 1 fi -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=openai-completions -export COMPATIBLE_API_KEY="$RESTORE_API_KEY" -unset NEMOCLAW_E2E_USE_HOSTED_INFERENCE - -pass "Configured onboard resume test for hermetic compatible-endpoint inference" - -assert_fake_openai_authenticated_inference() { - node - "$FAKE_OPENAI_REQUESTS_FILE" <<'NODE' -const fs = require("fs"); -const requestsFile = process.argv[2]; -if (!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", "/v1/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 -} - # ══════════════════════════════════════════════════════════════════ # Phase 2: First onboard (forced failure after sandbox creation) # ══════════════════════════════════════════════════════════════════ @@ -279,7 +211,7 @@ case $? in *) fail "Session file did not record the expected interrupted state" ;; esac -if assert_fake_openai_authenticated_inference; then +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" From 8cf22fda2de5aa554cf9f0d0273febf2e5d00ef9 Mon Sep 17 00:00:00 2001 From: Julie Yaunches Date: Wed, 24 Jun 2026 14:46:53 -0400 Subject: [PATCH 4/4] fix(e2e): force hermetic fake auth Signed-off-by: Julie Yaunches --- test/e2e-script-workflow.test.ts | 2 ++ test/e2e/lib/hermetic-compatible-inference.sh | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/test/e2e-script-workflow.test.ts b/test/e2e-script-workflow.test.ts index a3c28fc4f63..519e338b19d 100644 --- a/test/e2e-script-workflow.test.ts +++ b/test/e2e-script-workflow.test.ts @@ -1058,6 +1058,8 @@ describe("E2E reusable workflow contract", () => { 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", () => { diff --git a/test/e2e/lib/hermetic-compatible-inference.sh b/test/e2e/lib/hermetic-compatible-inference.sh index 08407eaea62..c3f5d7137ef 100755 --- a/test/e2e/lib/hermetic-compatible-inference.sh +++ b/test/e2e/lib/hermetic-compatible-inference.sh @@ -47,7 +47,7 @@ nemoclaw_e2e_start_hermetic_compatible_inference() { 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="${FAKE_OPENAI_REQUIRE_AUTH:-1}" + export FAKE_OPENAI_REQUIRE_AUTH=1 export NEMOCLAW_FAKE_OPENAI_REQUESTS_FILE="$FAKE_OPENAI_REQUESTS_FILE" if ! start_fake_openai_compatible_api; then