Skip to content

💫 Toolkit to help you get started with SDD or any other process!

fix(workflows): dispatch prompt steps via the resolved executable (#3793)

Ali jawwadd99170fb5ef2
diff --git a/src/specify_cli/workflows/steps/prompt/__init__.py b/src/specify_cli/workflows/steps/prompt/__init__.py
index f8c2de3b3..5bf10fbff 100644
--- a/src/specify_cli/workflows/steps/prompt/__init__.py
+++ b/src/specify_cli/workflows/steps/prompt/__init__.py
@@ -169,6 +169,17 @@ class PromptStep(StepBase):
if not exec_args:
return None
+ # Windows: ``subprocess.run`` calls ``CreateProcess``, which does not
+ # consult ``PATHEXT``, so a bare command name like ``claude`` installed
+ # as ``claude.cmd`` (the usual npm shim layout) fails with
+ # ``WinError 2``. That OSError is swallowed below and reported as "CLI
+ # not found or not installed" -- even though the preflight above just
+ # found it. Reuse the already-resolved path so the shim is executed,
+ # mirroring ``IntegrationBase.dispatch_command``, which the ``command``
+ # step already goes through. On POSIX this is the same executable.
+ if fallback_cli_path:
+ exec_args = [fallback_cli_path, *exec_args[1:]]
+
import subprocess
project_root = (
diff --git a/tests/test_workflows.py b/tests/test_workflows.py
index 9a6833eb7..6e191fe79 100644
--- a/tests/test_workflows.py
+++ b/tests/test_workflows.py
@@ -1486,6 +1486,41 @@ class TestPromptStep:
assert result.output["dispatched"] is True
assert result.output["exit_code"] == 0
+ def test_try_dispatch_executes_the_resolved_executable(self, tmp_path):
+ """argv[0] must be the shutil.which-resolved path, not the bare name.
+
+ On Windows subprocess.run calls CreateProcess, which ignores PATHEXT, so
+ a bare `claude` installed as `claude.cmd` (the usual npm shim) raises
+ WinError 2. That OSError is swallowed and reported as "CLI not found or
+ not installed" even though the preflight which() just found it, while
+ the `command` step -- which goes through
+ IntegrationBase.dispatch_command -- resolves argv[0] and works.
+ """
+ from unittest.mock import patch, MagicMock
+ from specify_cli.workflows.steps.prompt import PromptStep
+ from specify_cli.workflows.base import StepContext, StepStatus
+
+ step = PromptStep()
+ ctx = StepContext(default_integration="claude", project_root=str(tmp_path))
+ config = {"id": "test", "type": "prompt", "prompt": "hello"}
+
+ resolved = r"C:\tools\claude.CMD"
+ mock_result = MagicMock()
+ mock_result.returncode = 0
+ mock_result.stdout = ""
+ mock_result.stderr = ""
+
+ with patch(
+ "specify_cli.workflows.steps.prompt.shutil.which",
+ lambda name: resolved,
+ ), patch("subprocess.run", return_value=mock_result) as run:
+ result = step.execute(config, ctx)
+
+ assert result.status == StepStatus.COMPLETED
+ assert result.output["dispatched"] is True
+ argv = run.call_args.args[0]
+ assert argv[0] == resolved, argv
+
def test_dispatch_with_mock_cli(self, tmp_path):
from unittest.mock import patch, MagicMock
from specify_cli.workflows.steps.prompt import PromptStep