-
Notifications
You must be signed in to change notification settings - Fork 3.8k
fix: multiple cn nitpicks #8049
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 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
95e8460
fix: refresh ui on model change
sestinj 2089f47
feat: handle cmd+backspace as only single line
sestinj 5140ebe
fix: model selection persistence
sestinj 4b77d0d
fx: test
sestinj ad14fcc
fix: tests
sestinj a2deb42
fix: tests
sestinj 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
205 changes: 205 additions & 0 deletions
205
extensions/cli/src/integration/model-persistence-e2e.test.ts
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,205 @@ | ||
| import * as fs from "fs"; | ||
| import * as os from "os"; | ||
| import * as path from "path"; | ||
|
|
||
| import { AssistantUnrolled, ModelConfig } from "@continuedev/config-yaml"; | ||
| import { afterEach, beforeEach, describe, expect, test, vi } from "vitest"; | ||
|
|
||
| import { | ||
| AuthenticatedConfig, | ||
| getModelName, | ||
| loadAuthConfig, | ||
| saveAuthConfig, | ||
| updateModelName, | ||
| } from "../auth/workos.js"; | ||
| import { persistModelName } from "../util/modelPersistence.js"; | ||
| import * as config from "../config.js"; | ||
| import { ModelService } from "../services/ModelService.js"; | ||
|
|
||
| // Mock the config module | ||
| vi.mock("../config.js"); | ||
|
|
||
| describe("Model Persistence End-to-End", () => { | ||
| let testDir: string; | ||
| let originalContinueHome: string | undefined; | ||
| let mockAssistant: AssistantUnrolled; | ||
| let mockAuthConfig: AuthenticatedConfig; | ||
| const mockLlmApi = { complete: vi.fn(), stream: vi.fn() }; | ||
|
|
||
| beforeEach(() => { | ||
| vi.clearAllMocks(); | ||
|
|
||
| // Create a temporary directory for testing | ||
| testDir = fs.mkdtempSync(path.join(os.tmpdir(), "continue-test-")); | ||
| originalContinueHome = process.env.CONTINUE_GLOBAL_DIR; | ||
| process.env.CONTINUE_GLOBAL_DIR = testDir; | ||
|
|
||
| // Clear GlobalContext for clean test state | ||
| persistModelName(null); | ||
|
|
||
| mockAssistant = { | ||
| name: "test-assistant", | ||
| version: "1.0.0", | ||
| models: [ | ||
| { | ||
| provider: "openai", | ||
| model: "gpt-4", | ||
| name: "GPT-4", | ||
| apiKey: "test-key", | ||
| roles: ["chat"], | ||
| } as ModelConfig, | ||
| { | ||
| provider: "anthropic", | ||
| model: "claude-3-5-sonnet-20241022", | ||
| name: "Claude 3.5 Sonnet", | ||
| apiKey: "test-key", | ||
| roles: ["chat"], | ||
| } as ModelConfig, | ||
| { | ||
| provider: "anthropic", | ||
| model: "claude-3-opus-20240229", | ||
| name: "Claude 3 Opus", | ||
| apiKey: "test-key", | ||
| roles: ["chat"], | ||
| } as ModelConfig, | ||
| ], | ||
| } as AssistantUnrolled; | ||
|
|
||
| mockAuthConfig = { | ||
| userId: "test-user", | ||
| userEmail: "[email protected]", | ||
| accessToken: "test-token", | ||
| refreshToken: "test-refresh", | ||
| expiresAt: Date.now() + 3600000, // 1 hour from now | ||
| organizationId: "test-org", | ||
| }; | ||
|
|
||
| // Setup default mock behavior | ||
| vi.mocked(config.getLlmApi).mockReturnValue([ | ||
| mockLlmApi as any, | ||
| mockAssistant.models![0] as ModelConfig, | ||
| ]); | ||
| vi.mocked(config.createLlmApi).mockReturnValue(mockLlmApi as any); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| // Cleanup | ||
| if (fs.existsSync(testDir)) { | ||
| fs.rmSync(testDir, { recursive: true }); | ||
| } | ||
| if (originalContinueHome) { | ||
| process.env.CONTINUE_GLOBAL_DIR = originalContinueHome; | ||
| } else { | ||
| delete process.env.CONTINUE_GLOBAL_DIR; | ||
| } | ||
| }); | ||
|
|
||
| test("should restore model selection after restart", async () => { | ||
| // Step 1: Initial session - user starts with default model (GPT-4) | ||
| saveAuthConfig(mockAuthConfig); | ||
| let service = new ModelService(); | ||
| let state = await service.initialize(mockAssistant, mockAuthConfig); | ||
|
|
||
| console.log("Initial model:", state.model?.name); | ||
| expect(state.model?.name).toBe("GPT-4"); | ||
|
|
||
| // Step 2: User switches to Claude 3.5 Sonnet (index 1) | ||
| await service.switchModel(1); | ||
| state = service.getState(); | ||
|
|
||
| console.log("After switch:", state.model?.name); | ||
| expect(state.model?.name).toBe("Claude 3.5 Sonnet"); | ||
|
|
||
| // Step 3: Persist the model choice (this should happen in useModelSelector) | ||
| updateModelName("Claude 3.5 Sonnet"); | ||
|
|
||
| // Verify it was saved to auth.json | ||
| const savedConfig = loadAuthConfig(); | ||
| console.log("Saved model name:", getModelName(savedConfig)); | ||
| expect(getModelName(savedConfig)).toBe("Claude 3.5 Sonnet"); | ||
|
|
||
| // Step 4: Simulate restart - create new service instance | ||
| // Load fresh auth config from disk (this is what the real code does) | ||
| const freshAuthConfig = loadAuthConfig(); | ||
| console.log("Fresh auth config model name:", getModelName(freshAuthConfig)); | ||
|
|
||
| service = new ModelService(); | ||
| state = await service.initialize(mockAssistant, freshAuthConfig); | ||
|
|
||
| // Step 5: Verify the persisted model is restored | ||
| console.log("After restart:", state.model?.name); | ||
| expect(state.model?.name).toBe("Claude 3.5 Sonnet"); | ||
| expect(state.model?.provider).toBe("anthropic"); | ||
| }); | ||
|
|
||
| test("should handle model name mismatch gracefully", async () => { | ||
| // Save auth config with a model that doesn't exist | ||
| mockAuthConfig.modelName = "Non-existent Model"; | ||
| saveAuthConfig(mockAuthConfig); | ||
|
|
||
| const service = new ModelService(); | ||
| const state = await service.initialize(mockAssistant, mockAuthConfig); | ||
|
|
||
| // Should fall back to first available model (GPT-4) | ||
| expect(state.model?.name).toBe("GPT-4"); | ||
| }); | ||
|
|
||
| test("should check both name and model fields when matching", async () => { | ||
| // Some configs might have model field instead of name | ||
| const assistantWithModelField = { | ||
| ...mockAssistant, | ||
| models: [ | ||
| { | ||
| provider: "openai", | ||
| model: "gpt-4", | ||
| // No name field, just model | ||
| apiKey: "test-key", | ||
| roles: ["chat"], | ||
| } as ModelConfig, | ||
| { | ||
| provider: "anthropic", | ||
| model: "claude-3-5-sonnet-20241022", | ||
| // No name field, just model | ||
| apiKey: "test-key", | ||
| roles: ["chat"], | ||
| } as ModelConfig, | ||
| ], | ||
| } as AssistantUnrolled; | ||
|
|
||
| mockAuthConfig.modelName = "claude-3-5-sonnet-20241022"; | ||
| saveAuthConfig(mockAuthConfig); | ||
|
|
||
| const service = new ModelService(); | ||
| const state = await service.initialize( | ||
| assistantWithModelField, | ||
| mockAuthConfig, | ||
| ); | ||
|
|
||
| // Should match by model field | ||
| expect(state.model?.model).toBe("claude-3-5-sonnet-20241022"); | ||
| }); | ||
|
|
||
| test("should persist model through multiple switches", async () => { | ||
| saveAuthConfig(mockAuthConfig); | ||
| const service = new ModelService(); | ||
| await service.initialize(mockAssistant, mockAuthConfig); | ||
|
|
||
| // Switch to Claude 3.5 Sonnet | ||
| await service.switchModel(1); | ||
| updateModelName("Claude 3.5 Sonnet"); | ||
| expect(getModelName(loadAuthConfig())).toBe("Claude 3.5 Sonnet"); | ||
|
|
||
| // Switch to Claude 3 Opus | ||
| await service.switchModel(2); | ||
| updateModelName("Claude 3 Opus"); | ||
| expect(getModelName(loadAuthConfig())).toBe("Claude 3 Opus"); | ||
|
|
||
| // Restart and verify last selection | ||
| const freshAuthConfig = loadAuthConfig(); | ||
| console.log("Fresh auth config model name:", getModelName(freshAuthConfig)); | ||
|
|
||
| const newService = new ModelService(); | ||
| const state = await newService.initialize(mockAssistant, freshAuthConfig); | ||
| expect(state.model?.name).toBe("Claude 3 Opus"); | ||
| }); | ||
| }); | ||
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.
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.
Rule violated: Don't use console.log
New console.log statements were added to this test, but the guideline requires using the structured logger instead of console.* calls. Please swap these console logs out for the approved logging utility (and apply the same change to the other new console.log lines mentioned in the evidence).
Prompt for AI agents