Skip to content

Commit acab474

Browse files
committed
fix(integrations): honour SPECIFY_COPILOT_EXTRA_ARGS in dispatch_command
`CopilotIntegration` is the only integration that overrides `dispatch_command` — it builds `cli_args` inline rather than going through `build_exec_args`. The previous commit wired `_apply_extra_args_env_var` into `build_exec_args` but workflow execution calls `dispatch_command`, so `SPECIFY_COPILOT_EXTRA_ARGS` was silently ignored at runtime. Add the hook in `dispatch_command` immediately after `cli_args = ["copilot", "-p", prompt]`, mirroring the placement in `build_exec_args` (between `-p prompt` and the canonical `--agent` / `--yolo` / `--model` / `--output-format` flags). `IntegrationBase.dispatch_command` already delegates to `build_exec_args`, so Codex, Devin, and Opencode continue to honour their respective env vars through inheritance — no further changes needed for them. Adds two end-to-end tests that monkeypatch `subprocess.run` and assert the env-var args reach the executed argv: - `test_copilot_dispatch_command_includes_extra_args` locks the bypass fix on the overridden path. - `test_codex_dispatch_command_includes_extra_args` locks the inherited-base-dispatch path for the other three integrations. Addresses Copilot review on #2596.
1 parent a17b951 commit acab474

2 files changed

Lines changed: 86 additions & 0 deletions

File tree

‎src/specify_cli/integrations/copilot/__init__.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,11 @@ def dispatch_command(
208208
prompt = args or ""
209209

210210
cli_args = ["copilot", "-p", prompt]
211+
# Honour SPECIFY_COPILOT_EXTRA_ARGS for real workflow runs.
212+
# `dispatch_command` builds cli_args inline rather than going
213+
# through `build_exec_args`, so the hook must be invoked here
214+
# too — otherwise the env var is silently ignored.
215+
self._apply_extra_args_env_var(cli_args)
211216
if not skills_mode:
212217
cli_args.extend(["--agent", agent_name])
213218
if _allow_all():

‎tests/integrations/test_extra_args.py‎

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,3 +274,84 @@ def test_copilot_integration_honours_extra_args(monkeypatch):
274274
"--output-format",
275275
"json",
276276
]
277+
278+
279+
# ---------------------------------------------------------------------------
280+
# `dispatch_command` end-to-end coverage
281+
#
282+
# Workflow execution calls `impl.dispatch_command(...)`, not
283+
# `build_exec_args` directly. `IntegrationBase.dispatch_command` delegates
284+
# to `build_exec_args` (so the override fixes above flow through), but
285+
# `CopilotIntegration` overrides `dispatch_command` and constructs
286+
# `cli_args` inline — the hook must be invoked there too or the env var
287+
# is silently ignored at workflow runtime. These tests monkeypatch
288+
# `subprocess.run` and assert the env-var args reach the executed argv.
289+
# ---------------------------------------------------------------------------
290+
291+
292+
class _RunCapture:
293+
"""Test double that captures argv passed to subprocess.run."""
294+
295+
def __init__(self):
296+
self.captured_args: list[str] | None = None
297+
298+
def __call__(self, args, **kwargs):
299+
self.captured_args = list(args)
300+
301+
class _Result:
302+
returncode = 0
303+
stdout = ""
304+
stderr = ""
305+
306+
return _Result()
307+
308+
309+
def test_copilot_dispatch_command_includes_extra_args(monkeypatch):
310+
"""Locks the bypass fix: `CopilotIntegration.dispatch_command`
311+
must honour `SPECIFY_COPILOT_EXTRA_ARGS`, not just `build_exec_args`.
312+
"""
313+
import subprocess
314+
315+
from specify_cli.integrations.copilot import CopilotIntegration
316+
317+
capture = _RunCapture()
318+
monkeypatch.setattr(subprocess, "run", capture)
319+
monkeypatch.setenv("SPECKIT_COPILOT_ALLOW_ALL_TOOLS", "0")
320+
monkeypatch.setenv(
321+
"SPECIFY_COPILOT_EXTRA_ARGS", "--allow-tool 'shell(echo)'"
322+
)
323+
324+
CopilotIntegration().dispatch_command(
325+
"speckit.plan", args="body", stream=False
326+
)
327+
328+
assert capture.captured_args is not None
329+
# Hook inserted between `-p prompt` and the canonical Copilot flags.
330+
p_idx = capture.captured_args.index("-p")
331+
agent_idx = capture.captured_args.index("--agent")
332+
extra_idx = capture.captured_args.index("--allow-tool")
333+
assert p_idx < extra_idx < agent_idx
334+
assert "shell(echo)" in capture.captured_args
335+
336+
337+
def test_codex_dispatch_command_includes_extra_args(monkeypatch):
338+
"""Lock the inherited `IntegrationBase.dispatch_command` path:
339+
Codex (and by transitivity Devin, Opencode) flow through
340+
`build_exec_args`, so the env var must reach argv at workflow
341+
runtime.
342+
"""
343+
import subprocess
344+
345+
from specify_cli.integrations.codex import CodexIntegration
346+
347+
capture = _RunCapture()
348+
monkeypatch.setattr(subprocess, "run", capture)
349+
monkeypatch.setenv("SPECIFY_CODEX_EXTRA_ARGS", "--sandbox read-only")
350+
351+
CodexIntegration().dispatch_command(
352+
"speckit.plan", args="body", stream=False
353+
)
354+
355+
assert capture.captured_args is not None
356+
assert "--sandbox" in capture.captured_args
357+
assert "read-only" in capture.captured_args

0 commit comments

Comments
 (0)