-
Notifications
You must be signed in to change notification settings - Fork 2.8k
feat: add option to pause file-watching after initial indexing #10448
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
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
156 changes: 156 additions & 0 deletions
156
src/services/code-index/__tests__/file-watching-pause.spec.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,156 @@ | ||
| // npx vitest services/code-index/__tests__/file-watching-pause.spec.ts | ||
|
|
||
| import { CodeIndexConfigManager } from "../config-manager" | ||
| import { CodeIndexStateManager } from "../state-manager" | ||
|
|
||
| // Mock vscode | ||
| vi.mock("vscode", () => ({ | ||
| workspace: { | ||
| getConfiguration: vi.fn().mockImplementation(() => ({ | ||
| get: vi.fn().mockReturnValue(true), | ||
| })), | ||
| workspaceFolders: [{ uri: { fsPath: "/test/workspace" } }], | ||
| }, | ||
| EventEmitter: vi.fn().mockImplementation(() => ({ | ||
| event: vi.fn(), | ||
| fire: vi.fn(), | ||
| dispose: vi.fn(), | ||
| })), | ||
| })) | ||
|
|
||
| // Mock ContextProxy | ||
| vi.mock("../../../core/config/ContextProxy") | ||
|
|
||
| // Mock embeddingModels module | ||
| vi.mock("../../../shared/embeddingModels") | ||
|
|
||
| // Mock Package | ||
| vi.mock("../../../shared/package", () => ({ | ||
| Package: { | ||
| name: "roo-cline", | ||
| }, | ||
| })) | ||
|
|
||
| import * as vscode from "vscode" | ||
|
|
||
| describe("File Watching Pause Feature", () => { | ||
| let mockContextProxy: any | ||
|
|
||
| beforeEach(() => { | ||
| vi.clearAllMocks() | ||
|
|
||
| mockContextProxy = { | ||
| getGlobalState: vi.fn(), | ||
| getSecret: vi.fn().mockReturnValue(undefined), | ||
| refreshSecrets: vi.fn().mockResolvedValue(undefined), | ||
| updateGlobalState: vi.fn(), | ||
| } | ||
| }) | ||
|
|
||
| describe("CodeIndexConfigManager.isFileWatchingEnabled", () => { | ||
| it("should return true when file watching is enabled in workspace settings", () => { | ||
| // Mock vscode.workspace.getConfiguration to return true | ||
| const mockGetConfiguration = vi.mocked(vscode.workspace.getConfiguration) | ||
| mockGetConfiguration.mockReturnValue({ | ||
| get: vi.fn().mockReturnValue(true), | ||
| } as any) | ||
|
|
||
| mockContextProxy.getGlobalState.mockReturnValue({ | ||
| codebaseIndexEnabled: true, | ||
| }) | ||
|
|
||
| const configManager = new CodeIndexConfigManager(mockContextProxy) | ||
| expect(configManager.isFileWatchingEnabled).toBe(true) | ||
| }) | ||
|
|
||
| it("should return false when file watching is disabled in workspace settings", () => { | ||
| // Mock vscode.workspace.getConfiguration to return false | ||
| const mockGetConfiguration = vi.mocked(vscode.workspace.getConfiguration) | ||
| mockGetConfiguration.mockReturnValue({ | ||
| get: vi.fn().mockReturnValue(false), | ||
| } as any) | ||
|
|
||
| mockContextProxy.getGlobalState.mockReturnValue({ | ||
| codebaseIndexEnabled: true, | ||
| }) | ||
|
|
||
| const configManager = new CodeIndexConfigManager(mockContextProxy) | ||
| expect(configManager.isFileWatchingEnabled).toBe(false) | ||
| }) | ||
|
|
||
| it("should default to true when file watching setting is not set", () => { | ||
| // Mock vscode.workspace.getConfiguration to return default value | ||
| const mockGetConfiguration = vi.mocked(vscode.workspace.getConfiguration) | ||
| mockGetConfiguration.mockReturnValue({ | ||
| get: vi.fn().mockImplementation((key: string, defaultValue: any) => defaultValue), | ||
| } as any) | ||
|
|
||
| mockContextProxy.getGlobalState.mockReturnValue({ | ||
| codebaseIndexEnabled: true, | ||
| }) | ||
|
|
||
| const configManager = new CodeIndexConfigManager(mockContextProxy) | ||
| expect(configManager.isFileWatchingEnabled).toBe(true) | ||
| }) | ||
| }) | ||
|
|
||
| describe("CodeIndexStateManager IndexedPaused state", () => { | ||
| it("should set state to IndexedPaused with default message", () => { | ||
| const stateManager = new CodeIndexStateManager() | ||
|
|
||
| stateManager.setSystemState("IndexedPaused") | ||
|
|
||
| const status = stateManager.getCurrentStatus() | ||
| expect(status.systemStatus).toBe("IndexedPaused") | ||
| expect(status.message).toBe("Index ready. File watching paused.") | ||
| }) | ||
|
|
||
| it("should set state to IndexedPaused with custom message", () => { | ||
| const stateManager = new CodeIndexStateManager() | ||
|
|
||
| stateManager.setSystemState("IndexedPaused", "Custom paused message") | ||
|
|
||
| const status = stateManager.getCurrentStatus() | ||
| expect(status.systemStatus).toBe("IndexedPaused") | ||
| expect(status.message).toBe("Custom paused message") | ||
| }) | ||
|
|
||
| it("should reset progress counters when transitioning to IndexedPaused", () => { | ||
| const stateManager = new CodeIndexStateManager() | ||
|
|
||
| // First set to indexing with progress | ||
| stateManager.reportBlockIndexingProgress(50, 100) | ||
|
|
||
| // Then transition to IndexedPaused | ||
| stateManager.setSystemState("IndexedPaused") | ||
|
|
||
| const status = stateManager.getCurrentStatus() | ||
| expect(status.processedItems).toBe(0) | ||
| expect(status.totalItems).toBe(0) | ||
| }) | ||
|
|
||
| it("should allow transition from IndexedPaused to Indexing", () => { | ||
| const stateManager = new CodeIndexStateManager() | ||
|
|
||
| // Start in IndexedPaused state | ||
| stateManager.setSystemState("IndexedPaused") | ||
|
|
||
| // Then transition to Indexing (simulating re-index) | ||
| stateManager.setSystemState("Indexing", "Re-indexing...") | ||
|
|
||
| const status = stateManager.getCurrentStatus() | ||
| expect(status.systemStatus).toBe("Indexing") | ||
| expect(status.message).toBe("Re-indexing...") | ||
| }) | ||
| }) | ||
|
|
||
| describe("IndexingState type includes IndexedPaused", () => { | ||
| it("should accept IndexedPaused as valid state", () => { | ||
| const stateManager = new CodeIndexStateManager() | ||
|
|
||
| // Should not throw | ||
| stateManager.setSystemState("IndexedPaused") | ||
| expect(stateManager.state).toBe("IndexedPaused") | ||
| }) | ||
| }) | ||
| }) |
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
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.
This message uses a hardcoded string while the existing code pattern (e.g., line 202) uses the
t()function for i18n translations. For consistency and to support non-English locales, consider adding translation keys for these new messages.Fix it with Roo Code or mention @roomote and request a fix.