Skip to content

test(harness): regression-guard run_cli parent env propagation#544

Merged
AbirAbbas merged 1 commit intomainfrom
test/run-cli-env-propagation
May 6, 2026
Merged

test(harness): regression-guard run_cli parent env propagation#544
AbirAbbas merged 1 commit intomainfrom
test/run-cli-env-propagation

Conversation

@AbirAbbas
Copy link
Copy Markdown
Contributor

Summary

Adds a small unit test asserting that `run_cli` propagates parent process env to subprocesses — the contract that lets CLI-based providers (opencode, codex, gemini) inherit deployment-level env vars like `OPENCODE_ENABLE_EXA` and `EXA_API_KEY`.

Why

Opencode's built-in `websearch` / `webfetch` tools are gated on env vars. Reasoners running through agentfield's harness rely on those vars reaching the opencode subprocess, which works only because `run_cli` does:

```python
merged_env = {**os.environ}
if env:
merged_env.update(env)
```

If a refactor ever drops that `{**os.environ}` line, every CLI provider silently stops seeing parent env and tools that depend on them break across every consumer. This test catches that regression early.

What's tested

  1. Parent-process env reaches the subprocess
  2. Explicit `env=` arg overrides parent on conflict
  3. Explicit env layers additively on top of parent env (both reach the subprocess)
  4. `env=None` (default) still propagates parent env

Tests are pure — `bash -c "echo $VAR"`, no network, no fixtures. Run in <1s.

🤖 Generated with Claude Code

Adds a small unit test asserting that ``run_cli``:

1. Propagates parent process env to the subprocess (the contract that lets
   CLI providers inherit deployment-level vars like OPENCODE_ENABLE_EXA /
   EXA_API_KEY)
2. Lets explicit per-call env override parent env on conflict
3. Layers explicit env on top of parent env additively
4. Inherits parent env even when the explicit env arg is None

Motivates why this matters: opencode's built-in websearch / webfetch tools
are gated on env vars (OPENCODE_ENABLE_EXA + EXA_API_KEY). They reach the
opencode subprocess only because run_cli's ``merged_env = {**os.environ}``
preserves parent env. If a refactor ever drops that line, every CLI
provider quietly stops seeing deployment env and tools that depend on
them silently break across every consumer (SWE-AF, PR-AF, github-buddy).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@AbirAbbas AbirAbbas requested a review from a team as a code owner May 6, 2026 20:49
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 6, 2026

Performance

SDK Memory Δ Latency Δ Tests Status
Python 9.4 KB +4% 0.31 µs -11%

✓ No regressions detected

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 6, 2026

📊 Coverage gate

Thresholds from .coverage-gate.toml: per-surface ≥ 86%, aggregate ≥ 88%, max per-surface regression ≤ 1.0 pp, max aggregate regression ≤ 0.50 pp.

Surface Current Baseline Δ
control-plane 87.40% 87.30% ↑ +0.10 pp 🟡
sdk-go 91.90% 90.70% ↑ +1.20 pp 🟢
sdk-python 93.66% 93.63% ↑ +0.03 pp 🟢
sdk-typescript 92.68% 92.56% ↑ +0.12 pp 🟢
web-ui 89.81% 90.01% ↓ -0.20 pp 🟡
aggregate 88.92% 89.01% ↓ -0.09 pp 🟡

✅ Gate passed

No surface regressed past the allowed threshold and the aggregate stayed above the floor.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 6, 2026

📐 Patch coverage gate

Threshold: 80% on lines this PR touches vs origin/main (from .coverage-gate.toml:thresholds.min_patch).

Surface Touched lines Patch coverage Status
control-plane 0 ➖ no changes
sdk-go 0 ➖ no changes
sdk-python 0 ➖ no changes
sdk-typescript 0 ➖ no changes
web-ui 0 ➖ no changes

✅ Patch gate passed

Every surface whose lines were touched by this PR has patch coverage at or above the threshold.

@AbirAbbas AbirAbbas merged commit 04cacd1 into main May 6, 2026
37 of 39 checks passed
@AbirAbbas AbirAbbas deleted the test/run-cli-env-propagation branch May 6, 2026 20:58
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.

1 participant