-
Notifications
You must be signed in to change notification settings - Fork 55
Fix #1599: onDidChangePythonProjects never fires on runtime project a… #1641
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
edvilme
merged 4 commits into
microsoft:main
from
mohityadav8:fix-ondidchange-python-projects-not-firing
Jul 24, 2026
+92
−2
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
e3184e5
Fix #1599: onDidChangePythonProjects never fires on runtime project a…
mohityadav8 3359d8d
Potential fix for pull request finding
mohityadav8 a2efd25
Address Copilot review: add removal-path test coverage
mohityadav8 e14f6e4
Merge branch 'fix-ondidchange-python-projects-not-firing' of https://…
mohityadav8 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
Some comments aren't visible on the classic Files Changed page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| import * as assert from 'assert'; | ||
| import { EventEmitter, Uri } from 'vscode'; | ||
| import { PythonProject } from '../../api'; | ||
| import { PythonEnvironmentApiImpl } from '../../features/pythonApi'; | ||
| import { PythonProjectManager } from '../../internal.api'; | ||
|
|
||
| suite('PythonEnvironmentApiImpl - onDidChangePythonProjects', () => { | ||
| test('Fires event with correct added and removed projects', async () => { | ||
| // 1. Create a mock EventEmitter to simulate the internal project manager | ||
| const onDidChangeProjectsEmitter = new EventEmitter<void>(); | ||
|
|
||
| // 2. Mock the PythonProjectManager | ||
| let currentProjects: PythonProject[] = []; | ||
| const mockProjectManager = { | ||
| getProjects: () => currentProjects, | ||
| onDidChangeProjects: onDidChangeProjectsEmitter.event, | ||
| } as unknown as PythonProjectManager; | ||
|
|
||
| // 3. Mock the other required constructor arguments using ConstructorParameters | ||
| type ApiArgs = ConstructorParameters<typeof PythonEnvironmentApiImpl>; | ||
|
|
||
| const mockEnvManagers = { onDidChangeActiveEnvironment: new EventEmitter().event } as unknown as ApiArgs[0]; | ||
| const mockProjectCreators = {} as unknown as ApiArgs[2]; | ||
| const mockTerminalManager = {} as unknown as ApiArgs[3]; | ||
| const mockEnvVarManager = { onDidChangeEnvironmentVariables: new EventEmitter().event } as unknown as ApiArgs[4]; | ||
|
|
||
| // 4. Initialize the API instance | ||
| const api = new PythonEnvironmentApiImpl( | ||
| mockEnvManagers, | ||
| mockProjectManager, | ||
| mockProjectCreators, | ||
| mockTerminalManager, | ||
| mockEnvVarManager | ||
| ); | ||
|
|
||
| // 5. Listen to the public event we are testing | ||
| let firedEventPayload: unknown = null; | ||
| api.onDidChangePythonProjects((e: unknown) => { | ||
| firedEventPayload = e; | ||
| }); | ||
|
|
||
| // 6. Simulate adding a project | ||
| const newProject = { uri: Uri.joinPath(Uri.file(process.cwd()), 'fake', 'path') } as unknown as PythonProject; | ||
| currentProjects = [newProject]; // Update the mock's state | ||
|
|
||
| // Fire the internal event | ||
| onDidChangeProjectsEmitter.fire(); | ||
|
|
||
| // 7. Assert the public event fired with the correct delta | ||
| assert.ok(firedEventPayload, 'Event should have fired'); | ||
| assert.strictEqual((firedEventPayload as { added: PythonProject[] }).added.length, 1, 'Should have 1 added project'); | ||
| assert.strictEqual((firedEventPayload as { added: PythonProject[] }).added[0].uri.fsPath, newProject.uri.fsPath); | ||
| assert.strictEqual((firedEventPayload as { removed: PythonProject[] }).removed.length, 0, 'Should have 0 removed projects'); | ||
|
|
||
| // 8. Simulate removing the project | ||
| firedEventPayload = null; | ||
| currentProjects = []; | ||
| onDidChangeProjectsEmitter.fire(); | ||
|
|
||
| assert.ok(firedEventPayload, 'Event should have fired'); | ||
| assert.strictEqual((firedEventPayload as { added: PythonProject[] }).added.length, 0, 'Should have 0 added projects'); | ||
| assert.strictEqual((firedEventPayload as { removed: PythonProject[] }).removed.length, 1, 'Should have 1 removed project'); | ||
| assert.strictEqual((firedEventPayload as { removed: PythonProject[] }).removed[0].uri.fsPath, newProject.uri.fsPath); | ||
| }); | ||
| }); |
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.
Is there a reason we are exporting this?
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.
Hi @edvilme! I exported
PythonEnvironmentApiImplso I could import and instantiate it directly in the new unit test file (src/test/features/pythonApi.unit.test.ts) to verify onDidChangePythonProjects. If you prefer a different factory/internal access pattern for unit testing this class, let me know and I'd be happy to adjust!