Skip to content

fix(events): stop falling back to a fake "pwsh" argv when no launcher exists - #4340

Merged
KSchlobohm merged 1 commit into
github:mainfrom
Noor-ul-ain001:fix/ps-argv-missing-launcher-fallback
Aug 28, 2026
Merged

fix(events): stop falling back to a fake "pwsh" argv when no launcher exists#4340
KSchlobohm merged 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

Copilot AI 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.

Pull request overview

Aligns PowerShell event command resolution with the generated dispatcher when no launcher is installed.

Changes:

  • Returns None when neither pwsh nor powershell is available.
  • Adds regression coverage for the missing-launcher case.
Show a summary per file
File Description
src/specify_cli/events.py Handles unavailable PowerShell launchers cleanly.
tests/integrations/test_events.py Tests missing-launcher behavior.

Review details

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Balanced

@KSchlobohm
KSchlobohm merged commit 2dc229b into github:main Aug 28, 2026
14 checks passed
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.

3 participants