From 4eae36abd6b282166daa7359c914c749e762ed6f Mon Sep 17 00:00:00 2001 From: JATMN Date: Thu, 22 Oct 2026 09:03:45 -0700 Subject: [PATCH] test: restore Shell and GrowthBook module mocks after BashTool sandboxAnalysis tests (#2336) --- .../BashTool/BashTool.sandboxAnalysis.test.ts | 32 +++++++++++++------ 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/src/tools/BashTool/BashTool.sandboxAnalysis.test.ts b/src/tools/BashTool/BashTool.sandboxAnalysis.test.ts index 7a9b4fff0..ec8f2c44e 100644 --- a/src/tools/BashTool/BashTool.sandboxAnalysis.test.ts +++ b/src/tools/BashTool/BashTool.sandboxAnalysis.test.ts @@ -1,14 +1,28 @@ -import { afterEach, beforeEach, expect, mock, test } from 'bun:test' -import * as realGrowthbook from '../../services/analytics/growthbook.js' +import { afterAll, afterEach, beforeEach, expect, mock, test } from 'bun:test' import { getEmptyToolPermissionContext } from '../../Tool.js' import { acquireSharedMutationLock, releaseSharedMutationLock, } from '../../test/sharedMutationLock.js' -import * as realShell from '../../utils/Shell.js' import type { ExecResult, ShellCommand } from '../../utils/ShellCommand.js' import { SandboxManager } from '../../utils/sandbox/sandbox-adapter.js' +const nonce = `${Date.now()}-${Math.random()}` +const REAL_SHELL = { + ...await import(`../../utils/Shell.js?real=${nonce}`), +} +const REAL_GROWTHBOOK = { + ...await import(`../../services/analytics/growthbook.js?real=${nonce}`), +} + +afterAll(() => { + mock.restore() + mock.module('../../utils/Shell.js', () => REAL_SHELL) + mock.module('src/utils/Shell.js', () => REAL_SHELL) + mock.module('../../services/analytics/growthbook.js', () => REAL_GROWTHBOOK) + mock.module('src/services/analytics/growthbook.js', () => REAL_GROWTHBOOK) +}) + const originalSandboxMethods = { isSandboxingEnabled: SandboxManager.isSandboxingEnabled, areUnsandboxedCommandsAllowed: SandboxManager.areUnsandboxedCommandsAllowed, @@ -107,19 +121,19 @@ async function importBashToolWithExecutionMocks() { ) mock.module('../../utils/Shell.js', () => ({ - ...realShell, + ...REAL_SHELL, exec: execMock, })) mock.module('src/utils/Shell.js', () => ({ - ...realShell, + ...REAL_SHELL, exec: execMock, })) mock.module('../../services/analytics/growthbook.js', () => ({ - ...realGrowthbook, + ...REAL_GROWTHBOOK, getFeatureValue_CACHED_MAY_BE_STALE, })) mock.module('src/services/analytics/growthbook.js', () => ({ - ...realGrowthbook, + ...REAL_GROWTHBOOK, getFeatureValue_CACHED_MAY_BE_STALE, })) @@ -137,11 +151,11 @@ async function importSandboxPresentationWithMocks() { ) mock.module('../../services/analytics/growthbook.js', () => ({ - ...realGrowthbook, + ...REAL_GROWTHBOOK, getFeatureValue_CACHED_MAY_BE_STALE, })) mock.module('src/services/analytics/growthbook.js', () => ({ - ...realGrowthbook, + ...REAL_GROWTHBOOK, getFeatureValue_CACHED_MAY_BE_STALE, }))