-
Notifications
You must be signed in to change notification settings - Fork 4.6k
fix: expand AUTODETECT for tabAutocompleteModel in JSON config path #12504
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
Open
riyonp23
wants to merge
1
commit into
continuedev:main
Choose a base branch
from
riyonp23:fix/autodetect-model-fallback
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+271
−7
Open
Changes from all commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,204 @@ | ||
| import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest"; | ||
|
|
||
| import { Config, IDE, IdeInfo, IdeSettings, ILLMLogger } from ".."; | ||
| import { BaseLLM } from "../llm"; | ||
|
|
||
| import { intermediateToFinalConfig } from "./load"; | ||
|
|
||
| vi.mock("../llm", () => ({ | ||
| BaseLLM: class {}, | ||
| })); | ||
|
|
||
| vi.mock("../llm/llms", () => ({ | ||
| LLMClasses: [], | ||
| llmFromDescription: vi.fn(), | ||
| })); | ||
|
|
||
| vi.mock("../llm/llms/CustomLLM", () => ({ | ||
| default: class { | ||
| constructor(public _opts: any) {} | ||
| }, | ||
| })); | ||
|
|
||
| vi.mock("../llm/llms/llm", () => ({ | ||
| LLMReranker: class { | ||
| constructor(public _llm: any) {} | ||
| }, | ||
| })); | ||
|
|
||
| vi.mock("../llm/llms/TransformersJsEmbeddingsProvider", () => ({ | ||
| default: class { | ||
| providerName = "transformers.js"; | ||
| }, | ||
| })); | ||
|
|
||
| // Avoid pulling in @continuedev/fetch (CJS follow-redirects) via the legacy | ||
| // slash-command barrel — we don't exercise slash commands in these tests. | ||
| vi.mock("../commands/slash/built-in-legacy", () => ({ | ||
| getLegacyBuiltInSlashCommandFromDescription: vi.fn(() => undefined), | ||
| })); | ||
|
|
||
| // Avoid pulling in @continuedev/terminal-security (CJS shell-quote) via the | ||
| // tools barrel — we don't exercise tool definitions in these tests. | ||
| vi.mock("../tools", () => ({ | ||
| getBaseToolDefinitions: () => [], | ||
| serializeTool: (t: any) => t, | ||
| })); | ||
|
|
||
| vi.mock("../context/mcp/json/loadJsonMcpConfigs", () => ({ | ||
| loadJsonMcpConfigs: vi.fn().mockResolvedValue({ errors: [], mcpServers: [] }), | ||
| })); | ||
|
|
||
| vi.mock("./loadContextProviders", () => ({ | ||
| loadConfigContextProviders: vi.fn().mockReturnValue({ | ||
| providers: [], | ||
| errors: [], | ||
| }), | ||
| })); | ||
|
|
||
| let llmFromDescriptionMock: ReturnType<typeof vi.fn>; | ||
|
|
||
| beforeAll(async () => { | ||
| const { llmFromDescription } = await import("../llm/llms"); | ||
| llmFromDescriptionMock = llmFromDescription as ReturnType<typeof vi.fn>; | ||
| }); | ||
|
|
||
| function makeFakeLlm(overrides: Partial<BaseLLM> & { model: string }): BaseLLM { | ||
| return { | ||
| model: overrides.model, | ||
| title: overrides.title ?? overrides.model, | ||
| providerName: overrides.providerName ?? "openai", | ||
| listModels: overrides.listModels ?? (async () => []), | ||
| isFromAutoDetect: overrides.isFromAutoDetect ?? false, | ||
| } as unknown as BaseLLM; | ||
| } | ||
|
|
||
| function makeArgs(config: Partial<Config>) { | ||
| const ide: IDE = { | ||
| getWorkspaceDirs: async () => [], | ||
| readFile: async () => "", | ||
| getIdeSettings: async () => ({}) as IdeSettings, | ||
| showToast: async () => undefined, | ||
| } as unknown as IDE; | ||
|
|
||
| const baseConfig: Config = { | ||
| models: [], | ||
| ...config, | ||
| } as unknown as Config; | ||
|
|
||
| return { | ||
| config: baseConfig, | ||
| ide, | ||
| ideSettings: {} as IdeSettings, | ||
| ideInfo: { ideType: "jetbrains" } as IdeInfo, | ||
| uniqueId: "test-unique-id", | ||
| llmLogger: { log: vi.fn() } as unknown as ILLMLogger, | ||
| workOsAccessToken: undefined, | ||
| loadPromptFiles: false, | ||
| }; | ||
| } | ||
|
|
||
| describe("intermediateToFinalConfig — tabAutocompleteModel AUTODETECT expansion", () => { | ||
| beforeEach(() => { | ||
| llmFromDescriptionMock.mockReset(); | ||
| }); | ||
|
|
||
| it("expands an AUTODETECT tabAutocompleteModel into the provider's real model list (regression for #12400)", async () => { | ||
| llmFromDescriptionMock.mockImplementation(async (desc: any) => { | ||
| if (desc.model === "AUTODETECT") { | ||
| return makeFakeLlm({ | ||
| model: "AUTODETECT", | ||
| providerName: "openai", | ||
| listModels: async () => ["model-a", "model-b"], | ||
| }); | ||
| } | ||
| return makeFakeLlm({ | ||
| model: desc.model, | ||
| title: desc.title ?? desc.model, | ||
| providerName: "openai", | ||
| isFromAutoDetect: desc.isFromAutoDetect, | ||
| }); | ||
| }); | ||
|
|
||
| const { config: result } = await intermediateToFinalConfig( | ||
| makeArgs({ | ||
| tabAutocompleteModel: { | ||
| title: "auto", | ||
| provider: "openai", | ||
| model: "AUTODETECT", | ||
| apiBase: "https://example.invalid/v1", | ||
| } as any, | ||
| }), | ||
| ); | ||
|
|
||
| const autocomplete = result.modelsByRole.autocomplete; | ||
| expect(autocomplete).toHaveLength(2); | ||
| expect(autocomplete.every((m) => m.model !== "AUTODETECT")).toBe(true); | ||
| expect(autocomplete.map((m) => m.model).sort()).toEqual([ | ||
| "model-a", | ||
| "model-b", | ||
| ]); | ||
| expect(autocomplete.every((m) => m.isFromAutoDetect === true)).toBe(true); | ||
| }); | ||
|
|
||
| it("uses the configured model unchanged when it is not AUTODETECT", async () => { | ||
| llmFromDescriptionMock.mockImplementation(async (desc: any) => | ||
| makeFakeLlm({ | ||
| model: desc.model, | ||
| title: desc.title ?? desc.model, | ||
| providerName: "openai", | ||
| }), | ||
| ); | ||
|
|
||
| const { config: result } = await intermediateToFinalConfig( | ||
| makeArgs({ | ||
| tabAutocompleteModel: { | ||
| title: "auto", | ||
| provider: "openai", | ||
| model: "qwen-7b", | ||
| apiBase: "https://example.invalid/v1", | ||
| } as any, | ||
| }), | ||
| ); | ||
|
|
||
| const autocomplete = result.modelsByRole.autocomplete; | ||
| expect(autocomplete).toHaveLength(1); | ||
| expect(autocomplete[0].model).toBe("qwen-7b"); | ||
| }); | ||
|
|
||
| it("drops the AUTODETECT placeholder when listModels() rejects (does not leak it into autocomplete)", async () => { | ||
| llmFromDescriptionMock.mockImplementation(async (desc: any) => { | ||
| if (desc.model === "AUTODETECT") { | ||
| return makeFakeLlm({ | ||
| model: "AUTODETECT", | ||
| providerName: "openai", | ||
| listModels: async () => { | ||
| throw new Error("listModels failed"); | ||
| }, | ||
| }); | ||
| } | ||
| return makeFakeLlm({ | ||
| model: desc.model, | ||
| title: desc.title ?? desc.model, | ||
| providerName: "openai", | ||
| }); | ||
| }); | ||
|
|
||
| const warnSpy = vi.spyOn(console, "warn").mockImplementation(() => {}); | ||
|
|
||
| const { config: result } = await intermediateToFinalConfig( | ||
| makeArgs({ | ||
| tabAutocompleteModel: { | ||
| title: "auto", | ||
| provider: "openai", | ||
| model: "AUTODETECT", | ||
| apiBase: "https://example.invalid/v1", | ||
| } as any, | ||
| }), | ||
| ); | ||
|
|
||
| expect(result.modelsByRole.autocomplete).toHaveLength(0); | ||
| expect(warnSpy).toHaveBeenCalled(); | ||
| warnSpy.mockRestore(); | ||
| }); | ||
| }); |
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.
P2: AUTODETECT expansion logic is duplicated from the earlier
config.modelsloop, and drift already exists between the two copies (e.g., the pre-existing CustomLLMClass shadowing bug inconfig.modelsis avoided here, but other behavioral differences like free-trial inline filtering remain). Extract a shared helper to prevent future regressions.Prompt for AI agents