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 6 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, --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, --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).', | ||
| ); | ||
| }); | ||
|
|
||
|
|
@@ -152,7 +152,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({ | ||
|
|
@@ -174,6 +174,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', | ||
|
|
@@ -184,9 +226,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', | ||
|
|
@@ -195,7 +234,7 @@ describe('modelCommand', () => { | |
| expect(result).toEqual({ | ||
| type: 'message', | ||
| messageType: 'info', | ||
| content: 'Model: qwen-max', | ||
| content: 'Model: qwen-max (default)', | ||
| }); | ||
| }); | ||
|
|
||
|
|
@@ -612,16 +651,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', | ||
|
|
@@ -1644,11 +1674,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', | ||
|
|
@@ -2040,22 +2066,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', | ||
| }); | ||
| }); | ||
|
|
@@ -2186,7 +2234,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), | ||
|
|
@@ -2209,7 +2257,10 @@ 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)'), | ||
|
|
||
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.
Deferred. The nine new
t()strings fall back to English for zh users, which is the existing behavior for untranslated keys. Adding translations is valid but out of scope for this round; deferred to a follow-up.中文说明
延期处理。9 条新增
t()字符串对中文用户会回退为英文,这与现有未翻译键的行为一致。添加翻译是有效的,但超出本轮范围;延期至后续处理。