Skip to content

fix: sweep remaining env-mutating unit tests for hermeticity#445

Draft
BunsDev wants to merge 1 commit into
mainfrom
fix/test-hermeticity-sweep
Draft

fix: sweep remaining env-mutating unit tests for hermeticity#445
BunsDev wants to merge 1 commit into
mainfrom
fix/test-hermeticity-sweep

Conversation

@BunsDev

@BunsDev BunsDev commented Jul 21, 2026

Copy link
Copy Markdown
Member

Summary

Follow-up to #440, completing the sweep: zero env_lock/EnvVarGuard/set_var/remove_var remain in coven-cli (grep -rn clean). All conversions use dependency injection; public signatures and production behavior are unchanged.

harness.rs (~45 lock-guarded tests → lock-free)

  • New AdapterEnv snapshot (COVEN_HOME, COVEN_HARNESS_ADAPTER_MANIFEST, COVEN_HARNESS_ADAPTER_DIRS) taken once per resolution and threaded through external_adapter_manifest_sources / external_harness_specs / configured-spec helpers; pub fns are thin from_process() wrappers.
  • Command construction split: env-free command_parts_with_specs(specs, …, codex_json, claude_bypass_enabled, resolve_program) holds the logic; the inner wrapper reads process env. Dropped the now-redundant with_claude_permission_flags variant.
  • harness_available_with(executable, engine_resolves) seam; engine test injects engine::resolve_from.
  • Tests inject built-in/external specs, AdapterEnv, and an identity program resolver — side benefit: program == asserts no longer depend on host PATH (notably flaky-prone on Windows).

privacy.rs

  • PrivacyEnv snapshot + single apply_env_overrides, deduplicating the copy-pasted override block while preserving the original file → env → settings → env precedence. Added retention-days override coverage (positive, zero, non-numeric).

main.rs → paths.rs

  • Moved the USERPROFILE fallback test onto the already-injectable coven_home_from_env seam; deleted the last env_lock/EnvVarGuard helpers from main.rs.

api.rs (latent env-dependent failure found by this sweep)

  • launch_request_with_unknown_harness_returns_400_upfront_no_session_row used hermes — a real installable adapter — so on any machine with local adapter recipes (~/.coven/adapters) the launch succeeded (201 ≠ 400). Reproduced on current main; CI only passes because runners are bare. Switched to a synthetic id so the test is hermetic everywhere.

Verification

  • cargo fmt --check
  • cargo clippy --workspace --all-targets --locked -- -D warnings ✅ (0 warnings)
  • cargo test --workspace --locked ✅ 1269 passed / 0 failed
  • python scripts/check-secrets.py

Readiness

  • Scoped to test hermeticity; no behavior change intended. Riskiest bit is the harness.rs command-construction split — covered by the full existing test suite routed through the new seam.

Follow-up to #440: remove every env_lock/EnvVarGuard mutex-and-mutate
pattern left in coven-cli by injecting dependencies instead of writing
to process env. Public signatures and production behavior unchanged.

- harness.rs: snapshot adapter env once via AdapterEnv (COVEN_HOME,
  manifest/dirs vars) and thread it through spec resolution; split
  command construction into env-free command_parts_with_specs taking
  codex_json/claude_bypass/resolve_program; add harness_available_with.
  Tests inject specs, AdapterEnv, and an identity program resolver —
  the ~45 formerly lock-guarded tests now run lock-free and parallel,
  and program asserts no longer depend on host PATH.
- privacy.rs: snapshot env once via PrivacyEnv + apply_env_overrides
  (preserving file → env → settings → env precedence); tests inject
  PrivacyEnv; add retention-days override coverage.
- main.rs → paths.rs: move the USERPROFILE fallback test onto the
  already-injectable coven_home_from_env seam; delete the last
  env_lock/EnvVarGuard helpers.
- api.rs: launch validation reads configured harnesses from process
  env, so the unknown-harness test used a real installable adapter id
  (hermes) and failed 201!=400 on any machine with local adapter
  recipes; use a synthetic id so the test is hermetic everywhere.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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