Skip to content

fix(terminal): wait for shell integration before running Python commands - #1741

Merged
Eduardo Villalpando Mello (edvilme) merged 2 commits into
microsoft:mainfrom
koolcandy:fix/wait-for-shell-integration-before-run
Aug 28, 2026
Merged

fix(terminal): wait for shell integration before running Python commands#1741
Eduardo Villalpando Mello (edvilme) merged 2 commits into
microsoft:mainfrom
koolcandy:fix/wait-for-shell-integration-before-run

Conversation

@koolcandy

Copy link
Copy Markdown
Contributor

Summary

  • Wait for shell integration before selecting the sendText fallback in runInTerminal.
  • Re-check terminal.shellIntegration after the wait so a terminal that becomes ready uses executeCommand.
  • Add unit-test coverage for the ordering.

Background

On a newly created terminal, terminal.shellIntegration can be undefined while the shell is still initializing. runInTerminal previously selected the sendText fallback immediately in that state. With Fish, the command can then be written before the shell prompt and shell-integration sequences are ready, which can produce duplicate command or prompt echo.

The existing waitForShellIntegration helper already filters shell-integration events to the target terminal. This change waits for that helper before selecting the execution path and preserves the existing sendText fallback when shell integration remains unavailable.

Related to #1312

Scope

This PR addresses the early sendText race in the Python Environments extension. A separate approximately five-second delay can occur inside VS Code Core after executeCommand is called; that Core behavior is not changed here.

Testing

  • npm run compile-tests
  • npm run lint
  • npm run compile
  • Unit suite via Mocha with Node 22: 1871 passing, 8 pending

@heejaechang

Copy link
Copy Markdown

🔒 Automated review in progress — Heejae Chang (@heejaechang) is auto-reviewing this PR.

@koolcandy

Copy link
Copy Markdown
Contributor Author

@microsoft-github-policy-service agree

@heejaechang

Copy link
Copy Markdown

Verification: The relevant tests could not be fully run in the isolated environment; this review is not fully verified.

Result: could-not-verify

Summary: Verification could not run because no trusted sandbox image is configured, and local execution was not authorized. The PR adds one targeted unit test for waiting until shell integration becomes available. The fallback path after waiting remains uncovered.

Test runs: 1 not run

  • ⚠️ Not run | Targeted runInTerminal unit test | npm run compile-tests && npm run unittest -- --grep "waits for shell integration before executing a command"
⚠️ Targeted runInTerminal unit test diagnostic output
Container verification could not start: no trusted sandbox image is configured for microsoft/vscode-python-environments.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Approved via Review Center.

@heejaechang Heejae Chang (heejaechang) added the review-auto:approved Automated review: no blocking findings (approval posted). label Aug 27, 2026
@koolcandy
koolcandy (koolcandy) force-pushed the fix/wait-for-shell-integration-before-run branch from 6f0d49f to c1ac6d3 Compare August 27, 2026 02:53
@koolcandy

Copy link
Copy Markdown
Contributor Author

The remaining delay of approximately five seconds occurs after executeCommand is invoked and is handled by VS Code Core. This is related to microsoft/vscode#329895 and will require an upstream fix. This PR is intentionally limited to fixing the earlier sendText race in the Python Environments extension.

@heejaechang

Copy link
Copy Markdown

Verification: The relevant tests could not be fully run in the isolated environment; this review is not fully verified.

Result: could-not-verify

Summary: Verification could not execute because no trusted sandbox image is configured for this repository, and local fallback was not authorized. The PR adds one unit test covering delayed shell integration followed by `executeCommand`. The post-wait `sendText` fallback remains uncovered.

Test runs: 1 not run

  • ⚠️ Not run | Verification environment and test discovery | printf '%s\n' '=== sandbox profile ==='; printf '%s\n' "${AUTOMATION_SANDBOX_PROFILE:-unset}"; printf '%s\n' '=== dependency state ==='; if [ -d node_modules ]; then echo 'node_modules: present'; else echo 'node_modules: missing'; fi; printf '%s\n' '=== relevant scripts ==='; node -e "const p=require('./package.json'); for (const [k,v] of Object.entries(p.scripts||{})) if (/test|compile|lint|unit/.test(k)) console.log(k+'='+v)"; printf '%s\n' '=== refs ==='; git branch -a --no-color; printf '%s\n' '=== working tree ==='; git status --short; printf '%s\n' '=== PR files vs first available base ==='; base=''; for ref in upstream/main origin/main main HEAD^; do if git rev-parse --verify "$ref" >/dev/null 2>&1; then base="$ref"; break; fi; done; echo "base=$base"; git diff --name-status "$base"...HEAD; printf '%s\n' '=== changed tests ==='; git diff --unified=0 "$base"...HEAD -- 'src/test/**/.test.ts' | grep -E '^(diff --git|+.(suite|test)()' || true
⚠️ Verification environment and test discovery diagnostic output
Container verification could not start: no trusted sandbox image is configured for microsoft/vscode-python-environments. Local execution was not authorized.

@koolcandy
koolcandy (koolcandy) force-pushed the fix/wait-for-shell-integration-before-run branch from 0d8156a to 03bd5e5 Compare August 27, 2026 03:34
@koolcandy

Copy link
Copy Markdown
Contributor Author

Added coverage for the post-wait fallback: when waitForShellIntegration completes but shell integration is still unavailable, runInTerminal now verifies that sendText is used. Local verification: npm run compile-tests, npm run compile, npm run lint, and the full unit suite with Node 22 (1872 passing, 8 pending).

@heejaechang

Copy link
Copy Markdown

Verification: The relevant tests could not be fully run in the isolated environment; this review is not fully verified.

Result: could-not-verify

Summary: The PR adds two unit tests covering delayed shell integration and the `sendText` fallback. No tests executed because the verification container could not start and local fallback was unauthorized. Runtime behavior therefore could not be verified.

Test runs: 1 not run

  • ⚠️ Not run | runInTerminal unit suite | npm run compile-tests && npm run unittest -- --grep "runInTerminal"
⚠️ runInTerminal unit suite diagnostic output
Container verification could not start: no trusted sandbox image is configured for microsoft/vscode-python-environments.

@edvilme Eduardo Villalpando Mello (edvilme) added the bug Issue identified by VS Code Team member as probable bug label Aug 28, 2026

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.

Hi! Thanks for the contribution!

@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.

@edvilme
Eduardo Villalpando Mello (edvilme) merged commit c8d26d9 into microsoft:main Aug 28, 2026
45 of 46 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.

4 participants