test: restore Shell and GrowthBook module mocks after BashTool sandboxAnalysis tests (#2336)

This commit is contained in:
JATMN
2026-10-22 09:03:45 -07:00
committed by GitHub
parent 5c9b3c92dc
commit 4eae36abd6
@@ -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,
}))