Repository navigation
fix(e2e): support compatible credential migration #5380
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| const COMPATIBLE_INFERENCE_FLAG = "NEMOCLAW_E2E_USE_NVIDIA_SECRET_AS_COMPATIBLE"; | ||
| const DEFAULT_COMPATIBLE_BASE_URL = "https://inference-api.nvidia.com/v1"; | ||
| const DEFAULT_COMPATIBLE_MODEL = "nvidia/nvidia/nemotron-3-super-v3"; | ||
|
|
||
| export interface HostedInferenceSecrets { | ||
| optional(name: string): string | undefined; | ||
| required(name: string): string; | ||
| } | ||
|
|
||
| export interface HostedInferenceOptions { | ||
| nvidiaSecretName?: "NVIDIA_INFERENCE_API_KEY" | "NVIDIA_API_KEY"; | ||
| nvidiaModel?: string; | ||
| } | ||
|
|
||
| export interface HostedInferenceConfig { | ||
| apiKey: string; | ||
| credentialEnv: "NVIDIA_INFERENCE_API_KEY" | "NVIDIA_API_KEY" | "COMPATIBLE_API_KEY"; | ||
| provider: "nvidia" | "compatible"; | ||
| providerName: "nvidia-prod" | "compatible-endpoint"; | ||
| env: NodeJS.ProcessEnv; | ||
| model: string; | ||
| endpointUrl: string; | ||
| contractLabel: string; | ||
| } | ||
|
|
||
| export function usingCiCompatibleInference(env: NodeJS.ProcessEnv = process.env): boolean { | ||
| return env[COMPATIBLE_INFERENCE_FLAG] === "1"; | ||
| } | ||
|
|
||
| export function requireHostedInferenceConfig( | ||
| secrets: HostedInferenceSecrets, | ||
| env: NodeJS.ProcessEnv = process.env, | ||
| options: HostedInferenceOptions = {}, | ||
| ): HostedInferenceConfig { | ||
| const nvidiaSecretName = options.nvidiaSecretName ?? "NVIDIA_INFERENCE_API_KEY"; | ||
|
|
||
| if (usingCiCompatibleInference(env)) { | ||
| const apiKey = | ||
| secrets.optional("COMPATIBLE_API_KEY") ?? | ||
| secrets.optional("NVIDIA_INFERENCE_API_KEY") ?? | ||
| secrets.required(nvidiaSecretName); | ||
| const endpointUrl = env.NEMOCLAW_ENDPOINT_URL || DEFAULT_COMPATIBLE_BASE_URL; | ||
| const model = env.NEMOCLAW_MODEL || env.NEMOCLAW_COMPAT_MODEL || DEFAULT_COMPATIBLE_MODEL; | ||
| return { | ||
| apiKey, | ||
| credentialEnv: "COMPATIBLE_API_KEY", | ||
| provider: "compatible", | ||
| providerName: "compatible-endpoint", | ||
| endpointUrl, | ||
| model, | ||
| env: { | ||
| NEMOCLAW_PROVIDER: "custom", | ||
| NEMOCLAW_ENDPOINT_URL: endpointUrl, | ||
| NEMOCLAW_MODEL: model, | ||
| NEMOCLAW_COMPAT_MODEL: model, | ||
| COMPATIBLE_API_KEY: apiKey, | ||
| }, | ||
| contractLabel: "CI compatible inference credential is present", | ||
| }; | ||
| } | ||
|
|
||
| const apiKey = secrets.required(nvidiaSecretName); | ||
| if (!apiKey.startsWith("nvapi-")) { | ||
| throw new Error( | ||
| `${nvidiaSecretName} must start with nvapi- unless ${COMPATIBLE_INFERENCE_FLAG}=1 is set`, | ||
| ); | ||
| } | ||
|
|
||
| const model = options.nvidiaModel ?? env.NEMOCLAW_MODEL ?? ""; | ||
| return { | ||
| apiKey, | ||
| credentialEnv: nvidiaSecretName, | ||
| provider: "nvidia", | ||
| providerName: "nvidia-prod", | ||
| endpointUrl: DEFAULT_COMPATIBLE_BASE_URL, | ||
| model, | ||
| env: { | ||
| [nvidiaSecretName]: apiKey, | ||
| ...(model ? { NEMOCLAW_MODEL: model } : {}), | ||
| }, | ||
| contractLabel: `${nvidiaSecretName} is present and nvapi-prefixed`, | ||
| }; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import { describe, expect, it } from "vitest"; | ||
|
|
||
| import { | ||
| requireHostedInferenceConfig, | ||
| usingCiCompatibleInference, | ||
| } from "../fixtures/hosted-inference.ts"; | ||
|
|
||
| function secrets(values: Record<string, string | undefined>) { | ||
| return { | ||
| optional: (name: string) => values[name], | ||
| required: (name: string) => { | ||
| const value = values[name]; | ||
| if (!value) throw new Error(`missing ${name}`); | ||
| return value; | ||
| }, | ||
| }; | ||
| } | ||
|
|
||
| describe("hosted inference E2E config", () => { | ||
| it("requires an nvapi-prefixed NVIDIA key by default", () => { | ||
| const cfg = requireHostedInferenceConfig( | ||
| secrets({ NVIDIA_INFERENCE_API_KEY: "nvapi-test-key" }), | ||
| {}, | ||
| ); | ||
|
|
||
| expect(cfg.provider).toBe("nvidia"); | ||
| expect(cfg.credentialEnv).toBe("NVIDIA_INFERENCE_API_KEY"); | ||
| expect(cfg.env.NVIDIA_INFERENCE_API_KEY).toBe("nvapi-test-key"); | ||
| }); | ||
|
|
||
| it("rejects a non-NVIDIA key unless the compatible-provider flag is set", () => { | ||
| expect(() => | ||
| requireHostedInferenceConfig(secrets({ NVIDIA_INFERENCE_API_KEY: "sk-compatible-key" }), {}), | ||
| ).toThrow(/must start with nvapi-/); | ||
| }); | ||
|
|
||
| it("accepts a compatible-provider credential when CI enables the compatibility flag", () => { | ||
| const cfg = requireHostedInferenceConfig( | ||
| secrets({ | ||
| COMPATIBLE_API_KEY: "sk-compatible-key", | ||
| NVIDIA_INFERENCE_API_KEY: "sk-compatible-key", | ||
| }), | ||
| { NEMOCLAW_E2E_USE_NVIDIA_SECRET_AS_COMPATIBLE: "1" }, | ||
| ); | ||
|
|
||
| expect(cfg.provider).toBe("compatible"); | ||
| expect(cfg.credentialEnv).toBe("COMPATIBLE_API_KEY"); | ||
| expect(cfg.env).toMatchObject({ | ||
| NEMOCLAW_PROVIDER: "custom", | ||
| NEMOCLAW_ENDPOINT_URL: "https://inference-api.nvidia.com/v1", | ||
| NEMOCLAW_MODEL: "nvidia/nvidia/nemotron-3-super-v3", | ||
| COMPATIBLE_API_KEY: "sk-compatible-key", | ||
| }); | ||
| }); | ||
|
|
||
| it("falls back to the configured NVIDIA secret name for reusable workflow compatibility", () => { | ||
| const cfg = requireHostedInferenceConfig( | ||
| secrets({ NVIDIA_API_KEY: "provider-key" }), | ||
| { NEMOCLAW_E2E_USE_NVIDIA_SECRET_AS_COMPATIBLE: "1" }, | ||
| { nvidiaSecretName: "NVIDIA_API_KEY" }, | ||
| ); | ||
|
|
||
| expect(cfg.provider).toBe("compatible"); | ||
| expect(cfg.apiKey).toBe("provider-key"); | ||
| expect(usingCiCompatibleInference({ NEMOCLAW_E2E_USE_NVIDIA_SECRET_AS_COMPATIBLE: "1" })).toBe( | ||
| true, | ||
| ); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.