Repository navigation
feat(events): add portable hook interpreter fallback and pre-flight checks - #5721
Open
dlwlgnsrhy wants to merge 2 commits into
Open
dlwlgnsrhy wants to merge 2 commits into
dlwlgnsrhy wants to merge 2 commits into
Conversation
…hecks Emit portable Python 3 fallback chains in generated event hooks so hooks keep working across Windows PowerShell 5.1 (.venv -> python -> py -3), POSIX sh (.venv -> python3 -> python -> py -3), host/cmd Windows targets (py -3 when python is absent or a Microsoft Store stub), and OpenCode's TypeScript plugin without hard-coding host-specific paths. Add shared interpreter availability helpers (check_hook_interpreter, check_integration_hook_interpreter, preflight_hook_interpreter) that match hook runtime resolution for PATH commands (including Windows Store stub rejection), project-relative .venv paths, and absolute paths: - Warn with actionable remediation during hook install/upgrade/refresh. - Fail fast before spawning agent CLIs in workflow command/prompt steps that depend on hooks. - Expose a diagnostic 'specify event check' CLI command with --json support.
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Windows checks can execute untrusted project-controlled binaries without consent, while unresolved interpreter fallback mismatches and Windows test flaws undermine reliability.
12 open issues
Require trust before probing project-controlled executables · New Skip POSIX shell fixture on Windows · New Isolate PATH in the Windows py-only test · New Probe POSIX PATH candidates before accepting them · New Respect installed hook versions when choosing interpreter fallbacks · New Windows checker misses later working PATH interpreters · New Serialize malformed integration state as a structured error · New Probe venv interpreter before selecting it · New Validate venv interpreters before selecting them · New Check installed hooks when project_root is omitted · New Add an MCP inventory disposition for event.check · New Select Windows PowerShell explicitly for compatibility tests · New
What changed in this PR
Adds portable Python resolution and early diagnostics for Spec Kit event hooks, extending #5619 beyond #5714’s install-only warnings.
Changes:
- Adds POSIX, PowerShell 5.1, and OpenCode interpreter fallbacks.
- Adds installation warnings and
specify event check. - Adds workflow preflight checks and resolution/runtime tests.
AI-generated review by GitHub Copilot (model unknown; automated) for the requesting contributor.
| File | Description |
|---|---|
tests/workflows/test_hook_preflight.py |
Tests command and prompt preflight behavior. |
tests/specify_cli/events/test_hook_interpreter.py |
Tests resolution, fallback execution, and warnings. |
tests/specify_cli/events/test_events.py |
Updates Copilot hook-generation expectations. |
tests/specify_cli/events/test_command_check.py |
Tests diagnostic CLI and JSON output. |
src/specify_cli/workflows/step/prompt/__init__.py |
Checks interpreters before prompt dispatch. |
src/specify_cli/workflows/step/command/__init__.py |
Checks interpreters before command dispatch. |
src/specify_cli/workflows/step/_hook_preflight.py |
Shares hook-dependency and failure handling. |
src/specify_cli/events/command_check.py |
Adds the interpreter diagnostic command. |
src/specify_cli/events/__init__.py |
Implements fallbacks, availability checks, and warnings. |
Review effort: Max (adaptive)
…tory - Avoid executing untrusted project-controlled or explicit hook binaries during static interpreter checks without explicit opt-in (allow_probe_untrusted=False); validate regular files and reject Windows Store AppExecutionAlias stubs statically. - Probe POSIX portable fallback PATH candidates (including py -3) with stdin=DEVNULL while preserving fixed-command lookup semantics. - Enumerate all Windows PATH/PATHEXT matches for the portable PowerShell fallback chain so Store aliases preceding a working python.exe do not falsely fail preflight. - Honor inspect_installed for Copilot hooks and OpenCode plugins, using the portable fallback chain only when the installed config or plugin implements it. - Probe .venv Python binaries before selection in both PowerShell 5.1 and POSIX sh generated fallback commands so damaged venvs or directories fall through to PATH fallbacks. - Replace _read_integration_json in check_project_event_interpreters with try_read_integration_json and structured EventCheckError so 'specify event check --json' serializes malformed state cleanly. - Resolve Path.cwd() when context.project_root is omitted in workflow hook preflight. - Add explicit hierarchy-owned MCP inventory dispositions for 'specify event' (event.check, event.run) wired into create_server with parity tests. - Gate POSIX /bin/sh test fixture on non-Windows executable /bin/sh, prefer Windows PowerShell 5.1 over pwsh on Windows, and isolate PATH in the Windows py-launcher execution test.
Contributor
Author
|
Addressed all 12 review findings in
Verification: 4,118 passed across events/preflight/MCP/integrations, 1,014 passed across |
Copilot stopped reviewing on behalf of
dlwlgnsrhy due to an error
December 6, 2026 14:19
This branch has not been deployed
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
Addresses #5619 by implementing portable interpreter fallback for generated event hooks, unified interpreter availability checks (PATH, project-relative
.venv, and absolute paths), install/upgrade/refresh diagnostics, aspecify event checkCLI command, and workflow dispatch pre-flight checks.(Note: #5714 implements install-time warnings only and explicitly leaves portable Windows
py -3fallback and workflow dispatch pre-flight out of scope; this PR implements the full #5619 scope end-to-end.)Changes
1. Portable Runtime Fallback (
src/specify_cli/events/__init__.py)copilot-jsonpowershell/target_os="windows"): emits a PowerShell 5.1–compatible& { ... }command (no&&/||/??,$null |stdin isolation on probe checks,$global:LASTEXITCODEpropagation,Get-Command -Allfiltering out Microsoft Store AppExecutionAlias stubs) trying.venv\Scripts\python.exe->python->py -3without hard-coding host-specific paths.sh(copilot-jsonbash/target_os="posix"): emitsset -- <quoted_args>; if ... exec ...trying.venv/bin/python->python3->python->py -3(covering Git Bash on Windows) with</dev/nullon probes andexecpreserving stdin and exit codes.ts-plugin: preserves project.venvpreference, falls back to portablepy -3on Windows whenpython3/pythonare absent or Store stubs, and avoids baking ephemeral hostsys.executablepaths into generated configs.2. Shared Interpreter Resolution & Install Diagnostics (
src/specify_cli/events/__init__.py,src/specify_cli/events/command_check.py)HookInterpreterStatus,HookInterpreterError,check_hook_interpreter,check_integration_hook_interpreter,preflight_hook_interpreter, andcheck_project_event_interpreters.IntegrationBase._interpreter_runsStore-stub rejection on Windows), project-relative.venvpaths againstproject_root, absolute paths, andpy -3.install_integration_eventswarns onstderrwith the missing interpreter, tried candidates, and exact remedy (add Python to PATH, or create a project.venvand rerunspecify integration upgrade <key>) without failing installation.specify event check [--integration KEY] [--json]diagnostic command.3. Workflow Dispatch Pre-Flight (
src/specify_cli/workflows/step/_hook_preflight.py,command/__init__.py,prompt/__init__.py)project_rootor the step declares hook-dependent config (additional_context), failing fast asStepStatus.FAILED(dispatched=False) with an actionable error message. Projects without hooks skip the check.Verification
pytest tests/specify_cli/events/ tests/workflows/test_hook_preflight.py tests/integrations/test_base.py tests/integrations/test_integration_vibe.py -q: 574 passed, 1 skipped (conditional live PowerShell test skipped on macOS; PowerShell 5.1 syntax/quoting invariants and live/bin/shfallback execution tests pass; Windows CI exercises the live PowerShell test).pytest -n auto tests/specify_cli/events/ tests/integrations/ tests/workflows/ tests/test_workflows.py tests/specify_cli/workflows/ -q: 7,291 passed, 38 skipped (0 failed).ruff@0.15.0 check src tests: All checks passed.