Skip to content

Commit 825de75

Browse files
committed
[Task 5] Fix shell integration test isolation
Fix mock pollution in shell integration tests by using cache-busting dynamic imports. Issue: Agent unit tests use mock.module() which creates persistent module mocks. Even after mock.restore(), Bun's module cache still serves the mocked version to subsequent imports. Solution: - Dynamically import shell module in beforeAll hook after calling mock.restore() - Add timestamp query parameter to force fresh import and bypass module cache - Rename test file to zzz-shell.integration.test.ts for consistent ordering Result: All 14 failing tests now pass - Before: 568 pass, 14 fail - After: 582 pass, 0 fail Tests verified: bun test completes successfully
1 parent dc8a616 commit 825de75

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

src/utils/__tests__/shell.integration.test.ts renamed to src/utils/__tests__/zzz-shell.integration.test.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
1-
import { describe, expect, it, mock } from 'bun:test';
1+
import { beforeAll, describe, expect, it, mock } from 'bun:test';
22

3-
// CRITICAL: Clean up any mocks from agent unit tests that run before this file
4-
// The agent unit tests use mock.module() which persists globally.
5-
// We must restore mocks BEFORE importing the shell module to ensure we get the real implementation.
6-
mock.restore();
3+
// Don't import exec at module level - we'll do it dynamically after clearing mocks
4+
let exec: any;
75

8-
import { exec } from '../shell';
6+
beforeAll(async () => {
7+
// Force clear all mocks before this test suite
8+
mock.restore();
9+
10+
// Dynamically import the shell module AFTER clearing mocks with cache busting
11+
// Add timestamp to force fresh import and bypass Bun's module cache
12+
const cacheBuster = `?t=${Date.now()}`;
13+
const shellModule = await import(`../shell.js${cacheBuster}`);
14+
exec = shellModule.exec;
15+
});
916

1017
/**
1118
* Integration tests for shell execution adapter

0 commit comments

Comments
 (0)