From be67c879a5121945cf13a232ff85206aabc570ba Mon Sep 17 00:00:00 2001 From: Drew Ritter Date: Mon, 3 Nov 2025 12:00:48 -0800 Subject: [PATCH] [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 --- ....test.ts => zzz-shell.integration.test.ts} | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) rename src/utils/__tests__/{shell.integration.test.ts => zzz-shell.integration.test.ts} (91%) diff --git a/src/utils/__tests__/shell.integration.test.ts b/src/utils/__tests__/zzz-shell.integration.test.ts similarity index 91% rename from src/utils/__tests__/shell.integration.test.ts rename to src/utils/__tests__/zzz-shell.integration.test.ts index 00c1441..2ca612a 100644 --- a/src/utils/__tests__/shell.integration.test.ts +++ b/src/utils/__tests__/zzz-shell.integration.test.ts @@ -1,11 +1,18 @@ -import { describe, expect, it, mock } from 'bun:test'; +import { beforeAll, describe, expect, it, mock } from 'bun:test'; -// CRITICAL: Clean up any mocks from agent unit tests that run before this file -// The agent unit tests use mock.module() which persists globally. -// We must restore mocks BEFORE importing the shell module to ensure we get the real implementation. -mock.restore(); +// Don't import exec at module level - we'll do it dynamically after clearing mocks +let exec: any; -import { exec } from '../shell'; +beforeAll(async () => { + // Force clear all mocks before this test suite + mock.restore(); + + // Dynamically import the shell module AFTER clearing mocks with cache busting + // Add timestamp to force fresh import and bypass Bun's module cache + const cacheBuster = `?t=${Date.now()}`; + const shellModule = await import(`../shell.js${cacheBuster}`); + exec = shellModule.exec; +}); /** * Integration tests for shell execution adapter