-
Notifications
You must be signed in to change notification settings - Fork 220
refactor(cli): canonicalize provider identifiers #1110
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
edelauna
merged 5 commits into
Zoo-Code-Org:main
from
WebMad:refactor/944-cli-provider-identifiers
Aug 7, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9819602
refactor(types): canonicalize provider settings identifiers
WebMad 721d2c8
refactor(cli): canonicalize provider identifiers
WebMad 52e2322
refactor(cli): extract option resolution helpers
WebMad 3e89aba
test(cli): cover run option resolution
WebMad 6476237
fix(cli): resolve specialized provider model IDs
WebMad 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 |
|---|---|---|
|
|
@@ -2,6 +2,152 @@ import fs from "fs" | |
| import path from "path" | ||
| import os from "os" | ||
|
|
||
| import { providerIdentifiers } from "@roo-code/types" | ||
| import { DEFAULT_FLAGS, FlagOptions } from "@/types/index.js" | ||
| import { | ||
| resolveLegacyRequireApproval, | ||
| resolveModel, | ||
| resolveProvider, | ||
| resolveReasoningEffort, | ||
| resolveWorkspacePath, | ||
| run, | ||
| } from "../run.js" | ||
|
|
||
| const runCommandMocks = vi.hoisted(() => ({ | ||
| activate: vi.fn(async () => undefined), | ||
| dispose: vi.fn(async () => undefined), | ||
| loadSettings: vi.fn(), | ||
| options: [] as unknown[], | ||
| runTask: vi.fn(async () => undefined), | ||
| })) | ||
|
|
||
| vi.mock("@/lib/storage/index.js", () => ({ | ||
| loadSettings: runCommandMocks.loadSettings, | ||
| })) | ||
|
|
||
| vi.mock("@/agent/index.js", () => ({ | ||
| ExtensionHost: class { | ||
| client = {} | ||
|
|
||
| constructor(options: unknown) { | ||
| runCommandMocks.options.push(options) | ||
| } | ||
|
|
||
| activate = runCommandMocks.activate | ||
| dispose = runCommandMocks.dispose | ||
| runTask = runCommandMocks.runTask | ||
| }, | ||
| })) | ||
|
|
||
| describe("resolveModel", () => { | ||
| it("uses the CLI flag before the settings model", () => { | ||
| expect(resolveModel("flag-model", "settings-model")).toBe("flag-model") | ||
| }) | ||
|
|
||
| it("uses the settings model when the CLI flag is absent", () => { | ||
| expect(resolveModel(undefined, "settings-model")).toBe("settings-model") | ||
| }) | ||
|
|
||
| it("uses the default model when neither the CLI flag nor settings provide one", () => { | ||
| expect(resolveModel()).toBe(DEFAULT_FLAGS.model) | ||
| }) | ||
| }) | ||
|
|
||
| describe("resolveReasoningEffort", () => { | ||
| it("uses CLI, settings, and default values in priority order", () => { | ||
| expect(resolveReasoningEffort("high", "low")).toBe("high") | ||
| expect(resolveReasoningEffort(undefined, "low")).toBe("low") | ||
| expect(resolveReasoningEffort()).toBe(DEFAULT_FLAGS.reasoningEffort) | ||
| }) | ||
| }) | ||
|
|
||
| describe("resolveProvider", () => { | ||
| it("uses CLI, settings, and openrouter values in priority order", () => { | ||
| expect(resolveProvider(providerIdentifiers.anthropic, providerIdentifiers.gemini)).toBe( | ||
| providerIdentifiers.anthropic, | ||
| ) | ||
| expect(resolveProvider(undefined, providerIdentifiers.gemini)).toBe(providerIdentifiers.gemini) | ||
| expect(resolveProvider()).toBe(providerIdentifiers.openrouter) | ||
| }) | ||
| }) | ||
|
|
||
| describe("resolveWorkspacePath", () => { | ||
| it("resolves the provided workspace path", () => { | ||
| expect(resolveWorkspacePath("relative/workspace")).toBe(path.resolve("relative/workspace")) | ||
| }) | ||
|
|
||
| it("uses the current working directory when workspace is absent", () => { | ||
| expect(resolveWorkspacePath()).toBe(process.cwd()) | ||
| }) | ||
| }) | ||
|
|
||
| describe("resolveLegacyRequireApproval", () => { | ||
| it.each([ | ||
| { requireApproval: true, dangerouslySkipPermissions: true, expected: true }, | ||
| { requireApproval: false, dangerouslySkipPermissions: false, expected: false }, | ||
| { requireApproval: undefined, dangerouslySkipPermissions: false, expected: true }, | ||
| { requireApproval: undefined, dangerouslySkipPermissions: true, expected: false }, | ||
| { requireApproval: undefined, dangerouslySkipPermissions: undefined, expected: undefined }, | ||
| ])( | ||
| "resolves requireApproval=$requireApproval and dangerouslySkipPermissions=$dangerouslySkipPermissions", | ||
| ({ requireApproval, dangerouslySkipPermissions, expected }) => { | ||
| expect(resolveLegacyRequireApproval(requireApproval, dangerouslySkipPermissions)).toBe(expected) | ||
| }, | ||
| ) | ||
| }) | ||
|
|
||
| describe("run command option resolution", () => { | ||
| let workspacePath: string | ||
|
|
||
| beforeEach(() => { | ||
| vi.clearAllMocks() | ||
| runCommandMocks.options.length = 0 | ||
| workspacePath = fs.mkdtempSync(path.join(os.tmpdir(), "roo-run-test-")) | ||
| }) | ||
|
|
||
| afterEach(() => { | ||
| fs.rmSync(workspacePath, { recursive: true, force: true }) | ||
| vi.restoreAllMocks() | ||
| }) | ||
|
|
||
| it("passes resolved settings and workspace values to the extension host", async () => { | ||
| runCommandMocks.loadSettings.mockResolvedValue({ | ||
| model: "settings-model", | ||
| reasoningEffort: "high", | ||
| provider: providerIdentifiers.anthropic, | ||
| dangerouslySkipPermissions: false, | ||
| }) | ||
| const exitSpy = vi.spyOn(process, "exit").mockImplementation(() => undefined as never) | ||
| const flags: FlagOptions = { | ||
| continue: false, | ||
| workspace: path.relative(process.cwd(), workspacePath), | ||
| print: true, | ||
| stdinPromptStream: false, | ||
| signalOnlyExit: false, | ||
| debug: false, | ||
| requireApproval: false, | ||
| exitOnError: false, | ||
| apiKey: "test-api-key", | ||
| ephemeral: true, | ||
| oneshot: false, | ||
| } | ||
|
|
||
| await run("test prompt", flags) | ||
|
|
||
| expect(runCommandMocks.options).toEqual([ | ||
| expect.objectContaining({ | ||
| model: "settings-model", | ||
| reasoningEffort: "high", | ||
| provider: providerIdentifiers.anthropic, | ||
| workspacePath, | ||
| nonInteractive: false, | ||
| }), | ||
| ]) | ||
| expect(runCommandMocks.runTask).toHaveBeenCalledWith("test prompt", undefined) | ||
| expect(exitSpy).toHaveBeenCalledWith(0) | ||
| }) | ||
| }) | ||
|
|
||
| describe("run command --prompt-file option", () => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These tests exercise |
||
| let tempDir: string | ||
| let promptFilePath: string | ||
|
|
||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This covers the
settings win when no flag is setpath forprovider. What about theflag overrides settingspath? With the current fixture (flagshas noproviderkey), transposing the arguments inresolveProvider(flagOptions.provider, settings.provider)at run.ts:156 would produce the same result.