Commit e07ef9d
authored
🤖 fix: remove mock.module causing test pollution across files (#1008)
## Problem
The `enforceThinkingPolicy` tests in `policy.test.ts` fail
intermittently depending on test execution order. When
`providerOptions.test.ts` runs before `policy.test.ts`, the policy tests
fail because they receive a mocked pass-through function instead of the
real implementation.
**Root cause:** `providerOptions.test.ts` uses
`mock.module("@/browser/utils/thinking/policy", ...)` at module load
time, which globally replaces the real module. Bun's `mock.module` does
not isolate between test files—this is a [known
limitation](oven-sh/bun#12823).
**Why it's flaky:** Bun randomizes test file order. Different seeds
produce different orderings:
- `--seed=2`: policy tests pass (providerOptions runs after policy)
- `--seed=1`, `--seed=42`, default: policy tests fail (providerOptions
runs before policy)
## Solution
Remove the `mock.module` for `enforceThinkingPolicy` from
`providerOptions.test.ts`.
## Why this fix is safe
The mock was added to test `buildProviderOptions` output formatting in
isolation—passing arbitrary thinking levels without policy clamping.
However, examining the tests:
- They use thinking levels (`"medium"`, `"high"`, `"low"`, `"off"`) that
are valid for the models being tested
- `enforceThinkingPolicy` returns these levels unchanged for these
model/level combinations
- The tests still pass without the mock because the real policy allows
these levels
The mock was defensive but unnecessary. Removing it:
1. Fixes the flaky test
2. Follows the codebase's preference for avoiding mocks (per AGENTS.md)
3. Makes tests more honest—they now test real behavior
## Verification
```
# Before fix (default seed): 5 failures
bun test src
# After fix: 0 failures across all seeds
bun test src # 1571 pass, 0 fail
bun test --seed=1 src # passes
bun test --seed=42 src # passes
```
_Generated with `mux`_1 parent d3dee7d commit e07ef9d
2 files changed
+1
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
8 | 7 | | |
9 | 8 | | |
10 | 9 | | |
| |||
16 | 15 | | |
17 | 16 | | |
18 | 17 | | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | 18 | | |
25 | 19 | | |
26 | 20 | | |
| |||
0 commit comments