-
Notifications
You must be signed in to change notification settings - Fork 3.1k
fix(core): retry API request on model-unloaded errors for local model servers #3920
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
Closed
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
cfab698
fix(memory): route auto-memory recall selector to fast model
B-A-M-N 9d163ab
feat(cli): polish --add-dir / --include-directories feature
B-A-M-N 9aeb468
fix(directory): address review comments on /directory remove command
B-A-M-N c0f6207
fix(i18n): add zh and zh-TW translations for /directory remove command
B-A-M-N cc12845
fix(core): retry API request on model-unloaded errors for local model…
B-A-M-N 04ca9c9
fix(core): remove overly broad 'model not found' from isModelUnloaded…
B-A-M-N c413001
fix(pr-3920): address review comments on model-unloaded retry and dir…
B-A-M-N bf9f52f
fix: address review comments for PR #3920
B-A-M-N 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,9 +6,14 @@ | |
|
|
||
| import { describe, it, expect, vi, beforeEach } from 'vitest'; | ||
| import { directoryCommand, expandHomeDir } from './directoryCommand.js'; | ||
| import type { Config, WorkspaceContext } from '@qwen-code/qwen-code-core'; | ||
| import type { | ||
| Config, | ||
| WorkspaceContext, | ||
| SettingsFile, | ||
| } from '@qwen-code/qwen-code-core'; | ||
| import type { CommandContext } from './types.js'; | ||
| import { MessageType } from '../types.js'; | ||
| // eslint-disable-next-line import/no-internal-modules | ||
| import { SettingScope } from '../../config/settings.js'; | ||
| import * as os from 'node:os'; | ||
| import * as path from 'node:path'; | ||
|
|
@@ -21,6 +26,9 @@ describe('directoryCommand', () => { | |
| const addCommand = directoryCommand.subCommands?.find( | ||
| (c) => c.name === 'add', | ||
| ); | ||
| const removeCommand = directoryCommand.subCommands?.find( | ||
| (c) => c.name === 'remove', | ||
| ); | ||
| const showCommand = directoryCommand.subCommands?.find( | ||
| (c) => c.name === 'show', | ||
| ); | ||
|
|
@@ -30,6 +38,7 @@ describe('directoryCommand', () => { | |
| path.normalize('/home/user/project1'), | ||
| path.normalize('/home/user/project2'), | ||
| ]; | ||
| const initialDirs = new Set([path.normalize('/home/user/project1')]); | ||
| mockWorkspaceContext = { | ||
| addDirectory: vi.fn((directory: string) => { | ||
| const normalizedDirectory = path.normalize(directory); | ||
|
|
@@ -38,6 +47,11 @@ describe('directoryCommand', () => { | |
| } | ||
| }), | ||
| getDirectories: vi.fn(() => [...mockWorkspaceDirectories]), | ||
| getInitialDirectories: vi.fn(() => [...initialDirs]), | ||
| isInitialDirectory: vi.fn((dir: string) => | ||
| initialDirs.has(path.normalize(dir)), | ||
| ), | ||
| removeDirectory: vi.fn(), | ||
| } as unknown as WorkspaceContext; | ||
|
|
||
| mockConfig = { | ||
|
|
@@ -56,17 +70,29 @@ describe('directoryCommand', () => { | |
| setGeminiMdFileCount: vi.fn(), | ||
| } as unknown as Config; | ||
|
|
||
| const createMockSettings = () => ({ | ||
| merged: {}, | ||
| workspace: { | ||
| settings: {}, | ||
| originalSettings: {}, | ||
| } as SettingsFile, | ||
| user: { | ||
| settings: {}, | ||
| originalSettings: {}, | ||
| } as SettingsFile, | ||
| setValue: vi.fn(), | ||
| forScope: vi.fn(function (this: SettingsFile, scope: string) { | ||
| if (scope === 'user') return this.user; | ||
| return this.workspace; | ||
| }), | ||
| }); | ||
|
|
||
| const mockSettings = createMockSettings(); | ||
|
|
||
| mockContext = { | ||
| services: { | ||
| config: mockConfig, | ||
| settings: { | ||
| merged: {}, | ||
| workspace: { | ||
| settings: {}, | ||
| originalSettings: {}, | ||
| }, | ||
| setValue: vi.fn(), | ||
| }, | ||
| settings: mockSettings, | ||
| }, | ||
| ui: { | ||
| addItem: vi.fn(), | ||
|
|
@@ -314,6 +340,155 @@ describe('directoryCommand', () => { | |
| ); | ||
|
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. [Suggestion] remove 的 — deepseek-v4-pro via Qwen Code /review |
||
| }); | ||
| }); | ||
| describe('remove', () => { | ||
| it('should show an error if no path is provided', async () => { | ||
| if (!removeCommand?.action) throw new Error('No action'); | ||
| await removeCommand.action(mockContext, ''); | ||
| expect(mockContext.ui.addItem).toHaveBeenCalledWith( | ||
| expect.objectContaining({ | ||
| type: MessageType.ERROR, | ||
| text: 'Please provide a directory path to remove.', | ||
| }), | ||
| expect.any(Number), | ||
| ); | ||
| }); | ||
|
|
||
| it('should show an error when trying to remove the initial directory', async () => { | ||
| const initialDir = path.normalize('/home/user/project1'); | ||
| if (!removeCommand?.action) throw new Error('No action'); | ||
| await removeCommand.action(mockContext, initialDir); | ||
| expect(mockContext.ui.addItem).toHaveBeenCalledWith( | ||
| expect.objectContaining({ | ||
| type: MessageType.ERROR, | ||
| text: `Cannot remove initial workspace directory: ${initialDir}`, | ||
| }), | ||
| expect.any(Number), | ||
| ); | ||
| }); | ||
|
|
||
| it('should show an error when directory is not in workspace', async () => { | ||
| const nonExistent = path.normalize('/not/in/workspace'); | ||
| if (!removeCommand?.action) throw new Error('No action'); | ||
| await removeCommand.action(mockContext, nonExistent); | ||
| expect(mockContext.ui.addItem).toHaveBeenCalledWith( | ||
| expect.objectContaining({ | ||
| type: MessageType.ERROR, | ||
| text: `Directory not found in workspace: ${nonExistent}`, | ||
| }), | ||
| expect.any(Number), | ||
| ); | ||
| }); | ||
|
|
||
| it('should remove a directory and persist to settings', async () => { | ||
| const removableDir = path.normalize('/home/user/project2'); | ||
| mockWorkspaceContext = { | ||
| ...mockWorkspaceContext, | ||
| removeDirectory: vi.fn().mockReturnValue(true), | ||
| isInitialDirectory: vi.fn().mockReturnValue(false), | ||
| getInitialDirectories: vi | ||
| .fn() | ||
| .mockReturnValue([path.normalize('/home/user/project1')]), | ||
| } as unknown as WorkspaceContext; | ||
|
|
||
| mockConfig = { | ||
| ...mockConfig, | ||
| getWorkspaceContext: () => mockWorkspaceContext, | ||
| } as unknown as Config; | ||
|
|
||
| mockContext = { | ||
| ...mockContext, | ||
| services: { | ||
| ...mockContext.services, | ||
| config: mockConfig, | ||
| settings: { | ||
| ...mockContext.services.settings, | ||
| workspace: { | ||
| settings: {}, | ||
| originalSettings: { | ||
| context: { | ||
| includeDirectories: [ | ||
| path.normalize('/home/user/project1'), | ||
| removableDir, | ||
| ], | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| } as unknown as CommandContext; | ||
|
|
||
| if (!removeCommand?.action) throw new Error('No action'); | ||
| await removeCommand.action(mockContext, removableDir); | ||
|
|
||
| expect(mockWorkspaceContext.removeDirectory).toHaveBeenCalledWith( | ||
| removableDir, | ||
| ); | ||
| expect(mockContext.services.settings.setValue).toHaveBeenCalledWith( | ||
| SettingScope.Workspace, | ||
| 'context.includeDirectories', | ||
| [path.normalize('/home/user/project1')], | ||
| ); | ||
| expect(mockContext.ui.addItem).toHaveBeenCalledWith( | ||
| expect.objectContaining({ | ||
| type: MessageType.INFO, | ||
| text: `Removed directory: ${removableDir}`, | ||
| }), | ||
| expect.any(Number), | ||
| ); | ||
| }); | ||
|
|
||
| it('should show error when settings update fails after removal', async () => { | ||
| const removableDir = path.normalize('/home/user/project2'); | ||
| mockWorkspaceContext = { | ||
| ...mockWorkspaceContext, | ||
| removeDirectory: vi.fn().mockReturnValue(true), | ||
| isInitialDirectory: vi.fn().mockReturnValue(false), | ||
| getInitialDirectories: vi | ||
| .fn() | ||
| .mockReturnValue([path.normalize('/home/user/project1')]), | ||
| } as unknown as WorkspaceContext; | ||
|
|
||
| mockConfig = { | ||
| ...mockConfig, | ||
| getWorkspaceContext: () => mockWorkspaceContext, | ||
| } as unknown as Config; | ||
|
|
||
| const settingsError = new Error('write failed'); | ||
| mockContext = { | ||
| ...mockContext, | ||
| services: { | ||
| ...mockContext.services, | ||
| config: mockConfig, | ||
| settings: { | ||
| ...mockContext.services.settings, | ||
| workspace: { | ||
| settings: {}, | ||
| originalSettings: { | ||
| context: { includeDirectories: [removableDir] }, | ||
| }, | ||
| }, | ||
| setValue: vi.fn().mockImplementation(() => { | ||
| throw settingsError; | ||
| }), | ||
| }, | ||
| }, | ||
| } as unknown as CommandContext; | ||
|
|
||
| if (!removeCommand?.action) throw new Error('No action'); | ||
| await removeCommand.action(mockContext, removableDir); | ||
|
|
||
| expect(mockContext.ui.addItem).toHaveBeenCalledWith( | ||
| expect.objectContaining({ | ||
| type: MessageType.ERROR, | ||
| text: `Failed to persist directory removal: ${settingsError.message}`, | ||
| }), | ||
| expect.any(Number), | ||
| ); | ||
| // Directory should NOT have been removed from memory since persistence failed | ||
| expect(mockWorkspaceContext.removeDirectory).not.toHaveBeenCalled(); | ||
| }); | ||
| }); | ||
|
|
||
| it('should correctly expand a Windows-style home directory path', () => { | ||
| const windowsPath = '%userprofile%\\Documents'; | ||
| const expectedPath = path.win32.join(os.homedir(), 'Documents'); | ||
|
|
||
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.
[Critical] TypeScript 类型错误:
Cannot find name 'SettingsFile'(第 73、77 行)和'this' implicitly has type 'any'(第 81 行)。createMockSettings函数中使用了SettingsFile类型但未导入,且forScope方法中的this缺少类型注解。— deepseek-v4-pro via Qwen Code /review