fix(events): stop falling back to a fake "pwsh" argv when no launcher exists - #4340
Open
Noor-ul-ain001 wants to merge 1 commit into
Open
fix(events): stop falling back to a fake "pwsh" argv when no launcher exists#4340Noor-ul-ain001 wants to merge 1 commit into
Noor-ul-ain001 wants to merge 1 commit into
Conversation
… exists
`_resolve_event_command_argv`'s `ps` branch did:
launcher = shutil.which("pwsh") or shutil.which("powershell") or "pwsh"
When neither `pwsh` nor `powershell` is on PATH, this silently returns
`["pwsh", "-File", <script>, ...]` instead of degrading to "no runnable
script" (`None`) like every other failure branch in this same function
(unparseable frontmatter, non-mapping scripts, unresolvable script path,
etc.). `subprocess.run()` then raises `FileNotFoundError` trying to exec a
binary that was just proven absent, which `resolve_and_run_event_command`'s
generic exception handler reports as a confusing
"Event command X error: [Errno 2] No such file or directory: 'pwsh'"
(exit code 2) instead of the clean "No script found for event command"
warning (exit code 0) every other missing-script case gets.
This function is explicitly documented as mirroring the generated
dispatcher's own stdlib-only `_resolve_argv` (same file), which already
gets this right: `if not launcher: return None`. The two had drifted apart.
Fix: mirror that behavior — return `None` when neither launcher is found,
instead of fabricating an argv naming a binary that doesn't exist.
## Test plan
- Added `test_ps_variant_returns_none_when_no_launcher_available` to
`tests/integrations/test_events.py::TestCommandRunner`: with
`shutil.which` mocked to return `None` for every name, the resolver must
return `None` rather than an argv naming a nonexistent `pwsh`.
- Verified the test fails without the fix (test-the-test): it asserted
`argv is None` but got `['pwsh', '-File', '.../boot.ps1']` — reproducing
the exact bug.
- Ran the full `tests/integrations/test_events.py` suite: 118 passed, 4
pre-existing Windows symlink-elevation failures (need admin rights,
unrelated to this change), 1 skipped.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PJHJ2dHP2RVCNncHqN8Qm9
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
_resolve_event_command_argv'spsbranch did:pwshnorpowershellis on PATH, this silently returns["pwsh", "-File", <script>, ...]instead of degrading to "no runnable script" (None) like every other failure branch in this same function (unparseable frontmatter, non-mapping scripts, unresolvable script path, etc.).subprocess.run()then raisesFileNotFoundErrortrying to exec a binary that was just proven absent, whichresolve_and_run_event_command's generic exception handler reports as a confusingEvent command X error: [Errno 2] No such file or directory: 'pwsh'(exit code 2) instead of the cleanNo script found for event commandwarning (exit code 0) every other missing-script case gets._resolve_argv(same file), which already gets this right:if not launcher: return None. The two had drifted apart.Nonewhen neither launcher is found, instead of fabricating an argv naming a binary that doesn't exist.Test plan
test_ps_variant_returns_none_when_no_launcher_availabletotests/integrations/test_events.py::TestCommandRunner: withshutil.whichmocked to returnNonefor every name, the resolver must returnNonerather than an argv naming a nonexistentpwsh.argv is Nonebut got['pwsh', '-File', '.../boot.ps1']— reproducing the exact bug.tests/integrations/test_events.pysuite: 118 passed, 4 pre-existing Windows symlink-elevation failures (need admin rights, unrelated to this change), 1 skipped.Co-Authored-By: Claude Sonnet 5 noreply@anthropic.com
https://claude.ai/code/session_01PJHJ2dHP2RVCNncHqN8Qm9