diff --git a/src/lib/actions/inference-set-gateway-route-containment.test.ts b/src/lib/actions/inference-set-gateway-route-containment.test.ts index c116a4cc77f..004103dd488 100644 --- a/src/lib/actions/inference-set-gateway-route-containment.test.ts +++ b/src/lib/actions/inference-set-gateway-route-containment.test.ts @@ -32,6 +32,25 @@ describe("runtime shared gateway route containment", () => { delete process.env[HTTPS_PIN_RUNTIME_ADAPTER_PROVIDER_CREDENTIAL_ENV]; }); + it("retains native Hermes metadata when switching models on the same provider", () => { + const metadata = { + endpointUrl: "https://integrate.api.nvidia.com/v1", + credentialEnv: "NVIDIA_INFERENCE_API_KEY", + preferredInferenceApi: "openai-completions", + }; + const baseline = entry("hermes-switch", { agent: "hermes", ...metadata }); + const prepared = prepareInferenceSetRoute({ + entry: baseline, + sandboxName: baseline.name, + provider: "nvidia-prod", + model: "nvidia/nemotron-3-super-120b-a12b", + customRoute: {}, + session: null, + sandboxes: [baseline], + }); + expect(prepared.preliminaryRegistryMetadata).toMatchObject(metadata); + }); + it("rejects an ambient gateway endpoint before OpenShell prep or state mutation", async () => { vi.stubEnv("OPENSHELL_GATEWAY_ENDPOINT", "https://other.example.test"); const deps = createDeps({ diff --git a/test/e2e/README.md b/test/e2e/README.md index f043e5f1043..b5aa7aa02fd 100644 --- a/test/e2e/README.md +++ b/test/e2e/README.md @@ -639,6 +639,12 @@ Changes to shared catalogue execution paths select every catalogue target. The `openclaw-inference-switch` target owns fresh custom-image route initialization. Its fixture contains only a different baked model and stale limits. The target requires onboarding to create the selected model without those limits, then preserves that native configuration through restart and rebuild. +The OpenClaw native NVIDIA and mock Anthropic switch variants start with an authenticated local OpenAI-compatible fixture. +The native NVIDIA destination uses the public endpoint and its public credential only after switching. +Route assertions use JSON fields so terminal column alignment does not affect the result. +Hermes native installation uses the public NVIDIA provider before its same-provider model switch. +The Hermes native switch derives its baseline model expectation from the environment passed to installation. +Its later proxy-resolution probe pairs the public NVIDIA credential with the public endpoint. Most entries use one ID for catalogue selection, evidence, and artifacts. Matrix-style targets use one target ID for evidence and artifacts, with separate catalogue IDs and shards for each concrete execution. diff --git a/test/e2e/live/hermes-inference-switch-helpers.ts b/test/e2e/live/hermes-inference-switch-helpers.ts index 608540e132e..8aa6d2c55b6 100644 --- a/test/e2e/live/hermes-inference-switch-helpers.ts +++ b/test/e2e/live/hermes-inference-switch-helpers.ts @@ -7,7 +7,10 @@ import type { AddressInfo } from "node:net"; import os from "node:os"; import path from "node:path"; -import { resolveAgentInferenceApi } from "../../../src/lib/inference/config.ts"; +import { + DEFAULT_CLOUD_MODEL, + resolveAgentInferenceApi, +} from "../../../src/lib/inference/config.ts"; import { NVIDIA_HOSTED_NATIVE_ENDPOINT } from "../../../src/lib/inference/native-nvidia/index.ts"; import { NATIVE_NVIDIA_AUTH_HEADER_SCRIPT } from "../../../src/lib/inference/native-nvidia/contract.ts"; import { execTimeout } from "../../helpers/timeouts.ts"; @@ -182,7 +185,12 @@ export function env(apiKey?: string, extra: NodeJS.ProcessEnv = {}): NodeJS.Proc NEMOCLAW_SANDBOX_NAME: SANDBOX_NAME, OPENSHELL_GATEWAY: openshellGatewayName(), }; - apiKey && Object.assign(out, { NVIDIA_INFERENCE_API_KEY: apiKey }); + apiKey && + Object.assign(out, { + NVIDIA_INFERENCE_API_KEY: apiKey, + NEMOCLAW_PROVIDER: "build", + NEMOCLAW_MODEL: process.env.NEMOCLAW_MODEL ?? DEFAULT_CLOUD_MODEL, + }); USE_COMPATIBLE_HOSTED && apiKey && Object.assign(out, { @@ -231,7 +239,10 @@ export async function prepareProxyResolutionRoute({ redactionValues: string[]; }): Promise<{ model: string; requestOffset: number }> { const endpoint = - mockBaseline?.baseUrl ?? process.env.NEMOCLAW_ENDPOINT_URL ?? DEFAULT_HOSTED_INFERENCE_BASE_URL; + mockBaseline?.baseUrl ?? + (USE_COMPATIBLE_HOSTED + ? (process.env.NEMOCLAW_ENDPOINT_URL ?? DEFAULT_HOSTED_INFERENCE_BASE_URL) + : NVIDIA_HOSTED_NATIVE_ENDPOINT); const model = mockBaseline ? PROXY_RESOLUTION_MODEL : SWITCH_MODEL; const requestOffset = mockBaseline?.requests().length ?? 0; @@ -755,8 +766,13 @@ export function expectedApiMode(): string | undefined { // POSIX ERE character classes; support tests pin the accepted scalar shapes. export const API_KEY_SHAPE_PATTERN = `^[[:space:]]*api_key:[[:space:]]*("sk-[^"[:space:]]+"|'sk-[^'[:space:]]+'|sk-[^"'[:space:]]+)[[:space:]]*$`; -export function apiKeyShapeCommand(): string[] { - return ["grep", "-Eq", API_KEY_SHAPE_PATTERN, "/sandbox/.hermes/config.yaml"]; +export function apiKeyShapeCommand(provider: string = SWITCH_PROVIDER): string[] { + const nativeReference = String.raw`\$\{NVIDIA_INFERENCE_API_KEY\}`; + const pattern = + provider === PUBLIC_NVIDIA_SWITCH_PROVIDER + ? `^[[:space:]]*api_key:[[:space:]]*("${nativeReference}"|'${nativeReference}'|${nativeReference})[[:space:]]*$` + : API_KEY_SHAPE_PATTERN; + return ["grep", "-Eq", pattern, "/sandbox/.hermes/config.yaml"]; } export async function apiKeyShape(sandbox: SandboxClient): Promise { diff --git a/test/e2e/live/hermes-inference-switch.test.ts b/test/e2e/live/hermes-inference-switch.test.ts index c017315f0ad..e113c4e7a6f 100644 --- a/test/e2e/live/hermes-inference-switch.test.ts +++ b/test/e2e/live/hermes-inference-switch.test.ts @@ -184,9 +184,11 @@ test( expect(baselineRoute.exitCode, resultText(baselineRoute)).toBe(0); expect(parseInferenceRoute(resultText(baselineRoute))).toEqual({ provider: mockBaseline ? "compatible-endpoint" : PUBLIC_NVIDIA_SWITCH_PROVIDER, - model: hostedInstallModel(installEnv), + model: hostedInstallModel(env(apiKey, installEnv)), }); - const baselineSession = structuredClone(registryState().session); + const baselineState = registryState(); + const baselineSession = structuredClone(baselineState.session); + const baselineRegistry = structuredClone(baselineState.registry.sandboxes?.[SANDBOX_NAME]); const switchBinding = await prepareCompatibleAnthropicSwitchBinding(host, cleanup); const switchEndpointUrl = switchBinding?.endpointUrl ?? null; switchBinding && redactionValues.push(switchBinding.credentialValue); @@ -338,12 +340,12 @@ test( expect(state.session).toEqual(baselineSession); const publicSwitch = SWITCH_PROVIDER === PUBLIC_NVIDIA_SWITCH_PROVIDER; const durableEndpointUrl = publicSwitch - ? null + ? baselineRegistry?.endpointUrl : (switchEndpointUrl ?? process.env.NEMOCLAW_ENDPOINT_URL ?? DEFAULT_HOSTED_INFERENCE_BASE_URL); const durableCredentialEnv = publicSwitch - ? null + ? baselineRegistry?.credentialEnv : switchEndpointUrl ? "COMPATIBLE_ANTHROPIC_API_KEY" : "COMPATIBLE_API_KEY"; @@ -352,7 +354,7 @@ test( ); expect(state.registry.sandboxes?.[SANDBOX_NAME]?.credentialEnv).toBe(durableCredentialEnv); expect(state.registry.sandboxes?.[SANDBOX_NAME]?.preferredInferenceApi).toBe( - publicSwitch ? null : RUNTIME_SWITCH_API, + publicSwitch ? baselineRegistry?.preferredInferenceApi : RUNTIME_SWITCH_API, ); expect(state.registry.sandboxes?.[SANDBOX_NAME]?.nimContainer).toBeNull(); progress.phase("exercise sandbox inference and Hermes API"); diff --git a/test/e2e/live/openclaw-inference-switch-helpers.ts b/test/e2e/live/openclaw-inference-switch-helpers.ts index c6b8f3f4a69..a8fd0acb24a 100644 --- a/test/e2e/live/openclaw-inference-switch-helpers.ts +++ b/test/e2e/live/openclaw-inference-switch-helpers.ts @@ -4,6 +4,10 @@ // Fixture and response helpers shared by the openclaw-inference-switch live // target and fast e2e-support tests without gating on NEMOCLAW_RUN_LIVE_E2E=1. +import type { HostCliClient } from "../fixtures/clients/host.ts"; +import type { SandboxClient } from "../fixtures/clients/sandbox.ts"; +import type { ShellProbeResult } from "../fixtures/shell-probe.ts"; +import { CLI_ENTRYPOINT } from "../fixtures/paths.ts"; import type { RetryFailureClass } from "../../../tools/e2e/retry-evidence.mts"; import { startFakeOpenAiCompatibleServer, @@ -188,3 +192,49 @@ export function mockBaselineInference(endpointUrl: string): BaselineInferenceCon }, }; } + +/** Read the structured route through the same host CLI used by the live scenario. */ +export async function getRouteOutput( + host: HostCliClient, + options: { env: NodeJS.ProcessEnv; timeoutMs: number }, +): Promise { + return host.command("node", [CLI_ENTRYPOINT, "inference", "get", "--json"], { + ...options, + artifactName: "nemoclaw-inference-get-after-switch", + }); +} + +/** Validate the native handle inside the sandbox before artifact redaction. */ +export async function readOpenClawConfig( + sandbox: SandboxClient, + sandboxName: string, + options: { + env: NodeJS.ProcessEnv; + timeoutMs: number; + artifactName: string; + nativeNvidia?: boolean; + }, +): Promise { + return sandbox.exec( + sandboxName, + options.nativeNvidia + ? [ + "node", + "-e", + [ + 'const fs = require("node:fs");', + 'const config = JSON.parse(fs.readFileSync("/sandbox/.openclaw/openclaw.json", "utf8"));', + "const provider = config.models?.providers?.inference;", + // A fresh exec receives the newly attached provider handle. Keep + // both values inside the sandbox because ShellProbe redacts the + // credential-shaped config field before returning stdout. + "const handle = process.env.NVIDIA_INFERENCE_API_KEY;", + 'require("node:assert/strict").ok(/^openshell:resolve:env:(?:v[0-9]{1,20}|s[a-f0-9]{64})_NVIDIA_INFERENCE_API_KEY$/.test(handle ?? "") && provider?.apiKey === handle, "native credential reference mismatch");', + "delete provider.apiKey;", + "process.stdout.write(JSON.stringify(config));", + ].join(" "), + ] + : ["cat", "/sandbox/.openclaw/openclaw.json"], + { artifactName: options.artifactName, env: options.env, timeoutMs: options.timeoutMs }, + ); +} diff --git a/test/e2e/live/openclaw-inference-switch.test.ts b/test/e2e/live/openclaw-inference-switch.test.ts index 9032a8de43f..bca85809f7a 100644 --- a/test/e2e/live/openclaw-inference-switch.test.ts +++ b/test/e2e/live/openclaw-inference-switch.test.ts @@ -51,6 +51,8 @@ import { approveOpenClawAdminScope } from "./openclaw-admin-scope.ts"; import { runBoundedRetry } from "../../../tools/e2e/retry-evidence.mts"; import type { ShellProbeResult } from "../fixtures/shell-probe.ts"; import { + getRouteOutput, + readOpenClawConfig, agentReplyContainsToken, anthropicToolCount, classifyExhaustedPostSwitchEvidence, @@ -530,13 +532,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", "--json"], { - artifactName: "nemoclaw-inference-get-after-switch", - timeoutMs: COMMAND_TIMEOUT_MS, - }); -} - async function assertRegistryAndSession( home: string, options: { mockProvider?: MockAnthropicProvider; sandbox: SandboxClient }, @@ -617,32 +612,12 @@ async function readAndAssertOpenClawConfig( nativeNvidia?: boolean; }, ): Promise { - const configResult = await sandbox.exec( - SANDBOX_NAME, - expected.nativeNvidia - ? [ - "node", - "-e", - [ - 'const fs = require("node:fs");', - 'const config = JSON.parse(fs.readFileSync("/sandbox/.openclaw/openclaw.json", "utf8"));', - "const provider = config.models?.providers?.inference;", - // A fresh exec receives the newly attached provider handle. Keep - // both values inside the sandbox because ShellProbe redacts the - // credential-shaped config field before returning stdout. - "const handle = process.env.NVIDIA_INFERENCE_API_KEY;", - 'require("node:assert/strict").ok(/^openshell:resolve:env:(?:v[0-9]{1,20}|s[a-f0-9]{64})_NVIDIA_INFERENCE_API_KEY$/.test(handle ?? "") && provider?.apiKey === handle, "native credential reference mismatch");', - "delete provider.apiKey;", - "process.stdout.write(JSON.stringify(config));", - ].join(" "), - ] - : ["cat", "/sandbox/.openclaw/openclaw.json"], - { - artifactName: expected.artifactName, - env: commandEnv(home), - timeoutMs: COMMAND_TIMEOUT_MS, - }, - ); + const configResult = await readOpenClawConfig(sandbox, SANDBOX_NAME, { + nativeNvidia: expected.nativeNvidia, + artifactName: expected.artifactName, + env: commandEnv(home), + timeoutMs: COMMAND_TIMEOUT_MS, + }); expect(configResult.exitCode, resultText(configResult)).toBe(0); const config = JSON.parse(configResult.stdout) as OpenClawConfig; const expectedProviderKey = @@ -1334,7 +1309,10 @@ test( } progress.phase("inspect route configuration and recorded state"); - const route = await getRouteOutput(host, home); + const route = await getRouteOutput(host, { + env: commandEnv(home), + timeoutMs: COMMAND_TIMEOUT_MS, + }); expect(route.exitCode, resultText(route)).toBe(0); const routeState = JSON.parse(route.stdout) as { provider?: unknown; model?: unknown }; expect(routeState.provider).toBe(SWITCH_PROVIDER); diff --git a/test/e2e/support/hermes-inference-switch-command-shape.test.ts b/test/e2e/support/hermes-inference-switch-command-shape.test.ts index 621a8ec39fb..5245e06fd63 100644 --- a/test/e2e/support/hermes-inference-switch-command-shape.test.ts +++ b/test/e2e/support/hermes-inference-switch-command-shape.test.ts @@ -43,6 +43,13 @@ import { describe("Hermes inference switch command shape", () => { afterEach(() => vi.unstubAllEnvs()); + async function nativeSwitchHelpers() { + vi.stubEnv("NEMOCLAW_E2E_USE_HOSTED_INFERENCE", "0"); + vi.stubEnv("NEMOCLAW_MODEL", undefined); + vi.resetModules(); + return import("../live/hermes-inference-switch-helpers.ts"); + } + function matchesApiKeyShape(line: string): boolean { return ( spawnSync("grep", ["-Eq", API_KEY_SHAPE_PATTERN], { @@ -156,12 +163,24 @@ describe("Hermes inference switch command shape", () => { }); it("uses direct single-line argv for the in-sandbox API-key probe", () => { - const command = apiKeyShapeCommand(); + const command = apiKeyShapeCommand("compatible-anthropic-endpoint"); expect(command).toEqual(["grep", "-Eq", API_KEY_SHAPE_PATTERN, "/sandbox/.hermes/config.yaml"]); expect(command.every((argument) => !/[\r\n]/u.test(argument))).toBe(true); }); + it("accepts only the native NVIDIA credential reference on the native route", () => { + const [command, ...args] = apiKeyShapeCommand(PUBLIC_NVIDIA_SWITCH_PROVIDER); + const matches = (input: string) => + spawnSync(command, args.slice(0, -1), { input, encoding: "utf8" }).status === 0; + expect(matches(" api_key: ${NVIDIA_INFERENCE_API_KEY}\n")).toBe(true); + expect(matches(' api_key: "${NVIDIA_INFERENCE_API_KEY}"\n')).toBe(true); + expect(matches(" api_key: '${NVIDIA_INFERENCE_API_KEY}'\n")).toBe(true); + expect(matches(" api_key: sk-OPENSHELL-PROXY-REWRITE\n")).toBe(false); + expect(matches(" api_key: nvapi-raw-fixture-key\n")).toBe(false); + expect(matches(" api_key: ${NVIDIA_INFERENCE_API_KEY} trailing\n")).toBe(false); + }); + it("accepts only complete sk-prefixed YAML scalars", () => { expect( [" api_key: sk-value", ' api_key: "sk-value"', " api_key: 'sk-value'"].every( @@ -190,6 +209,41 @@ describe("Hermes inference switch command shape", () => { ).toBe("initial-hosted-model"); }); + it("derives the native baseline model from the install environment", async () => { + const { env } = await nativeSwitchHelpers(); + const installEnv = env("nvapi-public-fixture-key"); + expect(hostedInstallModel(installEnv)).toBe("nvidia/nemotron-3-super-120b-a12b"); + }); + + it("keeps the public proxy-resolution credential on the public NVIDIA endpoint", async () => { + const { prepareProxyResolutionRoute } = await nativeSwitchHelpers(); + const command = vi.fn().mockResolvedValue({ + exitCode: 0, + stderr: "", + stdout: "Type: openai\nCredentials: NVIDIA_INFERENCE_API_KEY\nConfig: OPENAI_BASE_URL\n", + }); + await prepareProxyResolutionRoute({ + apiKey: "nvapi-public-fixture-key", + host: { command } as unknown as HostCliClient, + mockBaseline: undefined, + redactionValues: ["nvapi-public-fixture-key"], + }); + expect(command.mock.calls[0]).toEqual([ + "openshell", + expect.arrayContaining([ + "provider", + "create", + "--credential", + "NVIDIA_INFERENCE_API_KEY", + "OPENAI_BASE_URL=https://integrate.api.nvidia.com/v1", + ]), + expect.objectContaining({ + env: expect.objectContaining({ NVIDIA_INFERENCE_API_KEY: "nvapi-public-fixture-key" }), + redactionValues: ["nvapi-public-fixture-key"], + }), + ]); + }); + it("keeps proxy-resolution evidence on a dedicated OpenAI provider", async () => { const command = vi .fn() diff --git a/test/e2e/support/openclaw-inference-switch-helpers.test.ts b/test/e2e/support/openclaw-inference-switch-helpers.test.ts index 2cdf8e0f5e6..5abcc20b46c 100644 --- a/test/e2e/support/openclaw-inference-switch-helpers.test.ts +++ b/test/e2e/support/openclaw-inference-switch-helpers.test.ts @@ -1,11 +1,20 @@ // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // SPDX-License-Identifier: Apache-2.0 -import { describe, expect, it } from "vitest"; +import { afterEach, describe, expect, it, vi } from "vitest"; +import fs from "node:fs"; +import os from "node:os"; +import path from "node:path"; +import { execFileSync } from "node:child_process"; +import { redactString } from "../fixtures/redaction.ts"; +import { patchOpenClawInferenceConfig } from "../../../src/lib/actions/inference-set.ts"; +import type { HostCliClient } from "../fixtures/clients/host.ts"; import { startTestProgress } from "../fixtures/progress.ts"; import { + getRouteOutput, + readOpenClawConfig, agentReplyContainsToken, anthropicToolCount, classifyExhaustedPostSwitchEvidence, @@ -291,3 +300,158 @@ describe("openclaw-inference-switch mock-Anthropic baseline", () => { expect(baseline.env.NEMOCLAW_ENDPOINT_URL).toBe("http://10.0.0.5:9000/v1"); }); }); + +const disposables: Array<() => unknown> = []; +afterEach(async () => { + for (const dispose of disposables.splice(0).reverse()) await dispose(); + vi.restoreAllMocks(); + vi.unstubAllEnvs(); +}); + +it("requests structured route output instead of aligned terminal columns", async () => { + const command = vi.fn(async (_command: string, args: string[]) => ({ + exitCode: 0, + stderr: "", + stdout: args.includes("--json") + ? JSON.stringify({ provider: "compatible-anthropic-endpoint", model: "mock-anthropic-model" }) + : "Provider: compatible-anthropic-endpoint\nModel: mock-anthropic-model\n", + })); + const result = await getRouteOutput({ command } as unknown as HostCliClient, { + env: { HOME: "/tmp/switch-test-home" }, + timeoutMs: 1000, + }); + expect(JSON.parse(result.stdout)).toEqual({ + provider: "compatible-anthropic-endpoint", + model: "mock-anthropic-model", + }); +}); + +async function probeOpenClawConfig( + sandbox: Parameters[0], + home: string, + expected: { + model: string; + inferenceApi: string; + artifactName: string; + nativeNvidia?: boolean; + }, +) { + const result = await readOpenClawConfig(sandbox, "switch-test", { + artifactName: expected.artifactName, + env: { HOME: home }, + timeoutMs: 1000, + nativeNvidia: expected.nativeNvidia, + }); + expect(result.exitCode).toBe(0); + const config = JSON.parse(result.stdout); + const providerKey = expected.inferenceApi === "anthropic-messages" ? "anthropic" : "inference"; + const provider = config.models.providers[providerKey]; + expect(config.agents.defaults.model.primary).toBe(`${providerKey}/${expected.model}`); + expect(provider.api).toBe(expected.inferenceApi); + expect(provider.apiKey).toBe(expected.nativeNvidia ? undefined : "unused"); + const model = provider.models.find((entry: { id: string }) => entry.id === expected.model); + expect( + expected.inferenceApi === "anthropic-messages" + ? model.maxTokens > 0 + : model.maxTokens === undefined, + ).toBe(true); +} + +const scopedNativeHandle = "openshell:resolve:env:v1_NVIDIA_INFERENCE_API_KEY"; + +function sandboxForOpenClawConfig(config: object, handle = scopedNativeHandle) { + const directory = fs.mkdtempSync(path.join(os.tmpdir(), "switch-config-probe-")); + disposables.push(() => fs.rmSync(directory, { recursive: true, force: true })); + const configPath = path.join(directory, "openclaw.json"); + fs.writeFileSync(configPath, JSON.stringify(config)); + return { + exec: vi.fn(async (_sandboxName: string, argv: string[]) => ({ + exitCode: 0, + stdout: redactString( + execFileSync( + argv[0]!, + argv + .slice(1) + .map((arg) => arg.replaceAll("/sandbox/.openclaw/openclaw.json", configPath)), + { + encoding: "utf8", + env: { ...process.env, NVIDIA_INFERENCE_API_KEY: handle }, + stdio: ["pipe", "pipe", "pipe"], + }, + ), + ), + stderr: "", + })), + }; +} + +it("checks the actual switched native model budget with a materialized handle", async () => { + const model = "nvidia/nemotron-3-super-120b-a12b"; + const config: any = {}; + patchOpenClawInferenceConfig(config, "nvidia-prod", model, "openai-completions"); + config.models.providers.inference.apiKey = scopedNativeHandle; + await probeOpenClawConfig(sandboxForOpenClawConfig(config) as never, "/tmp/switch-home", { + model, + inferenceApi: "openai-completions", + artifactName: "switched-native-config", + nativeNvidia: true, + }); +}); + +it("checks the actual switched Anthropic model budget", async () => { + const model = "mock-anthropic-model"; + const config = {}; + patchOpenClawInferenceConfig( + config, + "compatible-anthropic-endpoint", + model, + "anthropic-messages", + ); + await probeOpenClawConfig(sandboxForOpenClawConfig(config) as never, "/tmp/switch-home", { + model, + inferenceApi: "anthropic-messages", + artifactName: "switched-anthropic-config", + }); +}); + +it.each([ + "unused", + "nvapi-fixture-secret", + "native", + "${OTHER_API_KEY}", + "${NVIDIA_INFERENCE_API_KEY}", + "openshell:resolve:env:v2_NVIDIA_INFERENCE_API_KEY", + "openshell:resolve:env:NVIDIA_INFERENCE_API_KEY", + null, +])("rejects an incorrect native OpenClaw credential value after redaction: %s", async (value) => { + const model = "nvidia/nemotron-3-super-120b-a12b"; + const config: any = {}; + patchOpenClawInferenceConfig(config, "nvidia-prod", model, "openai-completions"); + config.models.providers.inference.apiKey = value; + await expect( + probeOpenClawConfig(sandboxForOpenClawConfig(config) as never, "/tmp/switch-home", { + model, + inferenceApi: "openai-completions", + artifactName: "invalid-native-credential", + nativeNvidia: true, + }), + ).rejects.toThrow(); +}); + +it.each(["", "nvapi-fixture-secret", "openshell:resolve:env:NVIDIA_INFERENCE_API_KEY"])( + "rejects a missing or unscoped native handle even when config matches: %s", + async (handle) => { + const model = "nvidia/nemotron-3-super-120b-a12b"; + const config: any = {}; + patchOpenClawInferenceConfig(config, "nvidia-prod", model, "openai-completions"); + config.models.providers.inference.apiKey = handle; + await expect( + probeOpenClawConfig(sandboxForOpenClawConfig(config, handle) as never, "/tmp/switch-home", { + model, + inferenceApi: "openai-completions", + artifactName: "invalid-native-handle", + nativeNvidia: true, + }), + ).rejects.toThrow(); + }, +);