← Back to PRs

#16658: test: isolate env-dependent gateway/auth fixtures

by sauerdaniel open 2026-02-15 00:16 View on GitHub →
gateway size: S
## Summary - isolate browser profile CRUD tests from host gateway token/password env vars - isolate runtime auth test from host token/password env vars - ensure `withTempHome` clears/restores `OPENCLAW_AGENT_DIR` and `PI_CODING_AGENT_DIR` so auth-profile tests use temp home paths ## Why Several tests were reading host env vars (`OPENCLAW_GATEWAY_TOKEN`, `OPENCLAW_AGENT_DIR`) and became non-deterministic across machines/runners. ## Validation - `npx vitest run src/browser/server.post-tabs-open-profile-unknown-returns-404.test.ts src/gateway/server-runtime-config.test.ts src/infra/provider-usage.auth.normalizes-keys.test.ts` ## AI-Assisted Yes — implemented and reviewed with AI assistance. <!-- greptile_comment --> <h3>Greptile Summary</h3> Properly isolated environment-dependent test fixtures from host environment variables. The changes ensure `OPENCLAW_GATEWAY_TOKEN`, `OPENCLAW_GATEWAY_PASSWORD`, `OPENCLAW_AGENT_DIR`, and `PI_CODING_AGENT_DIR` don't leak into tests, preventing non-deterministic behavior across different machines and CI runners. - Extended `withTempHome` helper to snapshot/restore `OPENCLAW_AGENT_DIR` and `PI_CODING_AGENT_DIR` - Added proper cleanup to browser profile CRUD test fixtures - Wrapped auth test assertions in try-finally to guarantee env restoration <h3>Confidence Score: 5/5</h3> - This PR is safe to merge with minimal risk - The changes are straightforward test infrastructure improvements that add proper environment isolation. All modifications follow consistent patterns: snapshot env vars before modification, restore them in cleanup. The code doesn't affect production logic, only test fixtures. The PR includes validation command showing the specific tests that were fixed. - No files require special attention <sub>Last reviewed commit: a1bc4f5</sub> <!-- greptile_other_comments_section --> <!-- /greptile_comment --> ## Local Validation ```bash pnpm build && pnpm check && pnpm test ``` Build passes. Lint passes. 4743/4747 tests pass (4 pre-existing env-isolation failures fixed by #16658). ## Local Validation ```bash pnpm build && pnpm check && pnpm test ``` Build passes. Lint passes. **All tests pass** (including the 4 that were failing without this fix: `provider-usage.auth.normalizes-keys.test.ts`).

Most Similar PRs