Skip to content

Add run-button uv-mode test coverage#1494

Draft
Copilot wants to merge 11 commits intomainfrom
copilot/update-run-button-for-uv
Draft

Add run-button uv-mode test coverage#1494
Copilot wants to merge 11 commits intomainfrom
copilot/update-run-button-for-uv

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 29, 2026

  • The run button/task execution now uses uv run --python ... when python-envs.alwaysUseUv applies.
  • The uv setting is resolved with project scope so workspace-folder precedence is respected.
  • Updated the setting description to mention run-button behavior.
  • Added unit tests for uv, quoted-uv, and non-uv paths.

Copilot AI and others added 7 commits April 27, 2026 22:26
Agent-Logs-Url: https://github.com/microsoft/vscode-python-environments/sessions/5f628821-9c7b-48a6-9f5f-9fccb9a33bf6

Co-authored-by: eleanorjboyd <26030610+eleanorjboyd@users.noreply.github.com>
Agent-Logs-Url: https://github.com/microsoft/vscode-python-environments/sessions/5f628821-9c7b-48a6-9f5f-9fccb9a33bf6

Co-authored-by: eleanorjboyd <26030610+eleanorjboyd@users.noreply.github.com>
Agent-Logs-Url: https://github.com/microsoft/vscode-python-environments/sessions/5f628821-9c7b-48a6-9f5f-9fccb9a33bf6

Co-authored-by: eleanorjboyd <26030610+eleanorjboyd@users.noreply.github.com>
Agent-Logs-Url: https://github.com/microsoft/vscode-python-environments/sessions/5f628821-9c7b-48a6-9f5f-9fccb9a33bf6

Co-authored-by: eleanorjboyd <26030610+eleanorjboyd@users.noreply.github.com>
Agent-Logs-Url: https://github.com/microsoft/vscode-python-environments/sessions/5f628821-9c7b-48a6-9f5f-9fccb9a33bf6

Co-authored-by: eleanorjboyd <26030610+eleanorjboyd@users.noreply.github.com>
Agent-Logs-Url: https://github.com/microsoft/vscode-python-environments/sessions/5f628821-9c7b-48a6-9f5f-9fccb9a33bf6

Co-authored-by: eleanorjboyd <26030610+eleanorjboyd@users.noreply.github.com>
Agent-Logs-Url: https://github.com/microsoft/vscode-python-environments/sessions/ee61d4e1-336b-405a-93dc-f691bd210c7e

Co-authored-by: eleanorjboyd <26030610+eleanorjboyd@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds UV-mode coverage for run-button task execution, ensuring that when python-envs.alwaysUseUv applies the task is executed via uv run --python <interpreter> ..., and that the setting is resolved with proper project/workspace scope precedence.

Changes:

  • Updated runAsTask() to route task execution through uv run --python ... when shouldUseUv() applies (including passing project URI scope for settings precedence).
  • Extended shouldUseUv() to accept an optional VS Code configuration scope for correct workspace-folder precedence.
  • Added/expanded unit tests covering UV/non-UV execution paths, quoting behavior for the UV executable, and scope passing.
Show a summary per file
File Description
src/test/features/execution/runAsTask.unit.test.ts Adds unit test coverage for UV-mode task invocation, scope passing, and argument ordering.
src/managers/builtin/helpers.ts Extends shouldUseUv() with an optional ConfigurationScope to respect settings precedence.
src/features/execution/runAsTask.ts Implements UV-mode task execution (uv run --python ...) and passes project URI scope to shouldUseUv().
package.nls.json Updates the alwaysUseUv setting description to mention run-button behavior.

Copilot's findings

  • Files reviewed: 4/4 changed files
  • Comments generated: 2

Comment thread src/features/execution/runAsTask.ts
Comment thread src/managers/builtin/helpers.ts
@eleanorjboyd
Copy link
Copy Markdown
Member

this PR needs to updated to better respect PEP 723 style scripts:

Run Button: Interpreter Selection Logic
When a user clicks Run on a Python script, the behavior depends on whether the script uses PEP 723 inline metadata:

PEP 723 script (/// script block present): Run with uv run <script> and let uv manage interpreter and dependency resolution entirely. The script is self-contained and declares its own requirements, so the user's saved interpreter is not relevant.
Standard script (no /// script block): Run with uv run --python <saved_interpreter> <script>, using the interpreter the user has configured for the project/workspace.

Detection is done by scanning the script file for the /// script marker before constructing the run command.

@eleanorjboyd eleanorjboyd added the feature-request Request for new features or functionality label Apr 29, 2026
eleanorjboyd and others added 3 commits April 28, 2026 20:14
- Strip surrounding quotes from executable before passing as --python
  to uv; quoting the argument value causes uv to fail to resolve the
  interpreter (mirrors the same fix in runInBackground.ts)
- Add regression test: quoted python path under uv mode is unquoted
- Update shouldUseUv JSDoc to document the new scope parameter

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
When the run button is clicked on a PEP 723 script (one containing a
`# /// script` block), uv manages the interpreter and dependencies
entirely. We must not pass `--python` in that case or it would
override the script's own requirements.

Detection logic:
- New `isPep723Script(filePath)` helper in pep723.ts reads the script
  and checks for the PEP 723 opening marker `# /// script`
- In runAsTask, when uv mode is active, inspect options.args[0] (the
  script path) before building the command:
 `uv run <script> [userArgs]` (no --python, no env args)
 `uv run --python <interpreter> [envArgs] [userArgs]`

Tests added:
- pep723.unit.test.ts: unit tests for isPep723Script (marker present,
  absent, near-misses, trailing whitespace, read error fallback)
- runAsTask.unit.test.ts: PEP 723 suite (uv run without --python,
  extra user args forwarded, flag-first args skip detection, non-PEP 723
  still gets --python, read-error graceful fallback)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…wrapper

TypeScript's __importStar wraps CommonJS modules in a new object where
every property is a non-configurable  sinon cannot stub them.getter
Stub the underlying require('fs-extra') object instead; the namespace
wrapper's getters delegate to it, so the stub is picked up by the
source-under-test transparently. All 7 pep723 tests now pass.

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

Labels

feature-request Request for new features or functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants