Skip to content

Commit 932cfb9

Browse files
committed
refactor(integrations): rename env var to SPECIFY_INTEGRATION_<KEY>_EXTRA_ARGS
Per maintainer request: scope the operator-injected env var to the integration subsystem by prepending `INTEGRATION_` to the key segment, so it does not collide with other Spec Kit env-var namespaces. Renames everywhere it appears: - Helper `IntegrationBase._apply_extra_args_env_var` env_name format and docstring (`base.py`). - Inline comment in `CopilotIntegration.dispatch_command`. - All `monkeypatch.setenv(...)` calls, docstrings, and the autouse fixture's scope filter in `tests/integrations/test_extra_args.py`. No behaviour change beyond the variable name. Default (env var unset) still byte-identical to before this PR. Addresses review on #2596.
1 parent acab474 commit 932cfb9

3 files changed

Lines changed: 30 additions & 26 deletions

File tree

‎src/specify_cli/integrations/base.py‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,14 +141,16 @@ def build_exec_args(
141141
return None
142142

143143
def _apply_extra_args_env_var(self, args: list[str]) -> None:
144-
"""Append `SPECIFY_<KEY>_EXTRA_ARGS` env-var value to *args*.
144+
"""Append `SPECIFY_INTEGRATION_<KEY>_EXTRA_ARGS` env-var value to *args*.
145145
146146
Operators can inject extra CLI flags into the spawned agent
147147
subprocess by setting an env var named for the integration key,
148-
e.g. `SPECIFY_CLAUDE_EXTRA_ARGS="--dangerously-skip-permissions"`.
148+
e.g. `SPECIFY_INTEGRATION_CLAUDE_EXTRA_ARGS="--dangerously-skip-permissions"`.
149+
The `INTEGRATION` segment scopes the variable to this subsystem
150+
so it does not collide with other Spec Kit env-var namespaces.
149151
Hyphens in the integration key are replaced with underscores
150152
and the key is uppercased
151-
(e.g. `kiro-cli` → `SPECIFY_KIRO_CLI_EXTRA_ARGS`).
153+
(e.g. `kiro-cli` → `SPECIFY_INTEGRATION_KIRO_CLI_EXTRA_ARGS`).
152154
153155
Useful in CI / non-interactive contexts where the spawned agent
154156
needs flags that change its prompt-handling behaviour.
@@ -159,7 +161,7 @@ def _apply_extra_args_env_var(self, args: list[str]) -> None:
159161
See issue #2595.
160162
"""
161163
env_name = (
162-
f"SPECIFY_{self.key.upper().replace('-', '_')}_EXTRA_ARGS"
164+
f"SPECIFY_INTEGRATION_{self.key.upper().replace('-', '_')}_EXTRA_ARGS"
163165
)
164166
extra = os.environ.get(env_name, "").strip()
165167
if extra:

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ def dispatch_command(
208208
prompt = args or ""
209209

210210
cli_args = ["copilot", "-p", prompt]
211-
# Honour SPECIFY_COPILOT_EXTRA_ARGS for real workflow runs.
211+
# Honour SPECIFY_INTEGRATION_COPILOT_EXTRA_ARGS for real workflow runs.
212212
# `dispatch_command` builds cli_args inline rather than going
213213
# through `build_exec_args`, so the hook must be invoked here
214214
# too — otherwise the env var is silently ignored.

‎tests/integrations/test_extra_args.py‎

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Tests for the per-integration `SPECIFY_<KEY>_EXTRA_ARGS` env-var hook.
1+
"""Tests for the per-integration `SPECIFY_INTEGRATION_<KEY>_EXTRA_ARGS` env-var hook.
22
33
The hook is implemented in `IntegrationBase._apply_extra_args_env_var`
44
and wired into every concrete `build_exec_args` —
@@ -79,10 +79,12 @@ class _NoCliStub(SkillsIntegration):
7979

8080
@pytest.fixture(autouse=True)
8181
def _clean_extra_args_env(monkeypatch):
82-
"""Strip any leaked SPECIFY_*_EXTRA_ARGS from the test env so a
83-
developer's shell setting doesn't pollute results."""
82+
"""Strip any leaked SPECIFY_INTEGRATION_*_EXTRA_ARGS from the test
83+
env so a developer's shell setting doesn't pollute results."""
8484
for key in list(os.environ):
85-
if key.startswith("SPECIFY_") and key.endswith("_EXTRA_ARGS"):
85+
if key.startswith("SPECIFY_INTEGRATION_") and key.endswith(
86+
"_EXTRA_ARGS"
87+
):
8688
monkeypatch.delenv(key, raising=False)
8789

8890

@@ -100,7 +102,7 @@ def test_env_var_set_flag_inserted_before_model_and_output_format(
100102
monkeypatch,
101103
):
102104
monkeypatch.setenv(
103-
"SPECIFY_CLAUDE_EXTRA_ARGS", "--dangerously-skip-permissions"
105+
"SPECIFY_INTEGRATION_CLAUDE_EXTRA_ARGS", "--dangerously-skip-permissions"
104106
)
105107
args = _ClaudeStub().build_exec_args("hello prompt", model="sonnet")
106108
assert args == [
@@ -117,7 +119,7 @@ def test_env_var_set_flag_inserted_before_model_and_output_format(
117119

118120
def test_env_var_multi_token_parsed_via_shlex(monkeypatch):
119121
monkeypatch.setenv(
120-
"SPECIFY_CLAUDE_EXTRA_ARGS",
122+
"SPECIFY_INTEGRATION_CLAUDE_EXTRA_ARGS",
121123
"--dangerously-skip-permissions --max-turns 3",
122124
)
123125
args = _ClaudeStub().build_exec_args("p")
@@ -135,24 +137,24 @@ def test_env_var_multi_token_parsed_via_shlex(monkeypatch):
135137

136138
def test_env_var_empty_or_whitespace_is_noop(monkeypatch):
137139
"""An env var set to '' or ' ' is treated as unset."""
138-
monkeypatch.setenv("SPECIFY_CLAUDE_EXTRA_ARGS", " ")
140+
monkeypatch.setenv("SPECIFY_INTEGRATION_CLAUDE_EXTRA_ARGS", " ")
139141
args = _ClaudeStub().build_exec_args("p")
140142
assert args == ["claude", "-p", "p", "--output-format", "json"]
141143

142144

143145
def test_other_integration_env_var_ignored(monkeypatch):
144-
"""`SPECIFY_GEMINI_EXTRA_ARGS` set must NOT leak into
146+
"""`SPECIFY_INTEGRATION_GEMINI_EXTRA_ARGS` set must NOT leak into
145147
Claude's argv (per-integration scoping)."""
146-
monkeypatch.setenv("SPECIFY_GEMINI_EXTRA_ARGS", "--gemini-only-flag")
148+
monkeypatch.setenv("SPECIFY_INTEGRATION_GEMINI_EXTRA_ARGS", "--gemini-only-flag")
147149
args = _ClaudeStub().build_exec_args("p")
148150
assert args == ["claude", "-p", "p", "--output-format", "json"]
149151

150152

151153
def test_key_normalization_hyphen_to_underscore_uppercase(monkeypatch):
152-
"""`kiro-cli` key looks up `SPECIFY_KIRO_CLI_EXTRA_ARGS`
154+
"""`kiro-cli` key looks up `SPECIFY_INTEGRATION_KIRO_CLI_EXTRA_ARGS`
153155
(hyphens replaced with underscores, then uppercased)."""
154156
monkeypatch.setenv(
155-
"SPECIFY_KIRO_CLI_EXTRA_ARGS", "--some-kiro-flag"
157+
"SPECIFY_INTEGRATION_KIRO_CLI_EXTRA_ARGS", "--some-kiro-flag"
156158
)
157159
args = _KiroCliStub().build_exec_args("p")
158160
assert args == [
@@ -168,7 +170,7 @@ def test_key_normalization_hyphen_to_underscore_uppercase(monkeypatch):
168170
def test_requires_cli_false_returns_none(monkeypatch):
169171
"""`requires_cli: False` short-circuits to None — the env-var
170172
hook is never reached and no argv is built."""
171-
monkeypatch.setenv("SPECIFY_NO_CLI_EXTRA_ARGS", "--should-not-appear")
173+
monkeypatch.setenv("SPECIFY_INTEGRATION_NO_CLI_EXTRA_ARGS", "--should-not-appear")
172174
assert _NoCliStub().build_exec_args("p") is None
173175

174176

@@ -186,7 +188,7 @@ def test_requires_cli_false_returns_none(monkeypatch):
186188
def test_codex_integration_honours_extra_args(monkeypatch):
187189
from specify_cli.integrations.codex import CodexIntegration
188190

189-
monkeypatch.setenv("SPECIFY_CODEX_EXTRA_ARGS", "--sandbox read-only")
191+
monkeypatch.setenv("SPECIFY_INTEGRATION_CODEX_EXTRA_ARGS", "--sandbox read-only")
190192
args = CodexIntegration().build_exec_args("p", model="gpt-5")
191193
assert args == [
192194
"codex",
@@ -203,15 +205,15 @@ def test_codex_integration_honours_extra_args(monkeypatch):
203205
def test_devin_integration_honours_extra_args(monkeypatch):
204206
from specify_cli.integrations.devin import DevinIntegration
205207

206-
monkeypatch.setenv("SPECIFY_DEVIN_EXTRA_ARGS", "--no-confirm")
208+
monkeypatch.setenv("SPECIFY_INTEGRATION_DEVIN_EXTRA_ARGS", "--no-confirm")
207209
args = DevinIntegration().build_exec_args("p")
208210
assert args == ["devin", "-p", "p", "--no-confirm"]
209211

210212

211213
def test_opencode_integration_honours_extra_args(monkeypatch):
212214
from specify_cli.integrations.opencode import OpencodeIntegration
213215

214-
monkeypatch.setenv("SPECIFY_OPENCODE_EXTRA_ARGS", "--quiet")
216+
monkeypatch.setenv("SPECIFY_INTEGRATION_OPENCODE_EXTRA_ARGS", "--quiet")
215217
args = OpencodeIntegration().build_exec_args("p")
216218
assert args == [
217219
"opencode",
@@ -231,13 +233,13 @@ def test_opencode_extra_args_cannot_clobber_prompt_derived_command(
231233
repeated-flag CLI semantics (last value typically takes precedence).
232234
233235
Locks against the regression where an operator setting
234-
``SPECIFY_OPENCODE_EXTRA_ARGS="--command malicious"`` could redirect
236+
``SPECIFY_INTEGRATION_OPENCODE_EXTRA_ARGS="--command malicious"`` could redirect
235237
a slash-prefixed prompt to a different command.
236238
"""
237239
from specify_cli.integrations.opencode import OpencodeIntegration
238240

239241
monkeypatch.setenv(
240-
"SPECIFY_OPENCODE_EXTRA_ARGS", "--command operator-override"
242+
"SPECIFY_INTEGRATION_OPENCODE_EXTRA_ARGS", "--command operator-override"
241243
)
242244
args = OpencodeIntegration().build_exec_args("/speckit body text")
243245
# Prompt-derived "--command speckit" appears AFTER the
@@ -262,7 +264,7 @@ def test_copilot_integration_honours_extra_args(monkeypatch):
262264
# Disable --yolo so the argv shape stays deterministic.
263265
monkeypatch.setenv("SPECKIT_COPILOT_ALLOW_ALL_TOOLS", "0")
264266
monkeypatch.setenv(
265-
"SPECIFY_COPILOT_EXTRA_ARGS", "--allow-tool 'shell(echo)'"
267+
"SPECIFY_INTEGRATION_COPILOT_EXTRA_ARGS", "--allow-tool 'shell(echo)'"
266268
)
267269
args = CopilotIntegration().build_exec_args("p")
268270
assert args == [
@@ -308,7 +310,7 @@ class _Result:
308310

309311
def test_copilot_dispatch_command_includes_extra_args(monkeypatch):
310312
"""Locks the bypass fix: `CopilotIntegration.dispatch_command`
311-
must honour `SPECIFY_COPILOT_EXTRA_ARGS`, not just `build_exec_args`.
313+
must honour `SPECIFY_INTEGRATION_COPILOT_EXTRA_ARGS`, not just `build_exec_args`.
312314
"""
313315
import subprocess
314316

@@ -318,7 +320,7 @@ def test_copilot_dispatch_command_includes_extra_args(monkeypatch):
318320
monkeypatch.setattr(subprocess, "run", capture)
319321
monkeypatch.setenv("SPECKIT_COPILOT_ALLOW_ALL_TOOLS", "0")
320322
monkeypatch.setenv(
321-
"SPECIFY_COPILOT_EXTRA_ARGS", "--allow-tool 'shell(echo)'"
323+
"SPECIFY_INTEGRATION_COPILOT_EXTRA_ARGS", "--allow-tool 'shell(echo)'"
322324
)
323325

324326
CopilotIntegration().dispatch_command(
@@ -346,7 +348,7 @@ def test_codex_dispatch_command_includes_extra_args(monkeypatch):
346348

347349
capture = _RunCapture()
348350
monkeypatch.setattr(subprocess, "run", capture)
349-
monkeypatch.setenv("SPECIFY_CODEX_EXTRA_ARGS", "--sandbox read-only")
351+
monkeypatch.setenv("SPECIFY_INTEGRATION_CODEX_EXTRA_ARGS", "--sandbox read-only")
350352

351353
CodexIntegration().dispatch_command(
352354
"speckit.plan", args="body", stream=False

0 commit comments

Comments
 (0)