Repository navigation
fix(cli): keep model switches session-scoped #6579
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
Changes from 18 commits
1d6940f
77da2b8
c044a02
bf724cc
a6e995d
b6e9b58
a36e33d
4044ff7
60cc536
0a01d89
d57bdf0
7b7cb51
02b23fc
d6e7252
ff7e91d
1adfab3
d1c23dc
ded4336
6e81163
9cbc430
fdac9fd
f893109
991395a
5b12caf
db59eb8
78df51b
ed0ac4f
9246bbf
237b2ed
44be9d7
a90f499
c50a114
56d62ff
5152271
7e9cc4d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,7 +46,7 @@ describe('modelCommand', () => { | |
| it('should have the correct name and description', () => { | ||
| expect(modelCommand.name).toBe('model'); | ||
| expect(modelCommand.description).toBe( | ||
| 'Switch the model for this session (--fast for suggestion model, --voice for voice transcription model, --vision for the vision bridge model, --image for the image generation model, --project to persist to project settings, --global to persist to user settings, [model-id] to switch immediately, or [model-id] [prompt] to run a one-off prompt on another model; the inline prompt is sent verbatim without @file expansion).', | ||
| 'Switch the model for this session (--default to persist the main model for future sessions, --fast for suggestion model, --voice for voice transcription model, --vision for the vision bridge model, --image for the image generation model, --project to persist to project settings, --global to persist to user settings, [model-id] to switch immediately, or [model-id] [prompt] to run a one-off prompt on another model; the inline prompt is sent verbatim without @file expansion).', | ||
| ); | ||
| }); | ||
|
|
||
|
|
@@ -174,7 +174,7 @@ describe('modelCommand', () => { | |
| }); | ||
| }); | ||
|
|
||
| it('should switch the main model directly in interactive mode when args are provided', async () => { | ||
| it('should switch the main model directly in interactive mode without persisting', async () => { | ||
| const setValue = vi.fn(); | ||
| const switchModel = vi.fn().mockResolvedValue(undefined); | ||
| mockContext = createMockCommandContext({ | ||
|
|
@@ -196,6 +196,48 @@ describe('modelCommand', () => { | |
|
|
||
| const result = await modelCommand.action!(mockContext, 'qwen-max'); | ||
|
|
||
| expect(switchModel).toHaveBeenCalledWith( | ||
|
Collaborator
Author
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. The requested cases are reasonable coverage suggestions, but the repository review rules classify missing tests as Suggestion-level unless the untested path is itself the defect. This round adds regression coverage for the two reproduced user-visible blockers: the silently dropped 中文说明这些用例作为测试覆盖建议是合理的,但仓库评审规则明确规定:除非未测试路径本身就是缺陷,否则缺少测试属于 Suggestion。本轮已经为两个已复现的用户可见阻断问题补充了回归覆盖:静默丢弃
Collaborator
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. Partially addressed this round: added tests for 中文说明本轮已部分处理:新增了 |
||
| AuthType.QWEN_OAUTH, | ||
| 'qwen-max', | ||
| undefined, | ||
| ); | ||
| expect(setValue).not.toHaveBeenCalled(); | ||
| expect(result).toEqual({ | ||
| type: 'message', | ||
| messageType: 'info', | ||
| content: 'Model: qwen-max', | ||
| }); | ||
| }); | ||
|
|
||
| it('persists the main model only with --default', async () => { | ||
| const setValue = vi.fn(); | ||
| const switchModel = vi.fn().mockResolvedValue(undefined); | ||
| mockContext = createMockCommandContext({ | ||
| invocation: { | ||
| raw: '/model --default qwen-max', | ||
| name: 'model', | ||
| args: '--default qwen-max', | ||
| }, | ||
| services: { | ||
| config: { | ||
| getContentGeneratorConfig: vi.fn().mockReturnValue({ | ||
| model: 'qwen-plus', | ||
| authType: AuthType.QWEN_OAUTH, | ||
| }), | ||
| getAvailableModelsForAuthType: vi | ||
| .fn() | ||
| .mockReturnValue([{ id: 'qwen-max', label: 'Qwen Max' }]), | ||
| switchModel, | ||
| }, | ||
| settings: createMockSettings(setValue), | ||
| }, | ||
| }); | ||
|
|
||
| const result = await modelCommand.action!( | ||
| mockContext, | ||
| '--default qwen-max', | ||
| ); | ||
|
|
||
| expect(switchModel).toHaveBeenCalledWith( | ||
| AuthType.QWEN_OAUTH, | ||
| 'qwen-max', | ||
|
|
@@ -206,9 +248,6 @@ describe('modelCommand', () => { | |
| 'model.name', | ||
| 'qwen-max', | ||
| ); | ||
| // `/model <id>` is an id-only switch, so any baseUrl disambiguator left by | ||
| // a previous model-picker selection must be cleared (empty-string tombstone) | ||
| // to avoid resolving to a different provider on next launch. | ||
| expect(setValue).toHaveBeenCalledWith( | ||
| expect.any(String), | ||
| 'model.baseUrl', | ||
|
|
@@ -217,7 +256,7 @@ describe('modelCommand', () => { | |
| expect(result).toEqual({ | ||
| type: 'message', | ||
| messageType: 'info', | ||
| content: 'Model: qwen-max', | ||
| content: 'Model: qwen-max (default)', | ||
| }); | ||
| }); | ||
|
|
||
|
|
@@ -260,6 +299,45 @@ describe('modelCommand', () => { | |
| }); | ||
| }); | ||
|
|
||
| it('rejects --default with an inline prompt', async () => { | ||
| const setValue = vi.fn(); | ||
| const switchModel = vi.fn().mockResolvedValue(undefined); | ||
| mockContext = createMockCommandContext({ | ||
| invocation: { | ||
| raw: '/model --default qwen-max explain this code', | ||
| name: 'model', | ||
| args: '--default qwen-max explain this code', | ||
| }, | ||
| services: { | ||
| config: { | ||
| getContentGeneratorConfig: vi.fn().mockReturnValue({ | ||
| model: 'qwen-plus', | ||
| authType: AuthType.QWEN_OAUTH, | ||
| }), | ||
| getAvailableModelsForAuthType: vi | ||
| .fn() | ||
| .mockReturnValue([{ id: 'qwen-max', label: 'Qwen Max' }]), | ||
| switchModel, | ||
| }, | ||
| settings: createMockSettings(setValue), | ||
| }, | ||
| }); | ||
|
|
||
| const result = await modelCommand.action!( | ||
| mockContext, | ||
| '--default qwen-max explain this code', | ||
| ); | ||
|
|
||
| expect(switchModel).not.toHaveBeenCalled(); | ||
| expect(setValue).not.toHaveBeenCalled(); | ||
| expect(result).toEqual({ | ||
| type: 'message', | ||
| messageType: 'error', | ||
| content: | ||
| "Cannot combine --default with an inline prompt. Run '/model --default qwen-max' first, then send your prompt.", | ||
| }); | ||
| }); | ||
|
|
||
| it('rejects an inline prompt when the model id is not available', async () => { | ||
| const switchModel = vi.fn(); | ||
| mockContext = createMockCommandContext({ | ||
|
|
@@ -634,16 +712,7 @@ describe('modelCommand', () => { | |
| 'gpt-4', | ||
| undefined, | ||
| ); | ||
| expect(setValue).toHaveBeenCalledWith( | ||
| expect.any(String), | ||
| 'security.auth.selectedType', | ||
| AuthType.USE_OPENAI, | ||
| ); | ||
| expect(setValue).toHaveBeenCalledWith( | ||
| expect.any(String), | ||
| 'model.name', | ||
| 'gpt-4', | ||
| ); | ||
| expect(setValue).not.toHaveBeenCalled(); | ||
| expect(result).toEqual({ | ||
| type: 'message', | ||
| messageType: 'info', | ||
|
|
@@ -1791,11 +1860,7 @@ describe('modelCommand', () => { | |
| '--fast-model', | ||
| undefined, | ||
| ); | ||
| expect(setValue).toHaveBeenCalledWith( | ||
| expect.any(String), | ||
| 'model.name', | ||
| '--fast-model', | ||
| ); | ||
| expect(setValue).not.toHaveBeenCalled(); | ||
| expect(result).toEqual({ | ||
| type: 'message', | ||
| messageType: 'info', | ||
|
|
@@ -2221,22 +2286,44 @@ describe('modelCommand', () => { | |
| return mockContext; | ||
| } | ||
|
|
||
| it('should include persistScope in dialog return for /model --project', async () => { | ||
| it('should reject /model --project without --default', async () => { | ||
| const ctx = setupContext(); | ||
| const result = await modelCommand.action!(ctx, '--project'); | ||
| expect(result).toMatchObject({ | ||
| type: 'message', | ||
| messageType: 'error', | ||
| content: expect.stringContaining('--default'), | ||
| }); | ||
| }); | ||
|
|
||
| it('should reject /model --global without --default', async () => { | ||
| const ctx = setupContext(); | ||
| const result = await modelCommand.action!(ctx, '--global'); | ||
| expect(result).toMatchObject({ | ||
| type: 'message', | ||
| messageType: 'error', | ||
| content: expect.stringContaining('--default'), | ||
| }); | ||
| }); | ||
|
|
||
| it('should include persistScope in dialog return for /model --default --project', async () => { | ||
| const ctx = setupContext(); | ||
| const result = await modelCommand.action!(ctx, '--default --project'); | ||
| expect(result).toEqual({ | ||
| type: 'dialog', | ||
| dialog: 'model', | ||
| persistDefault: true, | ||
| persistScope: 'workspace', | ||
| }); | ||
| }); | ||
|
|
||
| it('should include persistScope in dialog return for /model --global', async () => { | ||
| it('should include persistScope in dialog return for /model --default --global', async () => { | ||
| const ctx = setupContext(); | ||
| const result = await modelCommand.action!(ctx, '--global'); | ||
| const result = await modelCommand.action!(ctx, '--default --global'); | ||
| expect(result).toEqual({ | ||
| type: 'dialog', | ||
| dialog: 'model', | ||
| persistDefault: true, | ||
| persistScope: 'user', | ||
| }); | ||
| }); | ||
|
|
@@ -2377,7 +2464,7 @@ describe('modelCommand', () => { | |
| expect(setValue).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('should show scope suffix in main model confirmation', async () => { | ||
| it('should persist and show scope suffix for --default main model confirmation', async () => { | ||
| const setValue = vi.fn(); | ||
| const settings = { | ||
| ...createMockSettings(setValue), | ||
|
|
@@ -2400,10 +2487,13 @@ describe('modelCommand', () => { | |
| { id: 'qwen-max', voiceOnly: false, fastOnly: false }, | ||
| ]); | ||
| cfg.switchModel = vi.fn().mockResolvedValue(mockGenerator); | ||
| const result = await modelCommand.action!(ctx, '--project qwen-max'); | ||
| const result = await modelCommand.action!( | ||
| ctx, | ||
| '--default --project qwen-max', | ||
| ); | ||
| expect(result).toMatchObject({ | ||
| type: 'message', | ||
| content: expect.stringContaining('(this project)'), | ||
| content: expect.stringContaining('(this project default)'), | ||
| }); | ||
| expect(setValue).toHaveBeenCalledWith( | ||
| SettingScope.Workspace, | ||
|
|
@@ -2420,5 +2510,82 @@ describe('modelCommand', () => { | |
| dialog: 'model', | ||
| }); | ||
| }); | ||
|
|
||
| it('should reject --default combined with --fast', async () => { | ||
| const ctx = setupContext(); | ||
| const result = await modelCommand.action!(ctx, '--default --fast'); | ||
| expect(result).toMatchObject({ | ||
| type: 'message', | ||
| messageType: 'error', | ||
| content: expect.stringContaining( | ||
| '--default only applies to the main model', | ||
| ), | ||
| }); | ||
| }); | ||
|
|
||
| it('should reject --default combined with --image', async () => { | ||
| const ctx = setupContext(); | ||
| const result = await modelCommand.action!(ctx, '--default --image'); | ||
| expect(result).toMatchObject({ | ||
| type: 'message', | ||
| messageType: 'error', | ||
| content: expect.stringContaining( | ||
| '--default only applies to the main model', | ||
| ), | ||
| }); | ||
| }); | ||
|
|
||
| it('should not reject --default when prompt text contains --vision', async () => { | ||
| const setValue = vi.fn(); | ||
| const settings = { | ||
| ...createMockSettings(setValue), | ||
| _merged: {}, | ||
| computeMergedSettings: vi.fn(), | ||
| isTrusted: true, | ||
| } as unknown as LoadedSettings; | ||
| const ctx = setupContext(); | ||
| ctx.services.settings = settings; | ||
| const cfg = ctx.services.config as unknown as Partial<Config> & { | ||
| [key: string]: unknown; | ||
| }; | ||
| cfg.getAvailableModelsForAuthType = vi | ||
| .fn() | ||
| .mockReturnValue([ | ||
| { id: 'qwen-max', voiceOnly: false, fastOnly: false }, | ||
| ]); | ||
| cfg.switchModel = vi.fn().mockResolvedValue(undefined); | ||
| const result = await modelCommand.action!( | ||
| ctx, | ||
| '--default qwen-max what does --vision do', | ||
| ); | ||
| expect(result).toMatchObject({ | ||
| type: 'message', | ||
| messageType: 'error', | ||
| content: expect.stringContaining('Cannot combine --default'), | ||
| }); | ||
| }); | ||
|
|
||
| it('should reject bare --default in non-interactive mode', async () => { | ||
| const ctx = setupContext(); | ||
| ctx.executionMode = 'non_interactive'; | ||
| const result = await modelCommand.action!(ctx, '--default'); | ||
| expect(result).toMatchObject({ | ||
| type: 'message', | ||
| messageType: 'error', | ||
| content: expect.stringContaining( | ||
| '--default requires a model ID in non-interactive mode', | ||
| ), | ||
| }); | ||
| }); | ||
|
|
||
| it('should open model picker with persistDefault for bare /model --default', async () => { | ||
| const ctx = setupContext(); | ||
| const result = await modelCommand.action!(ctx, '--default'); | ||
| expect(result).toEqual({ | ||
| type: 'dialog', | ||
| dialog: 'model', | ||
| persistDefault: true, | ||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
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.
Addressed in 237b2ed. I removed both unreferenced description variants from en, zh, and zh-TW, leaving only the full --default + --compaction + --image key used by modelCommand.
npm run check-i18npasses.