Skip to content

Commit e07ef9d

Browse files
🤖 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

File tree

2 files changed

+1
-6
lines changed

2 files changed

+1
-6
lines changed

bun.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"lockfileVersion": 1,
3+
"configVersion": 0,
34
"workspaces": {
45
"": {
56
"name": "mux",

src/common/utils/ai/providerOptions.test.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import { describe, test, expect, mock } from "bun:test";
66
import { buildProviderOptions } from "./providerOptions";
7-
import type { ThinkingLevel } from "@/common/types/thinking";
87

98
// Mock the log module to avoid console noise
109
void mock.module("@/node/services/log", () => ({
@@ -16,11 +15,6 @@ void mock.module("@/node/services/log", () => ({
1615
},
1716
}));
1817

19-
// Mock enforceThinkingPolicy to pass through
20-
void mock.module("@/browser/utils/thinking/policy", () => ({
21-
enforceThinkingPolicy: (_model: string, level: ThinkingLevel) => level,
22-
}));
23-
2418
describe("buildProviderOptions - Anthropic", () => {
2519
describe("Opus 4.5 (effort parameter)", () => {
2620
test("should use effort and thinking parameters for claude-opus-4-5", () => {

0 commit comments

Comments
 (0)