From d8fcaa8f6375aff59894fba241c020af9a363ee3 Mon Sep 17 00:00:00 2001 From: simoneschiavoi <314799283+simoneschiavoi@users.noreply.github.com> Date: Fri, 9 Oct 2026 14:23:13 +0200 Subject: [PATCH 1/8] test(e2e): accept aligned inference get columns in live switch target The live OpenClaw inference-switch target asserted exact single-space Provider and Model substrings against `nemoclaw inference get` output, but the CLI renders aligned label columns, so the target failed on terminal padding without a provider or inference change. Match the labeled fields with one-or-more-space tolerance instead; the exact rendering contract stays owned by src/lib/actions/inference-get.test.ts. Signed-off-by: simoneschiavoi <314799283+simoneschiavoi@users.noreply.github.com> --- test/e2e/live/openclaw-inference-switch.test.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/test/e2e/live/openclaw-inference-switch.test.ts b/test/e2e/live/openclaw-inference-switch.test.ts index 055ad7f9cbe..751c6523641 100644 --- a/test/e2e/live/openclaw-inference-switch.test.ts +++ b/test/e2e/live/openclaw-inference-switch.test.ts @@ -533,6 +533,10 @@ async function openclawGatewayPid(sandbox: SandboxClient, home: string): Promise return result.stdout.trim(); } +function escapeRegExp(value: string): string { + return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); +} + async function getRouteOutput(host: HostCliClient, home: string): Promise { return runNemoclaw(host, home, ["inference", "get"], { artifactName: "nemoclaw-inference-get-after-switch", @@ -1315,8 +1319,10 @@ test( const route = await getRouteOutput(host, home); expect(route.exitCode, resultText(route)).toBe(0); const plainRoute = stripAnsi(resultText(route)); - expect(plainRoute).toContain(`Provider: ${SWITCH_PROVIDER}`); - expect(plainRoute).toContain(`Model: ${SWITCH_MODEL}`); + // The CLI aligns the label columns; the exact rendering contract is owned by + // src/lib/actions/inference-get.test.ts, so accept one or more spaces here. + expect(plainRoute).toMatch(new RegExp(`Provider: +${escapeRegExp(SWITCH_PROVIDER)}\\b`)); + expect(plainRoute).toMatch(new RegExp(`Model: +${escapeRegExp(SWITCH_MODEL)}\\b`)); await assertOpenClawConfig(sandbox, home, { model: SWITCH_MODEL, inferenceApi: SWITCH_INFERENCE_API, From 5c2b5b5325181db6b0d340fc2b973712323c19bf Mon Sep 17 00:00:00 2001 From: simoneschiavoi <314799283+simoneschiavoi@users.noreply.github.com> Date: Fri, 9 Oct 2026 14:40:30 +0200 Subject: [PATCH 2/8] test(e2e): anchor inference get route values to line boundaries CodeRabbit review on #12911: word-boundary anchors let suffixed values pass because a hyphen already ends a word. Require each displayed value to end at a newline or end of output instead. Signed-off-by: simoneschiavoi <314799283+simoneschiavoi@users.noreply.github.com> --- test/e2e/live/openclaw-inference-switch.test.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/test/e2e/live/openclaw-inference-switch.test.ts b/test/e2e/live/openclaw-inference-switch.test.ts index 751c6523641..e6dea8ab0b7 100644 --- a/test/e2e/live/openclaw-inference-switch.test.ts +++ b/test/e2e/live/openclaw-inference-switch.test.ts @@ -1320,9 +1320,12 @@ test( expect(route.exitCode, resultText(route)).toBe(0); const plainRoute = stripAnsi(resultText(route)); // The CLI aligns the label columns; the exact rendering contract is owned by - // src/lib/actions/inference-get.test.ts, so accept one or more spaces here. - expect(plainRoute).toMatch(new RegExp(`Provider: +${escapeRegExp(SWITCH_PROVIDER)}\\b`)); - expect(plainRoute).toMatch(new RegExp(`Model: +${escapeRegExp(SWITCH_MODEL)}\\b`)); + // src/lib/actions/inference-get.test.ts, so accept one or more spaces here and + // require each displayed value to end at the line boundary. + expect(plainRoute).toMatch( + new RegExp(`Provider: +${escapeRegExp(SWITCH_PROVIDER)}(?:\\r?\\n|$)`), + ); + expect(plainRoute).toMatch(new RegExp(`Model: +${escapeRegExp(SWITCH_MODEL)}(?:\\r?\\n|$)`)); await assertOpenClawConfig(sandbox, home, { model: SWITCH_MODEL, inferenceApi: SWITCH_INFERENCE_API, From 4530e9be5f2549547a2aef15ac285869b012c5ef Mon Sep 17 00:00:00 2001 From: Rebecca Sliter <571084+rsliter@users.noreply.github.com> Date: Fri, 9 Oct 2026 10:11:28 -0700 Subject: [PATCH 3/8] test(e2e): move switch status rendering checks to fast tests Keep the live switch target focused on route state and inference outcomes. Extend fast coverage for the Anthropic-compatible route and map it to the live target. Signed-off-by: Rebecca Sliter <571084+rsliter@users.noreply.github.com> --- ci/e2e-assertion-budget.json | 14 ++++++------ src/lib/actions/inference-get.test.ts | 22 +++++++++++++++++++ .../live/openclaw-inference-switch.test.ts | 16 -------------- test/e2e/mock-parity.json | 1 + 4 files changed, 30 insertions(+), 23 deletions(-) diff --git a/ci/e2e-assertion-budget.json b/ci/e2e-assertion-budget.json index 9a6bd60d8bf..6b94178e859 100644 --- a/ci/e2e-assertion-budget.json +++ b/ci/e2e-assertion-budget.json @@ -15,26 +15,26 @@ "testFileCount": 77, "liveFileCount": 185, "direct": { - "expectCalls": 1234, - "matcherAssertions": 1213, + "expectCalls": 1232, + "matcherAssertions": 1211, "nodeAssertions": 104, "namedAssertionHelpers": 426, "failCalls": 0, "throwGuards": 50, "objectFieldAssertions": 166, - "assertionPoints": 1959, + "assertionPoints": 1957, "generatedProbeBlocks": 87, "generatedProbeConditions": 216 }, "unique": { - "expectCalls": 1659, - "matcherAssertions": 1633, + "expectCalls": 1657, + "matcherAssertions": 1631, "nodeAssertions": 127, "namedAssertionHelpers": 671, "failCalls": 1, "throwGuards": 528, "objectFieldAssertions": 243, - "assertionPoints": 3203, + "assertionPoints": 3201, "generatedProbeBlocks": 209, "generatedProbeConditions": 721 }, @@ -95,7 +95,7 @@ "test/e2e/live/onboard-repair.test.ts": [21,25,21,25,0], "test/e2e/live/onboard-resume.test.ts": [59,63,59,63,0], "test/e2e/live/openclaw-discord-pairing.test.ts": [13,20,28,86,10], - "test/e2e/live/openclaw-inference-switch.test.ts": [44,50,45,52,1], + "test/e2e/live/openclaw-inference-switch.test.ts": [42,48,43,50,1], "test/e2e/live/openclaw-skill-cli.test.ts": [10,14,10,14,1], "test/e2e/live/openclaw-slack-pairing.test.ts": [11,18,26,84,10], "test/e2e/live/openshell-credential-generation-window.test.ts": [42,92,43,112,18], diff --git a/src/lib/actions/inference-get.test.ts b/src/lib/actions/inference-get.test.ts index e60ba29acf7..40b6d5bdf14 100644 --- a/src/lib/actions/inference-get.test.ts +++ b/src/lib/actions/inference-get.test.ts @@ -220,6 +220,28 @@ describe("runInferenceGet", () => { ]); }); + it("returns the recorded Anthropic route while preserving the aligned display (#12850)", async () => { + const deps = createDeps( + configuredRoute("compatible-anthropic-endpoint", "mock-anthropic-model"), + ); + recordRoute(deps, { + provider: "compatible-anthropic-endpoint", + model: "mock-anthropic-model", + endpointUrl: "https://inference.example.test/v1", + }); + + await expect(runInferenceGet({ sandboxName: "custom" }, deps)).resolves.toEqual({ + provider: "compatible-anthropic-endpoint", + model: "mock-anthropic-model", + endpointUrl: "https://inference.example.test/v1", + }); + expect(deps.log.mock.calls.map(([line]) => line)).toEqual([ + "Provider: compatible-anthropic-endpoint", + "Model: mock-anthropic-model", + "Endpoint: https://inference.example.test/v1", + ]); + }); + it("supports JSON output", async () => { const deps = createDeps(configuredRoute("openai-api", "gpt-5.4")); diff --git a/test/e2e/live/openclaw-inference-switch.test.ts b/test/e2e/live/openclaw-inference-switch.test.ts index e6dea8ab0b7..ba4b0c273e3 100644 --- a/test/e2e/live/openclaw-inference-switch.test.ts +++ b/test/e2e/live/openclaw-inference-switch.test.ts @@ -227,10 +227,6 @@ async function proveSelectedMockBaselineAuthentication( ).toContainEqual(expectedRequest); } -function stripAnsi(value: string): string { - return value.replace(/\u001B\[[0-?]*[ -/]*[@-~]/g, ""); -} - function parsePortEnv(name: string, fallback: number): number { const raw = process.env[name]; if (!raw) return fallback; @@ -533,10 +529,6 @@ async function openclawGatewayPid(sandbox: SandboxClient, home: string): Promise return result.stdout.trim(); } -function escapeRegExp(value: string): string { - return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); -} - async function getRouteOutput(host: HostCliClient, home: string): Promise { return runNemoclaw(host, home, ["inference", "get"], { artifactName: "nemoclaw-inference-get-after-switch", @@ -1318,14 +1310,6 @@ test( progress.phase("inspect route configuration and recorded state"); const route = await getRouteOutput(host, home); expect(route.exitCode, resultText(route)).toBe(0); - const plainRoute = stripAnsi(resultText(route)); - // The CLI aligns the label columns; the exact rendering contract is owned by - // src/lib/actions/inference-get.test.ts, so accept one or more spaces here and - // require each displayed value to end at the line boundary. - expect(plainRoute).toMatch( - new RegExp(`Provider: +${escapeRegExp(SWITCH_PROVIDER)}(?:\\r?\\n|$)`), - ); - expect(plainRoute).toMatch(new RegExp(`Model: +${escapeRegExp(SWITCH_MODEL)}(?:\\r?\\n|$)`)); await assertOpenClawConfig(sandbox, home, { model: SWITCH_MODEL, inferenceApi: SWITCH_INFERENCE_API, diff --git a/test/e2e/mock-parity.json b/test/e2e/mock-parity.json index 00636d8d9a1..7f0e893a486 100644 --- a/test/e2e/mock-parity.json +++ b/test/e2e/mock-parity.json @@ -831,6 +831,7 @@ "test/e2e/fixtures/managed-image-receipt.ts" ], "fast": [ + "src/lib/actions/inference-get.test.ts", "src/lib/actions/inference-set-compatible-provider.test.ts", "test/e2e/support/retry-policy.test.ts", "test/e2e/support/compatible-anthropic-switch.test.ts", From 9f20a476787691f9e673434d37fcbb150584afe4 Mon Sep 17 00:00:00 2001 From: Rebecca Sliter <571084+rsliter@users.noreply.github.com> Date: Fri, 9 Oct 2026 11:35:47 -0700 Subject: [PATCH 4/8] test(e2e): use mock baseline for native NVIDIA switch Signed-off-by: Rebecca Sliter <571084+rsliter@users.noreply.github.com> (cherry picked from commit d91e7f78505b8f9a59316ea3a79f24e965427526) --- test/e2e/live/openclaw-inference-switch.test.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/e2e/live/openclaw-inference-switch.test.ts b/test/e2e/live/openclaw-inference-switch.test.ts index afbe391c1d5..9c1e99cd429 100644 --- a/test/e2e/live/openclaw-inference-switch.test.ts +++ b/test/e2e/live/openclaw-inference-switch.test.ts @@ -1152,7 +1152,8 @@ test( }); const useMockBaseline = - SWITCH_PROVIDER === "compatible-anthropic-endpoint" && SWITCH_MOCK_ANTHROPIC === "1"; + SWITCH_PROVIDER === PUBLIC_NVIDIA_SWITCH_PROVIDER || + (SWITCH_PROVIDER === "compatible-anthropic-endpoint" && SWITCH_MOCK_ANTHROPIC === "1"); // OpenShell reaches this fixture from its gateway network namespace, where // the runner's loopback address is not routable. const baselineProvider: FakeOpenAiCompatibleServer | undefined = useMockBaseline From ab7b0235913d5e449a3a1b9337da16bce057664a Mon Sep 17 00:00:00 2001 From: Rebecca Sliter <571084+rsliter@users.noreply.github.com> Date: Fri, 9 Oct 2026 11:48:53 -0700 Subject: [PATCH 5/8] test(e2e): protect native switch baseline credentials Signed-off-by: Rebecca Sliter <571084+rsliter@users.noreply.github.com> (cherry picked from commit 1ffa09326ac560b9c455dbdbdd40cd082385cc50) --- ...openclaw-inference-switch-baseline.test.ts | 79 +++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 test/e2e/support/openclaw-inference-switch-baseline.test.ts diff --git a/test/e2e/support/openclaw-inference-switch-baseline.test.ts b/test/e2e/support/openclaw-inference-switch-baseline.test.ts new file mode 100644 index 00000000000..bcc4a9eaa53 --- /dev/null +++ b/test/e2e/support/openclaw-inference-switch-baseline.test.ts @@ -0,0 +1,79 @@ +// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +import fs from "node:fs"; + +import { afterEach, expect, it, vi } from "vitest"; + +const captured = vi.hoisted(() => ({ test: vi.fn() })); +vi.mock("../fixtures/e2e-test.ts", async () => ({ + expect: (await import("vitest")).expect, + test: captured.test, +})); +vi.mock("../fixtures/managed-image-receipt.ts", () => ({ + selectedE2eManagedImageReference: () => "example.invalid/openclaw@sha256:" + "a".repeat(64), +})); + +const disposables: Array<() => unknown> = []; +afterEach(async () => { + for (const dispose of disposables.splice(0).reverse()) await dispose(); + vi.restoreAllMocks(); + vi.unstubAllEnvs(); +}); + +it("keeps the public NVIDIA key out of the native switch baseline", async () => { + vi.resetModules(); + captured.test.mockClear(); + vi.stubEnv("NEMOCLAW_SWITCH_PROVIDER", "nvidia-prod"); + vi.stubEnv("NEMOCLAW_SWITCH_MOCK_ANTHROPIC", "0"); + const exists = fs.existsSync; + vi.spyOn(fs, "existsSync").mockImplementation((file) => + String(file).endsWith("bin/nemoclaw.js") ? true : exists(file), + ); + const result = { exitCode: 0, stdout: "", stderr: "" }; + const stop = new Error("onboarding captured"); + const nemoclaw = vi.fn( + async (_args: string[], _options: { env: NodeJS.ProcessEnv; redactionValues: string[] }) => { + throw stop; + }, + ); + await import("../live/openclaw-inference-switch.test.ts"); + const { startTestProgress } = await import("../fixtures/progress.ts"); + const progress = startTestProgress( + "native switch baseline", + captured.test.mock.calls[0]![1].meta.e2ePhases, + { logLine: () => undefined }, + ); + disposables.push(() => progress.stop()); + const run = captured.test.mock.calls[0]![2] as (input: object) => Promise; + const required = vi.fn((name: string) => { + expect(name).toBe("NVIDIA_API_KEY"); + return "nvapi-public-fixture-key"; + }); + await expect( + run({ + artifacts: { target: { declare: vi.fn() } }, + cleanup: { + trackDisposable: (_name: string, dispose: () => unknown) => disposables.push(dispose), + trackGateway: vi.fn(), + trackSandbox: vi.fn(), + }, + host: { nemoclaw, command: vi.fn(async () => result) }, + progress, + runtimeProvider: { requireAvailable: vi.fn() }, + sandbox: { openshell: vi.fn(async () => result), cleanupSandbox: vi.fn() }, + secrets: { required }, + }), + ).rejects.toBe(stop); + expect(required).toHaveBeenCalledExactlyOnceWith("NVIDIA_API_KEY"); + const options = nemoclaw.mock.calls[0]![1]; + const environment = options.env; + expect(environment.NEMOCLAW_PROVIDER).toBe("custom"); + expect(environment.NEMOCLAW_ENDPOINT_URL).toMatch(/^http:\/\/host\.openshell\.internal:\d+\/v1$/); + expect(environment.NEMOCLAW_MODEL).toBe("openclaw-switch-baseline-model"); + expect(environment.COMPATIBLE_API_KEY).toBe("openclaw-switch-baseline-credential"); + expect(environment.NVIDIA_INFERENCE_API_KEY).toBeUndefined(); + expect(environment.NVIDIA_API_KEY).toBeUndefined(); + expect(options.redactionValues).toContain("nvapi-public-fixture-key"); + expect(options.redactionValues).toContain("openclaw-switch-baseline-credential"); +}); From 8459ede31ae9609b1991dcbd1279103508f55c59 Mon Sep 17 00:00:00 2001 From: Rebecca Sliter <571084+rsliter@users.noreply.github.com> Date: Fri, 9 Oct 2026 12:22:55 -0700 Subject: [PATCH 6/8] test(e2e): map native switch baseline fast test Signed-off-by: Rebecca Sliter <571084+rsliter@users.noreply.github.com> (cherry picked from commit 2bd54be82e15dcbc17eb8e2c1f4c50b0a60b9ce4) --- test/e2e/mock-parity.json | 1 + 1 file changed, 1 insertion(+) diff --git a/test/e2e/mock-parity.json b/test/e2e/mock-parity.json index eb7546b88de..ef7b0f9b608 100644 --- a/test/e2e/mock-parity.json +++ b/test/e2e/mock-parity.json @@ -840,6 +840,7 @@ "test/e2e/support/e2e-clients.test.ts", "test/e2e/support/inference-switch-workflow-boundary.test.ts", "test/e2e/support/managed-image-receipt.test.ts", + "test/e2e/support/openclaw-inference-switch-baseline.test.ts", "test/e2e/support/openclaw-inference-switch-helpers.test.ts", "test/e2e/support/public-nvidia-switch-provider.test.ts", "test/security/admin-approval-helper.test.ts", From a4efb7ccd67240f9ec0360e2d0b76b3eb950f0a0 Mon Sep 17 00:00:00 2001 From: Rebecca Sliter <571084+rsliter@users.noreply.github.com> Date: Fri, 9 Oct 2026 13:34:02 -0700 Subject: [PATCH 7/8] test(e2e): remove redundant inference status probe Signed-off-by: Rebecca Sliter <571084+rsliter@users.noreply.github.com> --- ci/e2e-assertion-budget.json | 14 +++++++------- test/e2e/live/openclaw-inference-switch.test.ts | 14 ++------------ 2 files changed, 9 insertions(+), 19 deletions(-) diff --git a/ci/e2e-assertion-budget.json b/ci/e2e-assertion-budget.json index b65ea4bacae..71e0d59d22e 100644 --- a/ci/e2e-assertion-budget.json +++ b/ci/e2e-assertion-budget.json @@ -15,26 +15,26 @@ "testFileCount": 77, "liveFileCount": 185, "direct": { - "expectCalls": 1238, - "matcherAssertions": 1217, + "expectCalls": 1237, + "matcherAssertions": 1216, "nodeAssertions": 104, "namedAssertionHelpers": 424, "failCalls": 0, "throwGuards": 50, "objectFieldAssertions": 166, - "assertionPoints": 1961, + "assertionPoints": 1960, "generatedProbeBlocks": 87, "generatedProbeConditions": 216 }, "unique": { - "expectCalls": 1663, - "matcherAssertions": 1637, + "expectCalls": 1662, + "matcherAssertions": 1636, "nodeAssertions": 127, "namedAssertionHelpers": 669, "failCalls": 1, "throwGuards": 528, "objectFieldAssertions": 243, - "assertionPoints": 3205, + "assertionPoints": 3204, "generatedProbeBlocks": 209, "generatedProbeConditions": 721 }, @@ -95,7 +95,7 @@ "test/e2e/live/onboard-repair.test.ts": [21,25,21,25,0], "test/e2e/live/onboard-resume.test.ts": [59,63,59,63,0], "test/e2e/live/openclaw-discord-pairing.test.ts": [13,20,28,86,10], - "test/e2e/live/openclaw-inference-switch.test.ts": [42,48,43,50,1], + "test/e2e/live/openclaw-inference-switch.test.ts": [41,47,42,49,1], "test/e2e/live/openclaw-skill-cli.test.ts": [10,14,10,14,1], "test/e2e/live/openclaw-slack-pairing.test.ts": [11,18,26,84,10], "test/e2e/live/openshell-credential-generation-window.test.ts": [42,92,43,112,18], diff --git a/test/e2e/live/openclaw-inference-switch.test.ts b/test/e2e/live/openclaw-inference-switch.test.ts index 9c1e99cd429..cd63db847d4 100644 --- a/test/e2e/live/openclaw-inference-switch.test.ts +++ b/test/e2e/live/openclaw-inference-switch.test.ts @@ -529,13 +529,6 @@ async function openclawGatewayPid(sandbox: SandboxClient, home: string): Promise return result.stdout.trim(); } -async function getRouteOutput(host: HostCliClient, home: string): Promise { - return runNemoclaw(host, home, ["inference", "get"], { - artifactName: "nemoclaw-inference-get-after-switch", - timeoutMs: COMMAND_TIMEOUT_MS, - }); -} - async function assertRegistryAndSession( home: string, options: { mockProvider?: MockAnthropicProvider; sandbox: SandboxClient }, @@ -1133,7 +1126,7 @@ test( "when selected, the mock baseline route completes one explicit authenticated fixture request", "nemoclaw inference set switches the running sandbox route", "OpenClaw gateway is supervisor-restarted after every changed inference configuration", - "NemoClaw reports the switched provider/model", + "NemoClaw records the switched provider/model", "OpenClaw config reflects the switched inference API/model", "registry and onboard session record the switched provider/model", "sandbox inference returns PONG from the switched model", @@ -1316,8 +1309,6 @@ test( } progress.phase("inspect route configuration and recorded state"); - const route = await getRouteOutput(host, home); - expect(route.exitCode, resultText(route)).toBe(0); await assertOpenClawConfig(sandbox, home, { model: SWITCH_MODEL, inferenceApi: SWITCH_INFERENCE_API, @@ -1333,7 +1324,7 @@ test( id: "openclaw-inference-switch", status: "skipped", reason: inference.skipped, - routeAndConfigChecksPassed: true, + configAndStateChecksPassed: true, }); skip(inference.skipped); } @@ -1382,7 +1373,6 @@ test( inferenceSetCompleted: switchResult.exitCode === 0, gatewayRestartExpected: true, gatewayPidStable, - routeChecked: true, configChecked: true, registryAndSessionChecked: true, inferenceLocalPong: true, From 909558b824dfed435b282fcc651b76596efb7326 Mon Sep 17 00:00:00 2001 From: Rebecca Sliter <571084+rsliter@users.noreply.github.com> Date: Fri, 9 Oct 2026 14:11:42 -0700 Subject: [PATCH 8/8] test(e2e): guard native baseline setup and trim duplicate coverage Signed-off-by: Rebecca Sliter <571084+rsliter@users.noreply.github.com> --- src/lib/actions/inference-get.test.ts | 22 -------------- .../live/openclaw-inference-switch.test.ts | 14 ++++----- ...openclaw-inference-switch-baseline.test.ts | 30 +++++++++++++++++++ 3 files changed, 37 insertions(+), 29 deletions(-) diff --git a/src/lib/actions/inference-get.test.ts b/src/lib/actions/inference-get.test.ts index 40b6d5bdf14..e60ba29acf7 100644 --- a/src/lib/actions/inference-get.test.ts +++ b/src/lib/actions/inference-get.test.ts @@ -220,28 +220,6 @@ describe("runInferenceGet", () => { ]); }); - it("returns the recorded Anthropic route while preserving the aligned display (#12850)", async () => { - const deps = createDeps( - configuredRoute("compatible-anthropic-endpoint", "mock-anthropic-model"), - ); - recordRoute(deps, { - provider: "compatible-anthropic-endpoint", - model: "mock-anthropic-model", - endpointUrl: "https://inference.example.test/v1", - }); - - await expect(runInferenceGet({ sandboxName: "custom" }, deps)).resolves.toEqual({ - provider: "compatible-anthropic-endpoint", - model: "mock-anthropic-model", - endpointUrl: "https://inference.example.test/v1", - }); - expect(deps.log.mock.calls.map(([line]) => line)).toEqual([ - "Provider: compatible-anthropic-endpoint", - "Model: mock-anthropic-model", - "Endpoint: https://inference.example.test/v1", - ]); - }); - it("supports JSON output", async () => { const deps = createDeps(configuredRoute("openai-api", "gpt-5.4")); diff --git a/test/e2e/live/openclaw-inference-switch.test.ts b/test/e2e/live/openclaw-inference-switch.test.ts index cd63db847d4..0430edf88b1 100644 --- a/test/e2e/live/openclaw-inference-switch.test.ts +++ b/test/e2e/live/openclaw-inference-switch.test.ts @@ -1144,6 +1144,10 @@ test( scenarioLabel: "OpenClaw inference switch", }); + const publicApiKey = + SWITCH_PROVIDER === PUBLIC_NVIDIA_SWITCH_PROVIDER + ? requirePublicNvidiaSwitchKey(secrets.required("NVIDIA_API_KEY")) + : null; const useMockBaseline = SWITCH_PROVIDER === PUBLIC_NVIDIA_SWITCH_PROVIDER || (SWITCH_PROVIDER === "compatible-anthropic-endpoint" && SWITCH_MOCK_ANTHROPIC === "1"); @@ -1152,10 +1156,9 @@ test( const baselineProvider: FakeOpenAiCompatibleServer | undefined = useMockBaseline ? await startMockOpenClawBaselineProvider(progress) : undefined; - const publicApiKey = - SWITCH_PROVIDER === PUBLIC_NVIDIA_SWITCH_PROVIDER - ? requirePublicNvidiaSwitchKey(secrets.required("NVIDIA_API_KEY")) - : null; + cleanup.trackDisposable("close baseline inference provider", async () => { + await baselineProvider?.close(); + }); const baseline = baselineProvider ? mockBaselineInference(baselineProvider.baseUrl) : requireHostedInferenceConfig({ @@ -1177,9 +1180,6 @@ test( cleanup.trackDisposable("close switched Anthropic provider", async () => { await mockProvider?.close(); }); - cleanup.trackDisposable("close baseline inference provider", async () => { - await baselineProvider?.close(); - }); const customDockerfile = writeCustomOpenClawDockerfile(home); cleanup.trackGateway(host, "nemoclaw", { artifactName: "cleanup-openshell-gateway-destroy-openclaw-inference-switch", diff --git a/test/e2e/support/openclaw-inference-switch-baseline.test.ts b/test/e2e/support/openclaw-inference-switch-baseline.test.ts index bcc4a9eaa53..40b74f36ba4 100644 --- a/test/e2e/support/openclaw-inference-switch-baseline.test.ts +++ b/test/e2e/support/openclaw-inference-switch-baseline.test.ts @@ -19,6 +19,7 @@ afterEach(async () => { for (const dispose of disposables.splice(0).reverse()) await dispose(); vi.restoreAllMocks(); vi.unstubAllEnvs(); + vi.doUnmock("../live/openclaw-inference-switch-helpers.ts"); }); it("keeps the public NVIDIA key out of the native switch baseline", async () => { @@ -77,3 +78,32 @@ it("keeps the public NVIDIA key out of the native switch baseline", async () => expect(options.redactionValues).toContain("nvapi-public-fixture-key"); expect(options.redactionValues).toContain("openclaw-switch-baseline-credential"); }); + +it("rejects an invalid NVIDIA key before starting the baseline provider", async () => { + vi.resetModules(); + captured.test.mockClear(); + vi.stubEnv("NEMOCLAW_SWITCH_PROVIDER", "nvidia-prod"); + vi.stubEnv("NEMOCLAW_SWITCH_MOCK_ANTHROPIC", "0"); + const startBaseline = vi.fn(); + vi.doMock("../live/openclaw-inference-switch-helpers.ts", async (importOriginal) => ({ + ...(await importOriginal()), + startMockOpenClawBaselineProvider: startBaseline, + })); + const exists = fs.existsSync; + vi.spyOn(fs, "existsSync").mockImplementation((file) => + String(file).endsWith("bin/nemoclaw.js") ? true : exists(file), + ); + + await import("../live/openclaw-inference-switch.test.ts"); + const run = captured.test.mock.calls[0]![2] as (input: object) => Promise; + const required = vi.fn(() => "invalid-key"); + await expect( + run({ + artifacts: { target: { declare: vi.fn() } }, + runtimeProvider: { requireAvailable: vi.fn() }, + secrets: { required }, + }), + ).rejects.toThrow("NVIDIA_API_KEY must be a public NVIDIA Endpoints nvapi-* key"); + expect(required).toHaveBeenCalledExactlyOnceWith("NVIDIA_API_KEY"); + expect(startBaseline).not.toHaveBeenCalled(); +});