diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml index b593b7af8d2..afa77fbc3f7 100644 --- a/.github/workflows/e2e.yaml +++ b/.github/workflows/e2e.yaml @@ -3519,7 +3519,7 @@ jobs: secrets: DOCKERHUB_USERNAME: ${{ github.ref == 'refs/heads/main' && github.workflow_ref == 'NVIDIA/NemoClaw/.github/workflows/e2e.yaml@refs/heads/main' && github.repository == 'NVIDIA/NemoClaw' && (github.event_name == 'workflow_dispatch' || (github.event_name == 'push' && github.ref == 'refs/heads/main')) && (inputs.checkout_sha == '' || needs.generate-matrix.outputs.e2e_credentials_allowed == 'true') && secrets.DOCKERHUB_USERNAME || '' }} DOCKERHUB_TOKEN: ${{ github.ref == 'refs/heads/main' && github.workflow_ref == 'NVIDIA/NemoClaw/.github/workflows/e2e.yaml@refs/heads/main' && github.repository == 'NVIDIA/NemoClaw' && (github.event_name == 'workflow_dispatch' || (github.event_name == 'push' && github.ref == 'refs/heads/main')) && (inputs.checkout_sha == '' || needs.generate-matrix.outputs.e2e_credentials_allowed == 'true') && secrets.DOCKERHUB_TOKEN || '' }} - HOSTED_INFERENCE_API_KEY: ${{ github.ref == 'refs/heads/main' && github.workflow_ref == 'NVIDIA/NemoClaw/.github/workflows/e2e.yaml@refs/heads/main' && github.repository == 'NVIDIA/NemoClaw' && (github.event_name == 'workflow_dispatch' || (github.event_name == 'push' && github.ref == 'refs/heads/main')) && (inputs.checkout_sha == '' || needs.generate-matrix.outputs.e2e_credentials_allowed == 'true') && (matrix.id == 'hosted-inference-openai' && secrets.OPENAI_API_KEY || matrix.id == 'hosted-inference-anthropic' && secrets.ANTHROPIC_API_KEY || matrix.id == 'hosted-inference-gemini' && secrets.GEMINI_API_KEY || matrix.id == 'hosted-inference-openrouter' && secrets.OPENROUTER_API_KEY || matrix.id == 'hosted-inference-hermes' && secrets.NOUS_API_KEY) || '' }} + HOSTED_INFERENCE_API_KEY: ${{ github.ref == 'refs/heads/main' && github.workflow_ref == 'NVIDIA/NemoClaw/.github/workflows/e2e.yaml@refs/heads/main' && github.repository == 'NVIDIA/NemoClaw' && (github.event_name == 'workflow_dispatch' || (github.event_name == 'push' && github.ref == 'refs/heads/main')) && (inputs.checkout_sha == '' || needs.generate-matrix.outputs.e2e_credentials_allowed == 'true') && matrix.id == 'hosted-inference-openrouter' && secrets.OPENROUTER_API_KEY || '' }} catalogue-standard: name: ${{ matrix.display_name }} (${{ matrix.runtime_provider }}) diff --git a/src/lib/inference/health.test.ts b/src/lib/inference/health.test.ts index e98689d2c72..2c17471c446 100644 --- a/src/lib/inference/health.test.ts +++ b/src/lib/inference/health.test.ts @@ -149,16 +149,24 @@ describe("inference health", () => { it("invokes the Gemini OpenAI-compatible chat-completions shim, not the native v1/models surface", () => { let capturedArgv: string[] = []; + let authConfigContent = ""; + const credentialNames: string[] = []; const result = probeRemoteProviderHealth("gemini-api", { model: "gemini-2.5-flash", - getCredentialImpl: (envName) => (envName === "GEMINI_API_KEY" ? "gm-test-secret" : null), + getCredentialImpl: (envName) => { + credentialNames.push(envName); + return envName === "GEMINI_API_KEY" ? "gm-test-secret" : null; + }, runCurlProbeImpl: (argv) => { capturedArgv = argv; + authConfigContent = fs.readFileSync(curlArgValue(argv, "--config")!, "utf8"); return httpOk(); }, }); expect(result?.ok).toBe(true); + expect(result?.probed).toBe(true); + expect(credentialNames).toEqual(["GEMINI_API_KEY"]); expect(result?.endpoint).toBe( "https://generativelanguage.googleapis.com/v1beta/openai/chat/completions", ); @@ -166,9 +174,11 @@ describe("inference health", () => { "https://generativelanguage.googleapis.com/v1beta/openai/chat/completions", ); expect(capturedArgv.join(" ")).not.toContain("gm-test-secret"); + expect(authConfigContent).toContain("Authorization: Bearer gm-test-secret"); const payload = JSON.parse(capturedArgv[capturedArgv.indexOf("-d") + 1]); - expect(payload).toMatchObject({ + expect(payload).toEqual({ model: "gemini-2.5-flash", + messages: [{ role: "user", content: "Reply with exactly: OK" }], max_tokens: 256, }); }); diff --git a/test/e2e/README.md b/test/e2e/README.md index 9a07a75dd1c..e150ec51833 100644 --- a/test/e2e/README.md +++ b/test/e2e/README.md @@ -2385,32 +2385,27 @@ The explicit `dgx-station-express` target runs the local Station Express install ## Fixed hosted provider qualification -`live/inference-routing-provider-smoke.test.ts` owns credential-backed native inference smoke tests. -Select `openai`, `anthropic`, `gemini`, `openrouter`, or `hermes` with -`NEMOCLAW_INFERENCE_ROUTING_PROVIDER_SMOKE`. Selecting `openrouter` runs both -OpenRouter agent cases; `all` runs all six cases. -Use an approved disposable environment and credentials from its approved source. +`live/inference-routing-provider-smoke.test.ts` owns the credential-backed OpenRouter smoke. +Select `openrouter` with `NEMOCLAW_INFERENCE_ROUTING_PROVIDER_SMOKE` to run both +OpenRouter agent cases. +Use an approved disposable environment and OpenRouter credential from its approved source. These tests are outside the credential-free `inference-routing` PR lane. -A skipped provider is missing qualification evidence. +A skipped OpenRouter case is missing qualification evidence. TC-INF-05 uses the same probe for NVIDIA credential isolation. Its separate environment, process, filesystem, and canary checks are replaced by the probe results; support tests cover leak detection and control cleanup. -OpenAI, Anthropic, Gemini, and OpenRouter onboard OpenClaw and start a fresh agent process. -Hermes Provider onboards Hermes and submits a fresh request to its managed API. +OpenRouter onboards OpenClaw and starts a fresh agent process. The `hosted-inference-openrouter` target also onboards Deep Agents Code with the same OpenRouter key and model. Its six-assertion case checks onboarding, credential isolation, the native TOML route, and one fresh `dcode -n --json` response. -The five OpenClaw and Hermes cases check the native endpoint, credential placeholder, +The OpenClaw case checks the native endpoint, credential placeholder, selected adapter, response model, and nonempty answer. The OpenRouter case switches the running sandbox to a second model and back. -It requires a fresh agent response with that model after each switch and checks that the return route is readable. -Each `nemoclaw inference set` switch also verifies its selected model with a sandbox-side inference request. +After each successful switch, it requires a fresh OpenClaw response whose reported model matches the selection. An unavailable or rate-limited intermediate model fails the first switch. -The alternate route read and return-route model assertion were removed from this live case: -agent responses prove the effective model after each restart, while the recorded-model behavior -belongs to the `inference get` source tests. Both switch exit checks and the return route read remain. -After onboarding, each hosted-provider case runs one sandbox probe before its first native agent request. +The case does not read either route. The `inference get` source tests cover recorded-model behavior. +After onboarding, the OpenRouter case runs one sandbox probe before its first native agent request. The OpenRouter model-switch requests and follow-up agent responses do not repeat that scan. The probe checks the raw environment and a bounded file sample for a salted fingerprint of the selected credential. The probe tries `ps aux`, then `ps -ef`, to check process arguments. @@ -2426,30 +2421,33 @@ rejection and credential binding. Deterministic tests own protocol/header construction, ownership collisions, sandbox isolation, restart, and failed-operation recovery. -Each selected case requires its matching approved model variable, listed below. The smoke does not select a default model. -The Hermes smoke uses `NOUS_API_KEY`. It does not prove interactive OAuth login or token refresh. +The smoke requires the approved `NEMOCLAW_OPENROUTER_MODEL`; it does not select a default model. Credentials remain in the test host environment and OpenShell provider store; artifacts redact them. The cleanup helper destroys each test sandbox. The Deep Agents Code case checks sandbox absence even if onboarding fails. -Other hosted cases check absence after successful onboarding; failed onboarding uses best-effort cleanup. +The OpenClaw case checks absence after successful onboarding; failed onboarding uses best-effort cleanup. Neither path proves removal of credentials from the OpenShell provider store. Discard the approved disposable gateway after each run, including failed onboarding. Use a fresh gateway for a retry. -Select one explicit target with `targets=hosted-inference-openai`, `hosted-inference-anthropic`, -`hosted-inference-gemini`, `hosted-inference-openrouter`, or `hosted-inference-hermes`. -These Docker targets reuse `inference-routing-provider-smoke.test.ts` and the trusted E2E controller. -These targets require explicit selection. Default suites and changed-file selection do not include them, -even when a workflow or provider source changes. The initial consumer is Slice 2 (#12589); its native -provider behavior must exist in the candidate before running these assertions. Advisor can recommend -an explicit hosted target. Selection does not grant dispatch or credential access. +Select `targets=hosted-inference-openrouter` explicitly. +This Docker target reuses `inference-routing-provider-smoke.test.ts` and the trusted E2E controller. +It requires explicit selection. Default suites and changed-file selection do not include it, +even when a workflow or provider source changes. Advisor can recommend the OpenRouter target. +Selection does not grant dispatch or credential access. The credential-free `inference-routing` target remains separate. -Before dispatch, obtain an approved disposable environment and credential source for the selected provider. +OpenAI, Anthropic, Gemini, and Hermes Provider use deterministic source contracts for fixed +endpoint and method selection, request headers and body, native agent configuration, +provider-bound credentials, and rejection of crossed routes. OpenAI, Anthropic, and Gemini +also have response-parsing contracts. Hermes malformed HTTP 2xx body parsing is deferred +to #13290. Their four former credentialed selectors are unavailable. These contracts do not +demonstrate live upstream authentication, model availability, or a fresh remote answer. +That evidence is deferred for issues #12589 and #12955; neither issue waits on those E2Es. + +Before dispatch, obtain an approved disposable environment and OpenRouter credential source. Credential-bearing hosted runs require the canonical `e2e.yaml` workflow from `main`. Branch-dispatched workflows receive no hosted-provider or registry credentials, even for an approved candidate. -The controller passes only that target's repository secret (`OPENAI_API_KEY`, `ANTHROPIC_API_KEY`, -`GEMINI_API_KEY`, `OPENROUTER_API_KEY`, or `NOUS_API_KEY`) to the test step. -Set the corresponding repository variable `NEMOCLAW_OPENAI_MODEL`, `NEMOCLAW_ANTHROPIC_MODEL`, -`NEMOCLAW_GEMINI_MODEL`, `NEMOCLAW_OPENROUTER_MODEL`, or `NEMOCLAW_HERMES_MODEL` to an approved model. +The controller passes only `OPENROUTER_API_KEY` to the test step. +Set `NEMOCLAW_OPENROUTER_MODEL` to an approved model. Missing credentials or models fail before onboarding. A selected test that skips cannot produce passing evidence. The existing controller binds artifacts to the tested source revision and trusted workflow revision. For an authorized hosted-provider candidate run, the trusted reporter comments on the PR after the selected jobs finish. @@ -2463,9 +2461,4 @@ Candidate-controlled host processes can read or copy the selected provider key w The sandbox isolation check does not attest isolation from those host processes. Job cleanup and artifact redaction do not revoke the key or erase a copy made by candidate code. Rotate or revoke the key in its issuing provider to remove later access. -Hermes API-key evidence does not qualify interactive OAuth login. - -Hermes OAuth remains a separate live qualification for Slice 2 (#12589). An authorized account operator -must complete device authorization in an approved disposable interactive environment, verify a fresh -request through the returned native endpoint, restart, and verify another fresh request. Record the -tested commit and redacted results. This prerequisite adds no OAuth selector or automation. +Hermes interactive OAuth evidence is also deferred for Slice 2 (#12589). diff --git a/test/e2e/live/inference-routing-helpers.ts b/test/e2e/live/inference-routing-helpers.ts index 59b42308b89..b38be9987c2 100644 --- a/test/e2e/live/inference-routing-helpers.ts +++ b/test/e2e/live/inference-routing-helpers.ts @@ -43,15 +43,12 @@ const CREDENTIAL_CLASSIFICATION_PATTERN = const TRANSPORT_CLASSIFICATION_PATTERN = /unreachable|timeout|connect|ECONNREFUSED|ETIMEDOUT|ENETUNREACH|EHOSTUNREACH|ENOTFOUND|EAI_AGAIN|No route to host|transport|network|endpoint|dns/i; -function shouldRunProviderSmoke( - provider: "openai" | "anthropic" | "gemini" | "openrouter" | "hermes", -): boolean { +function shouldRunProviderSmoke(provider: "openrouter"): boolean { // The former shell script auto-ran these smokes when provider secrets were - // present. This live migration requires an explicit opt-in so PR-safe jobs - // cannot spend third-party quota accidentally; any future secret-backed lane - // must set NEMOCLAW_INFERENCE_ROUTING_PROVIDER_SMOKE=all or a provider name. + // present. This live smoke requires explicit selection so PR-safe jobs do + // not spend third-party quota accidentally. const requested = process.env.NEMOCLAW_INFERENCE_ROUTING_PROVIDER_SMOKE?.trim().toLowerCase(); - return requested === "1" || requested === "true" || requested === "all" || requested === provider; + return requested === provider; } type SkipFn = (note?: string) => void; @@ -440,15 +437,12 @@ async function expectAnthropicMessageThroughSandbox( ); } -export function requireProviderSmokeSelected( - provider: "openai" | "anthropic" | "gemini" | "openrouter" | "hermes", - skip: SkipFn, -): void { +export function requireProviderSmokeSelected(provider: "openrouter", skip: SkipFn): void { if (!shouldRunProviderSmoke(provider)) { const label = provider; skipLive( skip, - `set NEMOCLAW_INFERENCE_ROUTING_PROVIDER_SMOKE=${provider} or all to run ${label} smoke`, + `set NEMOCLAW_INFERENCE_ROUTING_PROVIDER_SMOKE=${provider} to run ${label} smoke`, ); } } diff --git a/test/e2e/live/inference-routing-provider-smoke.test.ts b/test/e2e/live/inference-routing-provider-smoke.test.ts index dc41b605bb1..cac7a29ad69 100644 --- a/test/e2e/live/inference-routing-provider-smoke.test.ts +++ b/test/e2e/live/inference-routing-provider-smoke.test.ts @@ -2,15 +2,12 @@ // SPDX-License-Identifier: Apache-2.0 import crypto from "node:crypto"; -import { describe } from "vitest"; import { CLI_ENTRYPOINT } from "../fixtures/paths.ts"; import { hostedCredentialScanCommand } from "./inference-routing-credential-scan.ts"; import { parse as parseToml } from "smol-toml"; -import YAML from "yaml"; -import { hermesApiCommand } from "../fixtures/hermes-api-command.ts"; import { - HOSTED_PROVIDER_SMOKE_CASES as hostedCases, - hostedProviderSmokeEnvironment, + OPENROUTER_SMOKE, + openRouterSmokeEnvironment, } from "../../../tools/e2e/hosted-provider-smoke.mts"; import { parseOpenClawAgentText } from "../fixtures/openclaw-agent-output.ts"; import { isObjectRecord } from "../../../src/lib/core/json-types.ts"; @@ -39,9 +36,7 @@ import { verifyCredentialPlaceholder, } from "./inference-routing-helpers.ts"; -// These credential-backed smokes are intentionally outside the PR-required -// inference-routing lane. Explicit hosted-inference catalogue targets supply -// only the selected credential through the trusted E2E controller. +// The OpenRouter smoke is explicitly selected through the trusted E2E controller. test( "TC-INF-05 real NVIDIA key is isolated from sandbox env, process list, and filesystem", @@ -152,7 +147,7 @@ test( async ({ artifacts, cleanup, host, progress, runtimeProvider, sandbox, secrets, skip }) => { progress.phase("confirm hosted OpenRouter prerequisites"); requireProviderSmokeSelected("openrouter", skip); - const environment = hostedProviderSmokeEnvironment("hosted-inference-openrouter", { + const environment = openRouterSmokeEnvironment({ OPENROUTER_API_KEY: secrets.optional("OPENROUTER_API_KEY"), NEMOCLAW_OPENROUTER_MODEL: process.env.NEMOCLAW_OPENROUTER_MODEL, }); @@ -241,113 +236,93 @@ test( }, ); -// Four cases use OpenClaw; the Nous API-key case uses Hermes. - -describe.each(hostedCases.map((entry) => [entry.id, entry.label, entry] as const))( - "%s %s", - (_id, _label, selected) => { - test( - "answers through its native provider", +test( + "TC-INF-07 OpenRouter answers through its native provider", + { + timeout: 35 * 60_000, + meta: { + e2ePhases: [ + "confirm hosted provider prerequisites", + "recreate the hosted sandbox", + "onboard the hosted provider", + "exercise the selected hosted lifecycle", + "verify native agent configuration", + "verify hosted credential isolation", + "switch OpenRouter models when selected", + "request a fresh agent response", + ], + }, + }, + async ({ artifacts, cleanup, host, progress, runtimeProvider, sandbox, secrets, skip }) => { + const selected = OPENROUTER_SMOKE; + requireProviderSmokeSelected(selected.selector, skip); + const environment = openRouterSmokeEnvironment({ + [selected.credential]: secrets.optional(selected.credential), + [selected.modelEnv]: process.env[selected.modelEnv], + }); + const apiKey = environment[selected.credential]!; + const model = environment[selected.modelEnv]!; + await requireLivePrerequisites(host, runtimeProvider); + const sandboxName = inferenceSandboxName(`e2e-${selected.selector}`); + cleanup.add(`best-effort hosted inference cleanup for ${sandboxName}`, () => + cleanupSandbox(host, sandbox, sandboxName), + ); + progress.phase("recreate the hosted sandbox"); + await cleanupSandbox(host, sandbox, sandboxName); + await artifacts.target.declare({ + id: `inference-routing-${selected.selector}`, + model, + contract: [ + "hosted provider onboards", + "OpenRouter remains usable after rebuild without a fresh host credential", + "agent uses the native endpoint with a credential placeholder", + "selected credential is absent from sandbox environment, process arguments, and sampled files", + "fresh agent request answers with the selected model", + "both OpenRouter model switches preserve a fresh agent response", + ], + }); + progress.phase("onboard the hosted provider"); + const onboard = await onboardSandbox( + artifacts, + sandboxName, { - timeout: (selected.selector === "openrouter" ? 35 : 20) * 60_000, - meta: { - e2ePhases: [ - "confirm hosted provider prerequisites", - "recreate the hosted sandbox", - "onboard the hosted provider", - "exercise the selected hosted lifecycle", - "verify native agent configuration", - "verify hosted credential isolation", - "switch OpenRouter models when selected", - "request a fresh agent response", - ], + NEMOCLAW_AGENT: "openclaw", + NEMOCLAW_MODEL: model, + NEMOCLAW_PROVIDER: selected.provider, + [selected.credential]: apiKey, + }, + [apiKey], + `${selected.id}-onboard`, + progress, + ); + expectOnboardSuccess(onboard, `${selected.id} hosted onboard`); + cleanup.add(`strict hosted inference cleanup for ${sandboxName}`, () => + cleanupSandbox(host, sandbox, sandboxName, { strict: true }), + ); + progress.phase("exercise the selected hosted lifecycle"); + // Reuse routing and isolation checks after rebuild without a fresh host key. + const rebuilt = await host.command( + process.execPath, + [CLI_ENTRYPOINT, sandboxName, "rebuild", "--yes", "--verbose"], + { + artifactName: "tc-inf-07-rebuild", + env: { + ...buildAvailabilityProbeEnv(), + NEMOCLAW_ACCEPT_THIRD_PARTY_SOFTWARE: "1", + NEMOCLAW_NON_INTERACTIVE: "1", }, + redactionValues: [apiKey], + timeoutMs: 10 * 60_000, }, - async ({ artifacts, cleanup, host, progress, runtimeProvider, sandbox, secrets, skip }) => { - requireProviderSmokeSelected(selected.selector, skip); - const environment = hostedProviderSmokeEnvironment( - `hosted-inference-${selected.selector}`, - { - [selected.credential]: secrets.optional(selected.credential), - [selected.modelEnv]: process.env[selected.modelEnv], - }, - ); - const apiKey = environment[selected.credential]!; - const model = environment[selected.modelEnv]!; - await requireLivePrerequisites(host, runtimeProvider); - const hermes = selected.selector === "hermes"; - const sandboxName = inferenceSandboxName(`e2e-${selected.selector}`); - cleanup.add(`best-effort hosted inference cleanup for ${sandboxName}`, () => - cleanupSandbox(host, sandbox, sandboxName), - ); - progress.phase("recreate the hosted sandbox"); - await cleanupSandbox(host, sandbox, sandboxName); - await artifacts.target.declare({ - id: `inference-routing-${selected.selector}`, - model, - contract: [ - "hosted provider onboards", - ...(selected.selector === "openrouter" - ? ["OpenRouter remains usable after rebuild without a fresh host credential"] - : []), - "agent uses the native endpoint with a credential placeholder", - "selected credential is absent from sandbox environment, process arguments, and sampled files", - "fresh agent request answers with the selected model", - ...(selected.selector === "openrouter" - ? ["both OpenRouter model switches preserve a fresh agent response"] - : []), - ], - }); - progress.phase("onboard the hosted provider"); - const onboard = await onboardSandbox( - artifacts, - sandboxName, - { - NEMOCLAW_AGENT: hermes ? "hermes" : "openclaw", - NEMOCLAW_MODEL: model, - NEMOCLAW_PROVIDER: selected.provider, - [selected.credential]: apiKey, - }, - [apiKey], - `${selected.id}-onboard`, - progress, - ); - expectOnboardSuccess(onboard, `${selected.id} hosted onboard`); - cleanup.add(`strict hosted inference cleanup for ${sandboxName}`, () => - cleanupSandbox(host, sandbox, sandboxName, { strict: true }), - ); - progress.phase("exercise the selected hosted lifecycle"); - // Reuse routing and isolation checks after rebuild without a fresh host key. - const rebuilt = - selected.selector === "openrouter" - ? await host.command( - process.execPath, - [CLI_ENTRYPOINT, sandboxName, "rebuild", "--yes", "--verbose"], - { - artifactName: "tc-inf-07-rebuild", - env: { - ...buildAvailabilityProbeEnv(), - NEMOCLAW_ACCEPT_THIRD_PARTY_SOFTWARE: "1", - NEMOCLAW_NON_INTERACTIVE: "1", - }, - redactionValues: [apiKey], - timeoutMs: 10 * 60_000, - }, - ) - : null; - expect( - rebuilt === null ? 0 : rebuilt.exitCode, - rebuilt === null ? "fresh hosted provider lifecycle" : resultText(rebuilt), - ).toBe(0); - progress.phase("verify native agent configuration"); - const config = await sandbox.exec( - sandboxName, - hermes - ? ["cat", "/sandbox/.hermes/config.yaml"] - : [ - "node", - "-e", - String.raw` + ); + expect(rebuilt.exitCode, resultText(rebuilt)).toBe(0); + progress.phase("verify native agent configuration"); + const config = await sandbox.exec( + sandboxName, + [ + "node", + "-e", + String.raw` const fs = require("node:fs"); let config; try { @@ -368,204 +343,156 @@ console.log(JSON.stringify({ "openshell:resolve:env:" + process.argv[2], })); `, - selected.providerKey, - selected.placeholder, - selected.endpoint, - ], - { - artifactName: `${selected.id}-native-config`, - env: buildAvailabilityProbeEnv(), - redactionValues: [apiKey], - timeoutMs: 60_000, - }, - ); - expect(config.exitCode, "native provider config read failed; inspect the artifact").toBe(0); - const providerConfig = hermes ? YAML.parse(config.stdout).model : JSON.parse(config.stdout); - expect(providerConfig).toMatchObject({ - [hermes ? "base_url" : "endpointMatches"]: hermes ? selected.endpoint : true, - [hermes ? "api_key" : "credentialHandleMatches"]: hermes - ? `\${${selected.placeholder}}` - : true, - }); - progress.phase("verify hosted credential isolation"); - const isolation = await sandbox.exec(sandboxName, hostedCredentialScanCommand(apiKey), { - artifactName: `${selected.id}-credential-isolation`, - env: buildAvailabilityProbeEnv(), - redactionValues: [apiKey], - timeoutMs: 90_000, - }); - expect(isolation.exitCode, "credential isolation scan failed; inspect the artifact").toBe( - 0, - ); - const isolationEvidence = JSON.parse(isolation.stdout); - expect( - isolationEvidence.environmentClean, - "real credential absent from sandbox environment", - ).toBe(true); - expect( - isolationEvidence.processesClean, - "sandbox process arguments are available and credential-free", - ).toBe(true); - expect( - isolationEvidence.sampledFilesClean, - "real credential absent from sampled sandbox files", - ).toBe(true); - expect( - isolationEvidence.canaryDetected, - "filesystem scanner detects a planted control", - ).toBe(true); - const requestOpenClawAgent = async (artifactName: string) => { - const response = await sandbox.exec( - sandboxName, - [ - "nemoclaw-start", - "openclaw", - "agent", - "--agent", - "main", - "--json", - "--thinking", - "off", - "--session-id", - `native-${crypto.randomUUID()}`, - "-m", - "Reply with one short greeting. Do not use tools.", - ], - { - artifactName, - env: buildAvailabilityProbeEnv(), - redactionValues: [apiKey], - timeoutMs: 180_000, - }, - ); - const document = parseOpenClawJsonDocuments(response.stdout) - .map(openClawAgentResponseRecord) - .filter((value) => value !== null) - .at(-1); - return { response, document, text: parseOpenClawAgentText(response.stdout) }; - }; - switch (selected.selector) { - case "openrouter": { - const alternateModel = - model === "nvidia/nemotron-3-super-120b-a12b" - ? "nvidia/nemotron-3-ultra-550b-a55b" - : "nvidia/nemotron-3-super-120b-a12b"; - const switchEnv = buildChildEnv( - { ...process.env, OPENROUTER_API_KEY: apiKey }, - { - additionalAllowedEnv: AVAILABILITY_PROBE_EXTRA_ENV_KEYS, - secretEnv: ["OPENROUTER_API_KEY"], - fixtureOverlay: {}, - }, - ); - progress.phase("switch OpenRouter models when selected"); - const toAlternate = await host.nemoclaw( - [ - "inference", - "set", - "--provider", - "openrouter-api", - "--model", - alternateModel, - "--sandbox", - sandboxName, - ], - { - artifactName: `${selected.id}-switch-to-alternate`, - env: switchEnv, - redactionValues: [apiKey], - timeoutMs: 180_000, - }, - ); - expect( - toAlternate.exitCode, - "OpenRouter alternate switch failed; inspect the redacted artifact", - ).toBe(0); - const { - response: alternateResponse, - document: alternateDocument, - text: alternateText, - } = await requestOpenClawAgent(`${selected.id}-alternate-native-agent`); - expect(alternateResponse.exitCode, resultText(alternateResponse)).toBe(0); - const alternateMeta = alternateDocument?.meta; - const alternateAgentMeta = isObjectRecord(alternateMeta) - ? alternateMeta.agentMeta - : undefined; - expect(isObjectRecord(alternateAgentMeta) ? alternateAgentMeta.model : undefined).toBe( - alternateModel, - ); - expect(alternateText.trim()).not.toBe(""); - - const backToSelected = await host.nemoclaw( - [ - "inference", - "set", - "--provider", - "openrouter-api", - "--model", - model, - "--sandbox", - sandboxName, - ], - { - artifactName: `${selected.id}-switch-back`, - env: switchEnv, - redactionValues: [apiKey], - timeoutMs: 180_000, - }, - ); - expect( - backToSelected.exitCode, - "OpenRouter return switch failed; inspect the redacted artifact", - ).toBe(0); - break; - } - default: - break; - } - progress.phase("request a fresh agent response"); - const responseOptions = { - artifactName: `${selected.id}-native-agent`, + selected.providerKey, + selected.placeholder, + selected.endpoint, + ], + { + artifactName: `${selected.id}-native-config`, + env: buildAvailabilityProbeEnv(), + redactionValues: [apiKey], + timeoutMs: 60_000, + }, + ); + expect(config.exitCode, "native provider config read failed; inspect the artifact").toBe(0); + const providerConfig = JSON.parse(config.stdout); + expect(providerConfig).toMatchObject({ + endpointMatches: true, + credentialHandleMatches: true, + }); + progress.phase("verify hosted credential isolation"); + const isolation = await sandbox.exec(sandboxName, hostedCredentialScanCommand(apiKey), { + artifactName: `${selected.id}-credential-isolation`, + env: buildAvailabilityProbeEnv(), + redactionValues: [apiKey], + timeoutMs: 90_000, + }); + expect(isolation.exitCode, "credential isolation scan failed; inspect the artifact").toBe(0); + const isolationEvidence = JSON.parse(isolation.stdout); + expect( + isolationEvidence.environmentClean, + "real credential absent from sandbox environment", + ).toBe(true); + expect( + isolationEvidence.processesClean, + "sandbox process arguments are available and credential-free", + ).toBe(true); + expect( + isolationEvidence.sampledFilesClean, + "real credential absent from sampled sandbox files", + ).toBe(true); + expect(isolationEvidence.canaryDetected, "filesystem scanner detects a planted control").toBe( + true, + ); + const requestOpenClawAgent = async (artifactName: string) => { + const response = await sandbox.exec( + sandboxName, + [ + "nemoclaw-start", + "openclaw", + "agent", + "--agent", + "main", + "--json", + "--thinking", + "off", + "--session-id", + `native-${crypto.randomUUID()}`, + "-m", + "Reply with one short greeting. Do not use tools.", + ], + { + artifactName, env: buildAvailabilityProbeEnv(), redactionValues: [apiKey], timeoutMs: 180_000, - }; - const openClawResult = hermes - ? null - : await requestOpenClawAgent(`${selected.id}-native-agent`); - const response = hermes - ? await sandbox.execShell( - sandboxName, - trustedSandboxShellScript( - hermesApiCommand( - JSON.stringify({ - model, - messages: [ - { role: "user", content: "Reply with one short greeting. Do not use tools." }, - ], - stream: false, - }), - ), - ), - responseOptions, - ) - : openClawResult!.response; - expect(response.exitCode, resultText(response)).toBe(0); - const document = hermes ? JSON.parse(response.stdout) : openClawResult!.document; - // Hermes reports the response model through its API; its selected adapter is - // recorded in config. OpenClaw reports both in the agent response metadata. - const agentSelection = hermes - ? { provider: providerConfig.provider, model: document.model } - : document?.meta?.agentMeta; - expect(agentSelection).toMatchObject({ - provider: hermes ? "custom" : selected.providerKey, - model, - }); - const text = hermes - ? (document.choices?.[0]?.message?.content ?? "") - : openClawResult!.text; - expect(text.trim()).not.toBe(""); + }, + ); + const document = parseOpenClawJsonDocuments(response.stdout) + .map(openClawAgentResponseRecord) + .filter((value) => value !== null) + .at(-1); + return { response, document, text: parseOpenClawAgentText(response.stdout) }; + }; + const alternateModel = + model === "nvidia/nemotron-3-super-120b-a12b" + ? "nvidia/nemotron-3-ultra-550b-a55b" + : "nvidia/nemotron-3-super-120b-a12b"; + const switchEnv = buildChildEnv( + { ...process.env, OPENROUTER_API_KEY: apiKey }, + { + additionalAllowedEnv: AVAILABILITY_PROBE_EXTRA_ENV_KEYS, + secretEnv: ["OPENROUTER_API_KEY"], + fixtureOverlay: {}, }, ); + progress.phase("switch OpenRouter models when selected"); + const toAlternate = await host.nemoclaw( + [ + "inference", + "set", + "--provider", + "openrouter-api", + "--model", + alternateModel, + "--sandbox", + sandboxName, + ], + { + artifactName: `${selected.id}-switch-to-alternate`, + env: switchEnv, + redactionValues: [apiKey], + timeoutMs: 180_000, + }, + ); + expect( + toAlternate.exitCode, + "OpenRouter alternate switch failed; inspect the redacted artifact", + ).toBe(0); + const { + response: alternateResponse, + document: alternateDocument, + text: alternateText, + } = await requestOpenClawAgent(`${selected.id}-alternate-native-agent`); + expect(alternateResponse.exitCode, resultText(alternateResponse)).toBe(0); + const alternateMeta = alternateDocument?.meta; + const alternateAgentMeta = isObjectRecord(alternateMeta) ? alternateMeta.agentMeta : undefined; + expect(isObjectRecord(alternateAgentMeta) ? alternateAgentMeta.model : undefined).toBe( + alternateModel, + ); + expect(alternateText.trim()).not.toBe(""); + + const backToSelected = await host.nemoclaw( + [ + "inference", + "set", + "--provider", + "openrouter-api", + "--model", + model, + "--sandbox", + sandboxName, + ], + { + artifactName: `${selected.id}-switch-back`, + env: switchEnv, + redactionValues: [apiKey], + timeoutMs: 180_000, + }, + ); + expect( + backToSelected.exitCode, + "OpenRouter return switch failed; inspect the redacted artifact", + ).toBe(0); + progress.phase("request a fresh agent response"); + const { response, document, text } = await requestOpenClawAgent(`${selected.id}-native-agent`); + expect(response.exitCode, resultText(response)).toBe(0); + const meta = document?.meta; + const agentSelection = isObjectRecord(meta) ? meta.agentMeta : undefined; + expect(agentSelection).toMatchObject({ + provider: selected.providerKey, + model, + }); + expect(text.trim()).not.toBe(""); }, ); diff --git a/test/e2e/mock-parity.json b/test/e2e/mock-parity.json index 21256f07a43..2ffdc1fe713 100644 --- a/test/e2e/mock-parity.json +++ b/test/e2e/mock-parity.json @@ -203,8 +203,7 @@ { "live": "test/e2e/live/inference-routing-provider-smoke.test.ts", "liveSources": [ - "test/e2e/live/inference-routing-credential-scan.ts", - "test/e2e/fixtures/hermes-api-command.ts" + "test/e2e/live/inference-routing-credential-scan.ts" ], "fast": [ "test/agents/openclaw/runtime/provider-placeholder-refresh.test.ts", diff --git a/test/e2e/support/e2e-report-to-pr-workflow-boundary.test.ts b/test/e2e/support/e2e-report-to-pr-workflow-boundary.test.ts index 4dede60cb7e..70f5755acc6 100644 --- a/test/e2e/support/e2e-report-to-pr-workflow-boundary.test.ts +++ b/test/e2e/support/e2e-report-to-pr-workflow-boundary.test.ts @@ -976,7 +976,7 @@ const HOSTED_CANDIDATE_ENV: ReportEnv = { WORKFLOW_SHA: "c".repeat(40), MATRIX_RESULT: "success", SELECTED_WORKFLOW_JOBS: '["catalogue-hosted-inference"]', - JOB_TARGETS: "hosted-inference-openai", + JOB_TARGETS: "hosted-inference-openrouter", }; function hostedCandidatePr() { @@ -1035,7 +1035,7 @@ it.each(["success", "failure", "skipped"])( }); expect(report.body).toContain(`**Candidate commit:** \`${"a".repeat(40)}\``); expect(report.body).toContain(`**Trusted workflow commit:** \`${"c".repeat(40)}\``); - expect(report.body).toContain("hosted-inference-openai"); + expect(report.body).toContain("hosted-inference-openrouter"); expect(report.body).toContain(` ${result} |`); expect(report.body).toContain("cleanup.json"); expect(report.body.includes("All selected tests passed")).toBe(result === "success"); diff --git a/test/e2e/support/hosted-provider-smoke-selection.test.ts b/test/e2e/support/hosted-provider-smoke-selection.test.ts index 66a93f49fee..de4dfd6405d 100644 --- a/test/e2e/support/hosted-provider-smoke-selection.test.ts +++ b/test/e2e/support/hosted-provider-smoke-selection.test.ts @@ -6,8 +6,9 @@ import { execFileSync } from "node:child_process"; import YAML from "yaml"; import { afterEach, describe, expect, it, vi } from "vitest"; import { - HOSTED_PROVIDER_SMOKE_CASES, - hostedProviderSmokeEnvironment, + OPENROUTER_SMOKE, + configureOpenRouterSmokeEnvironment, + openRouterSmokeEnvironment, } from "../../../tools/e2e/hosted-provider-smoke.mts"; import { catalogueTarget, @@ -24,20 +25,15 @@ import { validateStandardProfileWorkflowBoundary } from "../../../tools/e2e/stan import { requireProviderSmokeSelected } from "../live/inference-routing-helpers.ts"; const workflow = YAML.parse(readFileSync(".github/workflows/e2e.yaml", "utf8")); +const selected = OPENROUTER_SMOKE; -describe.each(HOSTED_PROVIDER_SMOKE_CASES)("$label qualification selection", (selected) => { - const id = `hosted-inference-${selected.selector}`; +describe("OpenRouter qualification selection", () => { + const id = "hosted-inference-openrouter"; it("selects only the named provider in the existing smoke owner", () => { const target = catalogueTarget(id); - expect(target.agentRuntime).toBe( - selected.selector === "hermes" - ? "hermes" - : selected.selector === "openrouter" - ? "openclaw + langchain-deepagents-code" - : "openclaw", - ); + expect(target.agentRuntime).toBe("openclaw + langchain-deepagents-code"); expect(target.testFile).toBe("test/e2e/live/inference-routing-provider-smoke.test.ts"); - expect(target.timeoutMinutes).toBe(selected.selector === "openrouter" ? 90 : 30); + expect(target.timeoutMinutes).toBe(90); expect( new RegExp(target.selector!).test( `${selected.id} ${selected.label} answers through its native provider`, @@ -52,21 +48,50 @@ describe.each(HOSTED_PROVIDER_SMOKE_CASES)("$label qualification selection", (se }); it("passes only its approved key and model and refuses missing prerequisites", () => { expect( - hostedProviderSmokeEnvironment(id, { + openRouterSmokeEnvironment({ HOSTED_INFERENCE_API_KEY: "selected-canary", HOSTED_INFERENCE_MODEL: "approved-model", NVIDIA_API_KEY: "other-canary", }), ).toEqual({ [selected.credential]: "selected-canary", [selected.modelEnv]: "approved-model" }); + expect(() => openRouterSmokeEnvironment({ HOSTED_INFERENCE_MODEL: "approved-model" })).toThrow( + "requires", + ); expect(() => - hostedProviderSmokeEnvironment(id, { HOSTED_INFERENCE_MODEL: "approved-model" }), - ).toThrow("requires"); - expect(() => - hostedProviderSmokeEnvironment(id, { HOSTED_INFERENCE_API_KEY: "selected-canary" }), + openRouterSmokeEnvironment({ HOSTED_INFERENCE_API_KEY: "selected-canary" }), ).toThrow("requires"); }); + it("removes inherited retired provider credentials before the OpenRouter smoke", () => { + const environment: NodeJS.ProcessEnv = { + HOSTED_INFERENCE_API_KEY: "selected-canary", + HOSTED_INFERENCE_MODEL: "approved-model", + OPENAI_API_KEY: "retired-openai-canary", + ANTHROPIC_API_KEY: "retired-anthropic-canary", + GEMINI_API_KEY: "retired-gemini-canary", + NOUS_API_KEY: "retired-hermes-canary", + KEEP: "unrelated", + }; + configureOpenRouterSmokeEnvironment(environment); + expect(environment).toEqual({ + HOSTED_INFERENCE_MODEL: "approved-model", + OPENROUTER_API_KEY: "selected-canary", + NEMOCLAW_OPENROUTER_MODEL: "approved-model", + KEEP: "unrelated", + }); + }); }); +it.each(["openai", "anthropic", "gemini", "hermes"])( + "does not register or route the retired %s credentialed target", + (provider) => { + const id = `hosted-inference-${provider}`; + expect(E2E_TARGET_CATALOGUE.map((target) => target.id)).not.toContain(id); + expect(catalogueRecommendationSelectorIds()).not.toContain(id); + expect(() => catalogueTarget(id)).toThrow("Unknown catalogue E2E target"); + expect(() => buildE2eWorkflowPlan({ targets: id })).toThrow(); + }, +); + it("runs both OpenRouter agents through the existing trusted target", () => { const target = catalogueTarget("hosted-inference-openrouter"); expect( @@ -113,26 +138,22 @@ it("keeps hosted targets available for explicit recommendations only", () => { ).catalogueMatrices["hosted-inference"].map((row) => row.id), ).toEqual([]); expect(catalogueRecommendationSelectorIds()).toEqual( - expect.arrayContaining( - HOSTED_PROVIDER_SMOKE_CASES.map((entry) => `hosted-inference-${entry.selector}`), - ), + expect.arrayContaining(["hosted-inference-openrouter"]), ); }); -it.each(HOSTED_PROVIDER_SMOKE_CASES)( - "does not automatically select $label for its profile change", - (selected) => { - expect( - catalogueTargetsForChangedFiles([ - `managed-inference/provider-profiles/nemoclaw-${selected.selector}-inference-v1.yaml`, - ]) - .filter((target) => target.profile === "hosted-inference") - .map((target) => target.id), - ).toEqual([]); - }, -); +it("does not automatically select OpenRouter for its profile change", () => { + expect( + catalogueTargetsForChangedFiles([ + "managed-inference/provider-profiles/nemoclaw-openrouter-inference-v1.yaml", + ]) + .filter((target) => target.profile === "hosted-inference") + .map((target) => target.id), + ).toEqual([]); +}); -describe.each(HOSTED_PROVIDER_SMOKE_CASES)("$label workflow credential boundary", (provider) => { +describe("OpenRouter workflow credential boundary", () => { + const provider = OPENROUTER_SMOKE; it.each([ { name: "main dispatch", allowed: true }, { name: "main push", event: "push", allowed: true }, @@ -168,9 +189,11 @@ describe.each(HOSTED_PROVIDER_SMOKE_CASES)("$label workflow credential boundary" const secrets = { DOCKERHUB_USERNAME: "registry-user", DOCKERHUB_TOKEN: "registry-canary", - ...Object.fromEntries( - HOSTED_PROVIDER_SMOKE_CASES.map((provider) => [provider.credential, provider.selector]), - ), + OPENAI_API_KEY: "retired-openai-canary", + ANTHROPIC_API_KEY: "retired-anthropic-canary", + GEMINI_API_KEY: "retired-gemini-canary", + NOUS_API_KEY: "retired-hermes-canary", + OPENROUTER_API_KEY: "openrouter", }; const context = { github: { @@ -217,8 +240,47 @@ describe.each(HOSTED_PROVIDER_SMOKE_CASES)("$label workflow credential boundary" }); }); -// Evaluate the reusable workflow expression with distinct models to detect provider crossover. -it.each(HOSTED_PROVIDER_SMOKE_CASES)("routes only the approved $label model", (selected) => { +it.each(["openai", "anthropic", "gemini", "hermes"])( + "does not forward the retired %s secret even in a trusted workflow", + (provider) => { + const expression = workflow.jobs["catalogue-hosted-inference"].secrets.HOSTED_INFERENCE_API_KEY; + const context = { + github: { + repository: "NVIDIA/NemoClaw", + ref: "refs/heads/main", + workflow_ref: "NVIDIA/NemoClaw/.github/workflows/e2e.yaml@refs/heads/main", + event_name: "workflow_dispatch", + }, + inputs: { checkout_sha: "" }, + needs: { "generate-matrix": { outputs: { e2e_credentials_allowed: "true" } } }, + matrix: { id: `hosted-inference-${provider}` }, + secrets: { + OPENROUTER_API_KEY: "selected-canary", + OPENAI_API_KEY: "retired-canary", + ANTHROPIC_API_KEY: "retired-canary", + GEMINI_API_KEY: "retired-canary", + NOUS_API_KEY: "retired-canary", + }, + }; + const observed = execFileSync( + process.execPath, + [ + "-e", + `const { readFileSync } = require("node:fs"); + const { runInNewContext } = require("node:vm"); + const { expression, context } = JSON.parse(readFileSync(0, "utf8")); + process.stdout.write(runInNewContext( + expression.slice(3, -2).replaceAll("needs.generate-matrix", 'needs["generate-matrix"]'), + context, { timeout: 1000 }));`, + ], + { input: JSON.stringify({ expression, context }), env: {}, encoding: "utf8", timeout: 5000 }, + ); + expect(observed).toBe(""); + }, +); + +// Evaluate the reusable workflow expression with an unrelated model to detect model crossover. +it("routes only the approved OpenRouter model", () => { const profile = YAML.parse(readFileSync(".github/workflows/e2e-standard-profile.yaml", "utf8")); const step = profile.jobs.run.steps.find( (entry: { name?: string }) => entry.name === "Run catalogue E2E target", @@ -246,12 +308,7 @@ it.each(HOSTED_PROVIDER_SMOKE_CASES)("routes only the approved $label model", (s context: { matrix, inputs: { catalogue_id: `hosted-inference-${selected.selector}` }, - vars: Object.fromEntries( - HOSTED_PROVIDER_SMOKE_CASES.map((provider) => [ - provider.modelEnv, - `approved-${provider.selector}`, - ]), - ), + vars: { NEMOCLAW_OPENROUTER_MODEL: "approved-openrouter" }, }, }), env: {}, @@ -266,36 +323,38 @@ it.each(HOSTED_PROVIDER_SMOKE_CASES)("routes only the approved $label model", (s expect(() => validateE2eWorkflowPlan(plan)).toThrow("invalid output schema"); }); -describe.each(HOSTED_PROVIDER_SMOKE_CASES)("$label local smoke prerequisites", (selected) => { +describe("OpenRouter local smoke prerequisites", () => { afterEach(() => vi.unstubAllEnvs()); - it.each([undefined, "unrelated-provider"])("skips without matching opt-in %s", (requested) => { - vi.stubEnv("NEMOCLAW_INFERENCE_ROUTING_PROVIDER_SMOKE", requested); - const skip = vi.fn(); - expect(() => requireProviderSmokeSelected(selected.selector, skip)).toThrow( - `NEMOCLAW_INFERENCE_ROUTING_PROVIDER_SMOKE=${selected.selector}`, - ); - expect(skip).toHaveBeenCalledOnce(); - }); + it.each([undefined, "unrelated-provider", "all", "openai", "anthropic", "gemini", "hermes"])( + "skips without matching opt-in %s", + (requested) => { + vi.stubEnv("NEMOCLAW_INFERENCE_ROUTING_PROVIDER_SMOKE", requested); + const skip = vi.fn(); + expect(() => requireProviderSmokeSelected(selected.selector, skip)).toThrow( + `NEMOCLAW_INFERENCE_ROUTING_PROVIDER_SMOKE=${selected.selector}`, + ); + expect(skip).toHaveBeenCalledOnce(); + }, + ); it("runs only after explicit selection and validates its named key and model", () => { vi.stubEnv("NEMOCLAW_INFERENCE_ROUTING_PROVIDER_SMOKE", selected.selector); const skip = vi.fn(); requireProviderSmokeSelected(selected.selector, skip); expect(skip).not.toHaveBeenCalled(); - const id = `hosted-inference-${selected.selector}`; expect(() => - hostedProviderSmokeEnvironment(id, { + openRouterSmokeEnvironment({ [selected.modelEnv]: "approved-model", }), ).toThrow("requires its approved credential and model"); expect(() => - hostedProviderSmokeEnvironment(id, { + openRouterSmokeEnvironment({ [selected.credential]: "synthetic-selected-key", }), ).toThrow("requires its approved credential and model"); expect( - hostedProviderSmokeEnvironment(id, { + openRouterSmokeEnvironment({ [selected.credential]: "synthetic-selected-key", [selected.modelEnv]: "approved-model", }), diff --git a/test/helpers/onboard-smoke-verifier-harness.ts b/test/helpers/onboard-smoke-verifier-harness.ts index 72383eb5bfd..e6fa3b2523c 100644 --- a/test/helpers/onboard-smoke-verifier-harness.ts +++ b/test/helpers/onboard-smoke-verifier-harness.ts @@ -7,6 +7,7 @@ import path from "node:path"; export type SmokeVerifierHarnessCall = [string, ...unknown[]]; type VerifyOnboardSmokeInvocation = { + capturePayload?: boolean; selectedChatCapability?: boolean; credentialEnv?: string; endpointUrl?: string; @@ -23,6 +24,7 @@ export async function runVerifyOnboardSmokeHarness( const Module = require("node:module"); const originalLoad = Module._load; const calls = []; +let capturePayload = false; process.env.VITEST = "false"; @@ -68,7 +70,12 @@ Module._load = function patchedLoad(request, _parent, _isMain) { const headerMatch = contents.match(/header = "([^"]+)"/); authConfigSummary = headerMatch ? headerMatch[1] : "config:" + contents.trim(); } - calls.push(["runCurlProbe", args[args.length - 1], authConfigSummary]); + calls.push([ + "runCurlProbe", + args[args.length - 1], + authConfigSummary, + ...(capturePayload ? [JSON.parse(args[args.indexOf("-d") + 1])] : []), + ]); return { ok: true, httpStatus: 200, @@ -96,7 +103,8 @@ console.log = (...args) => calls.push(["log", args.join(" ")]); (async () => { for (const invocation of invocations) { - const { selectedChatCapability, ...input } = invocation; + const { selectedChatCapability, capturePayload: requestedPayload, ...input } = invocation; + capturePayload = requestedPayload === true; const capabilityCache = selectedChatCapability ? new OnboardInferenceCapabilityCache() : undefined; const effectiveInvocation = { endpointUrl: "https://api.example.com/v1", diff --git a/test/onboarding/onboard-smoke-verifier.test.ts b/test/onboarding/onboard-smoke-verifier.test.ts index 01509a07e14..9d95e63262d 100644 --- a/test/onboarding/onboard-smoke-verifier.test.ts +++ b/test/onboarding/onboard-smoke-verifier.test.ts @@ -68,6 +68,33 @@ describe("Hermes onboard smoke verification", () => { ]); }); + it("uses the fixed Hermes endpoint, NOUS credential, and Chat Completions payload (#13280)", async () => { + const calls = await runVerifyOnboardSmokeHarness([ + { + provider: "hermes-provider", + credentialEnv: "NOUS_API_KEY", + endpointUrl: "https://inference-api.nousresearch.com/v1", + model: "nous/test-model", + capturePayload: true, + }, + ]); + expect(calls.filter((call) => call[0] === "resolveProviderCredential")).toEqual([ + ["resolveProviderCredential", "NOUS_API_KEY"], + ]); + expect(calls.filter((call) => call[0] === "runCurlProbe")).toEqual([ + [ + "runCurlProbe", + "https://inference-api.nousresearch.com/v1/chat/completions", + "Authorization: Bearer resolved-NOUS_API_KEY", + expect.objectContaining({ + model: "nous/test-model", + messages: [{ role: "user", content: expect.any(String) }], + }), + ], + ]); + expect(JSON.stringify(calls)).not.toContain("OPENAI_API_KEY"); + }); + it("does not send a duplicate smoke request for a matching selected Chat Completions capability", async () => { const calls = await runVerifyOnboardSmokeHarness([ { diff --git a/tools/e2e/hosted-provider-smoke.mts b/tools/e2e/hosted-provider-smoke.mts index 849271e37f8..76cd144d90e 100644 --- a/tools/e2e/hosted-provider-smoke.mts +++ b/tools/e2e/hosted-provider-smoke.mts @@ -1,80 +1,37 @@ // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // SPDX-License-Identifier: Apache-2.0 -export const HOSTED_PROVIDER_SMOKE_CASES = [ - { - id: "TC-INF-02", - selector: "openai", - provider: "openai", - label: "OpenAI", - credential: "OPENAI_API_KEY", - modelEnv: "NEMOCLAW_OPENAI_MODEL", - defaultModel: "gpt-4o-mini", - providerKey: "openai", - endpoint: "https://api.openai.com/v1", - placeholder: "OPENAI_API_KEY", - }, - { - id: "TC-INF-03", - selector: "anthropic", - provider: "anthropic", - label: "Anthropic", - credential: "ANTHROPIC_API_KEY", - modelEnv: "NEMOCLAW_ANTHROPIC_MODEL", - defaultModel: "claude-sonnet-4-6", - providerKey: "anthropic", - endpoint: "https://api.anthropic.com", - placeholder: "ANTHROPIC_API_KEY", - }, - { - id: "TC-INF-06", - selector: "gemini", - provider: "gemini", - label: "Gemini", - credential: "GEMINI_API_KEY", - modelEnv: "NEMOCLAW_GEMINI_MODEL", - providerKey: "inference", - endpoint: "https://generativelanguage.googleapis.com/v1beta/openai/", - placeholder: "GEMINI_API_KEY", - }, - { - id: "TC-INF-07", - selector: "openrouter", - provider: "openrouter", - label: "OpenRouter", - credential: "OPENROUTER_API_KEY", - modelEnv: "NEMOCLAW_OPENROUTER_MODEL", - providerKey: "inference", - endpoint: "https://openrouter.ai/api/v1", - placeholder: "OPENROUTER_API_KEY", - }, - { - id: "TC-INF-08", - selector: "hermes", - provider: "hermes", - label: "Hermes Provider", - credential: "NOUS_API_KEY", - modelEnv: "NEMOCLAW_HERMES_MODEL", - providerKey: "inference", - endpoint: "https://inference-api.nousresearch.com/v1", - placeholder: "OPENAI_API_KEY", - }, -] as const; +export const OPENROUTER_SMOKE = { + id: "TC-INF-07", + selector: "openrouter", + provider: "openrouter", + label: "OpenRouter", + credential: "OPENROUTER_API_KEY", + modelEnv: "NEMOCLAW_OPENROUTER_MODEL", + providerKey: "inference", + endpoint: "https://openrouter.ai/api/v1", + placeholder: "OPENROUTER_API_KEY", +} as const; -/** Only the selected provider credential reaches the existing smoke test process. */ -export function hostedProviderSmokeEnvironment( - id: string, - environment: NodeJS.ProcessEnv, -): NodeJS.ProcessEnv { - const selected = HOSTED_PROVIDER_SMOKE_CASES.find( - (entry) => id === `hosted-inference-${entry.selector}`, - ); - if (!selected) throw new Error("Unknown hosted inference qualification target"); - const key = environment.HOSTED_INFERENCE_API_KEY || environment[selected.credential]; - const model = environment.HOSTED_INFERENCE_MODEL || environment[selected.modelEnv]; +/** Select only the OpenRouter credential and model for the smoke test. */ +export function openRouterSmokeEnvironment(environment: NodeJS.ProcessEnv): NodeJS.ProcessEnv { + const key = environment.HOSTED_INFERENCE_API_KEY || environment.OPENROUTER_API_KEY; + const model = environment.HOSTED_INFERENCE_MODEL || environment.NEMOCLAW_OPENROUTER_MODEL; if (!key || !model) - throw new Error( - "Selected hosted inference qualification requires its approved credential and model", - ); - return { [selected.credential]: key, [selected.modelEnv]: model }; + throw new Error("OpenRouter qualification requires its approved credential and model"); + return { OPENROUTER_API_KEY: key, NEMOCLAW_OPENROUTER_MODEL: model }; +} + +export function configureOpenRouterSmokeEnvironment(environment: NodeJS.ProcessEnv): void { + const selected = openRouterSmokeEnvironment(environment); + for (const key of [ + "HOSTED_INFERENCE_API_KEY", + "OPENAI_API_KEY", + "ANTHROPIC_API_KEY", + "GEMINI_API_KEY", + "NOUS_API_KEY", + ]) { + delete environment[key]; + } + Object.assign(environment, selected); } diff --git a/tools/e2e/standard-profile-workflow-boundary.mts b/tools/e2e/standard-profile-workflow-boundary.mts index fa8436dc7f2..52507c58be9 100644 --- a/tools/e2e/standard-profile-workflow-boundary.mts +++ b/tools/e2e/standard-profile-workflow-boundary.mts @@ -36,7 +36,7 @@ const HOSTED_WORKFLOW_SOURCE_GUARD = "github.ref == 'refs/heads/main' && github.workflow_ref == 'NVIDIA/NemoClaw/.github/workflows/e2e.yaml@refs/heads/main' && "; const guardedCallerSecret = (name: string, hosted = false): string => name === "HOSTED_INFERENCE_API_KEY" - ? `\${{ ${HOSTED_WORKFLOW_SOURCE_GUARD}github.repository == 'NVIDIA/NemoClaw' && (github.event_name == 'workflow_dispatch' || (github.event_name == 'push' && github.ref == 'refs/heads/main')) && (inputs.checkout_sha == '' || needs.generate-matrix.outputs.e2e_credentials_allowed == 'true') && (matrix.id == 'hosted-inference-openai' && secrets.OPENAI_API_KEY || matrix.id == 'hosted-inference-anthropic' && secrets.ANTHROPIC_API_KEY || matrix.id == 'hosted-inference-gemini' && secrets.GEMINI_API_KEY || matrix.id == 'hosted-inference-openrouter' && secrets.OPENROUTER_API_KEY || matrix.id == 'hosted-inference-hermes' && secrets.NOUS_API_KEY) || '' }}` + ? `\${{ ${HOSTED_WORKFLOW_SOURCE_GUARD}github.repository == 'NVIDIA/NemoClaw' && (github.event_name == 'workflow_dispatch' || (github.event_name == 'push' && github.ref == 'refs/heads/main')) && (inputs.checkout_sha == '' || needs.generate-matrix.outputs.e2e_credentials_allowed == 'true') && matrix.id == 'hosted-inference-openrouter' && secrets.OPENROUTER_API_KEY || '' }}` : `\${{ ${hosted ? HOSTED_WORKFLOW_SOURCE_GUARD : ""}${TRUSTED_CALLER_CREDENTIAL_PREDICATE} && secrets.${name} || '' }}`; const SKILL_AGENT_UPLOAD_PATH = `${[ "e2e-artifacts/live/skill-agent/evidence-manifest.json", diff --git a/tools/e2e/target-catalogue.mts b/tools/e2e/target-catalogue.mts index 8da00cbb04f..700a39ba29a 100644 --- a/tools/e2e/target-catalogue.mts +++ b/tools/e2e/target-catalogue.mts @@ -32,10 +32,7 @@ import { import { SANDBOX_SURVIVAL_TARGET_TIMEOUT_MINUTES } from "./sandbox-survival-timeout-contract.mts"; import { normalizeE2eSelectorId } from "./selector-aliases.mts"; -import { - HOSTED_PROVIDER_SMOKE_CASES, - hostedProviderSmokeEnvironment, -} from "./hosted-provider-smoke.mts"; +import { OPENROUTER_SMOKE, configureOpenRouterSmokeEnvironment } from "./hosted-provider-smoke.mts"; export const E2E_EXECUTION_PROFILES = [ "standard", @@ -1004,46 +1001,28 @@ export const E2E_TARGET_CATALOGUE: readonly E2eCatalogueTarget[] = [ NEMOCLAW_SANDBOX_NAME: "e2e-issue-4462", }, }), - ...HOSTED_PROVIDER_SMOKE_CASES.map((selected) => - dockerOnlyTarget(`hosted-inference-${selected.selector}`, { - displayName: - selected.selector === "openrouter" - ? "Inference: completes native OpenRouter agent requests" - : `Inference: completes a native ${selected.label} agent request`, - agentRuntime: - selected.selector === "hermes" - ? "hermes" - : selected.selector === "openrouter" - ? "openclaw + langchain-deepagents-code" - : "openclaw", - prAdvisorSelectable: true, - owningPaths: [ - "test/e2e/live/inference-routing-credential-scan.ts", - `managed-inference/provider-profiles/nemoclaw-${selected.selector}-inference-v1.yaml`, - ...(["openai", "anthropic", "hermes"].includes(selected.selector) - ? ["src/lib/inference/native-provider/", "src/lib/onboard/setup-inference.ts"] - : []), - ...(selected.selector === "hermes" ? ["src/lib/hermes-provider-auth.ts"] : []), - ...(selected.selector === "openrouter" - ? [ - "agents/langchain-deepagents-code/managed-dcode-runtime.py", - "agents/langchain-deepagents-code/generate-config.ts", - "src/lib/inference/managed-dcode/", - ] - : []), - ], - environmentOrInferenceEndpoint: `Ubuntu; ${selected.label} hosted inference`, - profile: "hosted-inference", - releaseRequired: false, - testFile: "test/e2e/live/inference-routing-provider-smoke.test.ts", - selector: selected.selector === "openrouter" ? selected.id : `^${selected.id}`, - timeoutMinutes: selected.selector === "openrouter" ? 90 : 30, - installMode: "none", - restoreCli: true, - exposeCliBin: true, - environment: { NEMOCLAW_INFERENCE_ROUTING_PROVIDER_SMOKE: selected.selector }, - }), - ), + dockerOnlyTarget("hosted-inference-openrouter", { + displayName: "Inference: completes native OpenRouter agent requests", + agentRuntime: "openclaw + langchain-deepagents-code", + prAdvisorSelectable: true, + owningPaths: [ + "test/e2e/live/inference-routing-credential-scan.ts", + "managed-inference/provider-profiles/nemoclaw-openrouter-inference-v1.yaml", + "agents/langchain-deepagents-code/managed-dcode-runtime.py", + "agents/langchain-deepagents-code/generate-config.ts", + "src/lib/inference/managed-dcode/", + ], + environmentOrInferenceEndpoint: "Ubuntu; OpenRouter hosted inference", + profile: "hosted-inference", + releaseRequired: false, + testFile: "test/e2e/live/inference-routing-provider-smoke.test.ts", + selector: OPENROUTER_SMOKE.id, + timeoutMinutes: 90, + installMode: "none", + restoreCli: true, + exposeCliBin: true, + environment: { NEMOCLAW_INFERENCE_ROUTING_PROVIDER_SMOKE: "openrouter" }, + }), managedRuntimeTarget("inference-routing", { displayName: "Inference: rejects unsafe routes and proves runtime identities", agentRuntime: "openclaw + langchain-deepagents-code", @@ -1920,9 +1899,7 @@ export function catalogueMatrix( e2eRuntimeProviders(entry.gatewayRuntimes, gatewayRuntimes).map((runtimeProvider) => ({ ...(profile === "hosted-inference" ? { - model_env: HOSTED_PROVIDER_SMOKE_CASES.find( - (selected) => entry.id === `hosted-inference-${selected.selector}`, - )!.modelEnv, + model_env: OPENROUTER_SMOKE.modelEnv, } : {}), id: entry.id, @@ -1961,10 +1938,7 @@ export async function runCatalogueTarget(id: string, testFile: string): Promise< } Object.assign(process.env, entry.environment); if (entry.profile === "hosted-inference") { - const selectedEnvironment = hostedProviderSmokeEnvironment(id, process.env); - for (const selected of HOSTED_PROVIDER_SMOKE_CASES) delete process.env[selected.credential]; - delete process.env.HOSTED_INFERENCE_API_KEY; - Object.assign(process.env, selectedEnvironment); + configureOpenRouterSmokeEnvironment(process.env); } if (entry.exposeCliBin) { process.env.NEMOCLAW_CLI_BIN = path.join(process.cwd(), "bin", "nemoclaw.js"); diff --git a/tools/e2e/workflow-plan.mts b/tools/e2e/workflow-plan.mts index 1e3925195e9..cd3db1890eb 100644 --- a/tools/e2e/workflow-plan.mts +++ b/tools/e2e/workflow-plan.mts @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 import { appendFileSync } from "node:fs"; -import { HOSTED_PROVIDER_SMOKE_CASES } from "./hosted-provider-smoke.mts"; +import { OPENROUTER_SMOKE } from "./hosted-provider-smoke.mts"; import { requiresManagedImages } from "./workflow-prerequisites.mts"; import path from "node:path"; import { fileURLToPath } from "node:url"; @@ -402,9 +402,7 @@ function isCatalogueMatrixRowForProfile( return ( target?.profile === profile && value.model_env === - HOSTED_PROVIDER_SMOKE_CASES.find( - (selected) => target.id === `hosted-inference-${selected.selector}`, - )?.modelEnv && + (target.id === "hosted-inference-openrouter" ? OPENROUTER_SMOKE.modelEnv : undefined) && target.targetId === value.target_id && target.displayName === value.display_name && target.agentRuntime === value.agent_runtime &&