Skip to content

Fix flaky Python project environment identity assertions - #1725

Merged
Stella Huang (StellaHuang95) merged 1 commit into
microsoft:mainfrom
StellaHuang95:fix-python-project-env-identity
Aug 18, 2026
Merged

Fix flaky Python project environment identity assertions#1725
Stella Huang (StellaHuang95) merged 1 commit into
microsoft:mainfrom
StellaHuang95:fix-python-project-env-identity

Conversation

@StellaHuang95

@StellaHuang95 Stella Huang (StellaHuang95) commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Context

The macOS 3.12 integration job in recent prs failed in Integration: Python Projects > File in project uses project environment

The assertion showed the same Python version with two different generated suffixes:

actual:   Python 3.13.14-cnykpnoi58
expected: Python 3.13.14-ul2l97bdet

Root cause

PythonEnvironmentApiImpl.createPythonEnvironmentItem() appends Math.random() when creating envId.id. A manager may rematerialize the same logical interpreter from its persisted path during getEnvironment(), producing a fresh object and random ID.

The Python Projects integration suite compared envId.id to verify:

  • candidate environments differ;
  • the expected change event arrived;
  • project readback returns the selected environment;
  • clearing starts from the selected environment;
  • a file inherits its containing project's environment.

Those checks can fail even when the manager, executable path, and Python version are all correct.

Fix

Use one logical-environment identity throughout this suite:

manager ID + normalized environment path + version

The shared helper now drives candidate selection, event filtering, and all project/file readback assertions. The event helper still subscribes before setEnvironment(), so this does not reintroduce the settings-persistence race that the event-driven test was designed to avoid.

The event-specific test also reuses the URI-and-environment-filtered helper instead of accepting any later event with a non-empty new value.

Why this is test-only

This suite verifies project association and inheritance, not the long-term stability contract of envId.id. Changing production ID generation here would be a broad public-API and cache-semantics change: environment IDs key package caches, watchers, terminals, tree items, and active-selection equality. Managers also do not consistently represent environmentPath as the same kind of path.

Production envId stability is worth evaluating separately. This focused fix keeps the integration assertion strict while avoiding an unrelated cross-cutting behavior change.

Validation

  • npm run compile-tests
  • ESLint on the changed test
  • targeted Integration: Python Projects suite: 8 passing
  • targeted suite repeated 7 times successfully in the VS Code integration harness
  • independent code review completed with no significant findings

A full local integration run reached and passed the changed Python Projects suite, then failed later in unrelated environment-creation tests. The separate Ubuntu package-network failure from the same CI run is not addressed by this PR.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 3cb82ae9-7424-40a4-9156-8c54ac6e0895
@rchiodo

Rich Chiodo (rchiodo) commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

🔒 Automated review in progress — Rich Chiodo (@rchiodo) is auto-reviewing this PR.

Comment on lines +29 to +35
function getEnvironmentIdentity(environment: PythonEnvironment) {
return {
managerId: environment.envId.managerId,
path: normalizePath(environment.environmentPath.fsPath),
version: environment.version,
};
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could/should we somehow hash them so we only have to compare the hashes?

@rchiodo Rich Chiodo (rchiodo) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved via Review Center.

@rchiodo Rich Chiodo (rchiodo) added the review-auto:approved Automated review: no blocking findings (approval posted). label Aug 18, 2026
@StellaHuang95
Stella Huang (StellaHuang95) merged commit 6104bbb into microsoft:main Aug 18, 2026
85 of 88 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Issue identified by VS Code Team member as probable bug review-auto:approved Automated review: no blocking findings (approval posted).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants