#20404: test: isolate gateway auth env vars in test runner
scripts
size: XS
## Summary
- **Problem**: Tests fail when running locally with `OPENCLAW_GATEWAY_TOKEN` or `OPENCLAW_GATEWAY_PASSWORD` environment variables set. Specifically:
- `src/browser/server.post-tabs-open-profile-unknown-returns-404.test.ts` - expects 400 but gets 401
- `src/gateway/server-runtime-config.test.ts` - expects rejection but gets resolved config with token
- **Why it matters**: Developers who have gateway auth env vars set for local development cannot run tests successfully
- **What changed**: Strip `OPENCLAW_GATEWAY_TOKEN` and `OPENCLAW_GATEWAY_PASSWORD` from the environment before spawning test processes in `scripts/test-parallel.mjs`
- **What did NOT change**: Individual test files remain unchanged; this elevates the isolation pattern to the test runner level
## Change Type
- [ ] Bug fix
- [ ] Feature
- [ ] Refactor
- [ ] Docs
- [ ] Security hardening
- [x] Chore/infra
## Scope
- [ ] Gateway / orchestration
- [ ] Skills / tool execution
- [ ] Auth / tokens
- [ ] Memory / storage
- [ ] Integrations
- [ ] API / contracts
- [ ] UI / DX
- [x] CI/CD / infra
## Linked Issue/PR
None
## User-visible / Behavior Changes
None
## Security Impact
- New permissions/capabilities? (`No`)
- Secrets/tokens handling changed? (`No`)
- New/changed network calls? (`No`)
- Command/tool execution surface changed? (`No`)
- Data access scope changed? (`No`)
## Repro + Verification
### Environment
- OS: macOS / Linux
- Runtime: Node.js 22+
### Steps
1. Set gateway auth env vars: `export OPENCLAW_GATEWAY_TOKEN=test`
2. Run tests: `pnpm test -- --run src/gateway/server-runtime-config.test.ts`
3. Observe failures before fix, passes after fix
### Expected
Tests should pass regardless of local environment variables
### Actual
Tests fail when env vars are set
## Evidence
- [x] Failing test/log before + passing after
Before fix:
```
OPENCLAW_GATEWAY_TOKEN=test pnpm test -- --run src/gateway/server-runtime-config.test.ts
# ❌ fails - expects rejection but resolves with token
```
After fix:
```
OPENCLAW_GATEWAY_TOKEN=test pnpm test -- --run src/gateway/server-runtime-config.test.ts
# ✅ passes
```
## Human Verification
- Verified scenarios: Tests pass with env vars set, tests pass without env vars
- Edge cases checked: Both `runOnce` and passthrough-args spawn paths
- What was **not** verified: Windows environment (no access)
## Compatibility / Migration
- Backward compatible? (`Yes`)
- Config/env changes? (`No`)
- Migration needed? (`No`)
## Failure Recovery
- How to disable/revert: Revert commit `879a77498`
- Known bad symptoms: None expected
## Risks and Mitigations
None - this is a minimal test infrastructure fix with no production code changes.
Most Similar PRs
#19885: test(gateway,browser): isolate tests from ambient OPENCLAW_GATEWAY_...
by NewdlDewdl · 2026-02-18
82.6%
#19937: fix(gateway): validate token/password auth modes and isolate gatewa...
by NewdlDewdl · 2026-02-18
79.8%
#16658: test: isolate env-dependent gateway/auth fixtures
by sauerdaniel · 2026-02-15
77.9%
#22658: Fix onboard ignoring OPENCLAW_GATEWAY_TOKEN env var
by Clawborn · 2026-02-21
73.7%
#21651: fix(gateway): token fallback + operator.admin scope superset in pai...
by lan17 · 2026-02-20
71.8%
#23139: test: fix flaky auth tests when OPENCLAW_GATEWAY_TOKEN is present
by Imccccc · 2026-02-22
71.4%
#21100: Security/Gateway: require explicit break-glass env for Control UI b...
by bmendonca3 · 2026-02-19
71.3%
#23444: Gateway: move auth token storage to state dotenv by default
by bmendonca3 · 2026-02-22
71.1%
#11455: fix(gateway): default gateway.mode to local when unset
by AnonO6 · 2026-02-07
71.0%
#22381: Security/Gateway: block cross-origin silent auto-pairing in auth mo...
by bmendonca3 · 2026-02-21
70.7%