Skip to content

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
github:mainfrom
Noor-ul-ain001:fix/ps-argv-missing-launcher-fallback
Open

fix(events): stop falling back to a fake "pwsh" argv when no launcher exists#4340
Noor-ul-ain001 wants to merge 1 commit into
github:mainfrom
Noor-ul-ain001:fix/ps-argv-missing-launcher-fallback

Conversation

@Noor-ul-ain001

Copy link
Copy Markdown
Contributor

Summary

  • _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

https://claude.ai/code/session_01PJHJ2dHP2RVCNncHqN8Qm9

… 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
@Noor-ul-ain001
Noor-ul-ain001 requested a review from mnriem as a code owner August 26, 2026 12:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant