-
Notifications
You must be signed in to change notification settings - Fork 3.1k
refactor(cli): extract model prompt helpers from onboard.js #1515
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 all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7bc63a4
refactor(cli): extract HTTP probe helpers from onboard.js
cv 6e47348
refactor(cli): extract validation recovery helpers from onboard.js
cv f0072e4
refactor(cli): extract provider model helpers from onboard.js
cv 94b9430
refactor(cli): extract model prompt helpers from onboard.js
cv acafdcc
merge: bring main into model-prompts branch
cv 07f1f70
fix(cli): defer transient model validation failures
cv 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import { describe, expect, it, vi } from "vitest"; | ||
|
|
||
| import { | ||
| BACK_TO_SELECTION, | ||
| promptCloudModel, | ||
| promptInputModel, | ||
| promptManualModelId, | ||
| promptRemoteModel, | ||
| } from "./model-prompts"; | ||
|
|
||
| function promptSequence(responses: string[]) { | ||
| const queue = [...responses]; | ||
| return vi.fn(async () => queue.shift() ?? ""); | ||
| } | ||
|
|
||
| describe("model prompt helpers", () => { | ||
| it("returns the selected cloud model from the curated list", async () => { | ||
| const promptFn = promptSequence(["2"]); | ||
| const result = await promptCloudModel({ | ||
| promptFn, | ||
| writeLine: vi.fn(), | ||
| cloudModelOptions: [ | ||
| { id: "nemotron", label: "Nemotron" }, | ||
| { id: "llama", label: "Llama" }, | ||
| ], | ||
| }); | ||
|
|
||
| expect(result).toBe("llama"); | ||
| }); | ||
|
|
||
| it("validates manual cloud model ids against the saved NVIDIA key", async () => { | ||
| const promptFn = promptSequence(["9", "bad-model", "nemotron-custom"]); | ||
| const errorLine = vi.fn(); | ||
| const result = await promptCloudModel({ | ||
| promptFn, | ||
| errorLine, | ||
| writeLine: vi.fn(), | ||
| cloudModelOptions: [{ id: "nemotron", label: "Nemotron" }], | ||
| getCredentialFn: () => "nvapi-test", | ||
| validateNvidiaEndpointModelFn: (model) => ({ | ||
| ok: model === "nemotron-custom", | ||
| message: `Model '${model}' is not available from NVIDIA Endpoints. Checked https://integrate.api.nvidia.com/v1/models.`, | ||
| }), | ||
| }); | ||
|
|
||
| expect(result).toBe("nemotron-custom"); | ||
| expect(errorLine).toHaveBeenCalledWith( | ||
| " Model 'bad-model' is not available from NVIDIA Endpoints. Checked https://integrate.api.nvidia.com/v1/models.", | ||
| ); | ||
| }); | ||
|
|
||
| it("returns back-to-selection with a clear message when the NVIDIA key is missing", async () => { | ||
| const errorLine = vi.fn(); | ||
| const result = await promptCloudModel({ | ||
| promptFn: promptSequence(["abc"]), | ||
| errorLine, | ||
| writeLine: vi.fn(), | ||
| cloudModelOptions: [{ id: "nemotron", label: "Nemotron" }], | ||
| getCredentialFn: () => null, | ||
| }); | ||
|
|
||
| expect(result).toBe(BACK_TO_SELECTION); | ||
| expect(errorLine).toHaveBeenCalledWith( | ||
| " NVIDIA_API_KEY is required before validating a custom NVIDIA Endpoints model.", | ||
| ); | ||
| }); | ||
|
|
||
| it("defers transient manual validation failures back to the caller flow", async () => { | ||
| const errorLine = vi.fn(); | ||
| const result = await promptManualModelId( | ||
| " Model: ", | ||
| "Provider", | ||
| () => ({ ok: false, message: "Could not validate model against /models: timeout" }), | ||
| { promptFn: promptSequence(["custom-model"]), errorLine }, | ||
| ); | ||
|
|
||
| expect(result).toBe("custom-model"); | ||
| expect(errorLine).toHaveBeenCalledWith( | ||
| " Could not validate model against /models: timeout", | ||
| ); | ||
| }); | ||
|
|
||
| it("returns back-to-selection for manual ids and input prompts", async () => { | ||
| await expect( | ||
| promptManualModelId(" Model: ", "Provider", null, { promptFn: promptSequence(["back"]) }), | ||
| ).resolves.toBe(BACK_TO_SELECTION); | ||
| await expect( | ||
| promptInputModel("Provider", "default-model", null, { promptFn: promptSequence(["back"]) }), | ||
| ).resolves.toBe(BACK_TO_SELECTION); | ||
| }); | ||
|
|
||
| it("uses the default remote model choice when the user presses enter", async () => { | ||
| const result = await promptRemoteModel("OpenAI", "openai", "gpt-5.4-mini", null, { | ||
| promptFn: promptSequence([""]), | ||
| writeLine: vi.fn(), | ||
| }); | ||
|
|
||
| expect(result).toBe("gpt-5.4-mini"); | ||
| }); | ||
|
|
||
| it("treats non-numeric curated selections as manual-entry fallback", async () => { | ||
| const result = await promptRemoteModel("OpenAI", "openai", "gpt-5.4-mini", null, { | ||
| promptFn: promptSequence(["abc", "custom-model"]), | ||
| writeLine: vi.fn(), | ||
| }); | ||
|
|
||
| expect(result).toBe("custom-model"); | ||
| }); | ||
|
|
||
| it("retries invalid input models until validation succeeds", async () => { | ||
| const promptFn = promptSequence(["bad model", "other", "candidate"]); | ||
| const errorLine = vi.fn(); | ||
| const result = await promptInputModel( | ||
| "Custom", | ||
| "default-model", | ||
| (model) => ({ ok: model === "candidate", message: "try again" }), | ||
| { promptFn, errorLine }, | ||
| ); | ||
|
|
||
| expect(result).toBe("candidate"); | ||
| expect(errorLine).toHaveBeenCalledWith(" Invalid Custom model id."); | ||
| expect(errorLine).toHaveBeenCalledWith(" try again"); | ||
| }); | ||
|
|
||
| it("returns input models immediately when validation should be deferred", async () => { | ||
| const errorLine = vi.fn(); | ||
| const result = await promptInputModel( | ||
| "Custom", | ||
| "default-model", | ||
| () => ({ ok: false, message: "Could not validate model against /models: auth failed" }), | ||
| { promptFn: promptSequence(["candidate"]), errorLine }, | ||
| ); | ||
|
|
||
| expect(result).toBe("candidate"); | ||
| expect(errorLine).toHaveBeenCalledWith( | ||
| " Could not validate model against /models: auth failed", | ||
| ); | ||
| }); | ||
| }); |
Oops, something went wrong.
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.