Skip to content

Add unit tests for venv/conda create & remove orchestration#1638

Open
StellaHuang95 wants to merge 1 commit into
microsoft:mainfrom
StellaHuang95:test/1624-venv-conda-create-remove-tests
Open

Add unit tests for venv/conda create & remove orchestration#1638
StellaHuang95 wants to merge 1 commit into
microsoft:mainfrom
StellaHuang95:test/1624-venv-conda-create-remove-tests

Conversation

@StellaHuang95

Copy link
Copy Markdown
Contributor

Closes #1624

Summary

The create/remove orchestration in VenvManager (src/managers/builtin/venvManager.ts) and CondaEnvManager (src/managers/conda/condaEnvManager.ts) previously had no unit-level coverage of the create/remove lifecycle. While helpers such as venvUtils.removeVenv and several condaEnvManager sub-behaviors (setEvents, setGlobal, findEnvironmentByPath) were unit-tested, the manager methods that tie discovery, creation, caching, and change-event firing together were only exercised indirectly via integration tests.

This PR adds focused unit tests for that lifecycle, plus the minimal supporting changes needed to make those paths testable.

What changed

New tests

  • src/test/managers/builtin/venvManager.createRemove.unit.test.ts — covers VenvManager.create/remove:
    • non-quick create delegates to the create helper, caches the environment, writes .gitignore, reveals the folder, and fires an add event
    • quick create uses the selected global Python and forwards additionalPackages
    • creation errors are reported without adding an environment
    • the skipWatcherRefresh guard is restored even when creation/removal throws
    • successful removal updates the collection and fires a remove event; a false result from the removal helper mutates nothing
  • src/test/managers/conda/condaEnvManager.createRemove.unit.test.ts — covers CondaEnvManager.create/remove:
    • non-quick create delegates, caches the env, and fires an add event
    • global quick create resolves a prefix and forwards additional packages; project quick create uses the project root and writes .gitignore
    • no state mutation when creation returns no environment or throws
    • successful removal updates caches and fires collection + per-project events
    • a rejected deletion is logged without firing a success event

Supporting production/test-helper changes

  • src/managers/builtin/venvManager.ts (4 lines): route the post-create revealInExplorer call through the existing executeCommand wrapper in src/common/command.api.ts instead of importing commands from vscode directly. This is a small testability refactor (the wrapper can be stubbed in unit tests) with no behavior change.
  • src/test/mocks/pythonEnvironment.ts: add an optional sysPrefix override to the shared mock helper (defaults to envPath, so existing callers are unaffected).

Testing

  • npm run compile-tests — clean.
  • npm run unittest (venv/conda manager suites) — all new and existing manager tests pass. The one remaining failure in the suite (venvManager.loadEnvMap.unit.test.ts — "projectB should have its env mapped despite projectA failing") pre-exists on main and is unrelated to this change.

Notes

  • This change is intentionally scoped to test coverage plus the minimal refactor required to enable it; no environment-manager behavior is changed.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 8f42031a-bd90-4448-bffe-b5c0ab522b6d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add unit tests for venvManager/condaEnvManager create & remove orchestration

1 participant