test: fresh-import remaining contamination-prone modules

This commit is contained in:
YeonGyu-Kim
2026-04-04 20:14:50 +09:00
parent 861ce1c161
commit 55d5ecb9fb
5 changed files with 90 additions and 47 deletions
@@ -1,20 +1,22 @@
const { describe, expect, mock, test, afterAll } = require("bun:test")
mock.module("../../shared/opencode-message-dir", () => ({
getMessageDir: () => null,
}))
mock.module("../../shared/opencode-storage-detection", () => ({
isSqliteBackend: () => true,
}))
mock.module("../../shared/normalize-sdk-response", () => ({
normalizeSDKResponse: <TData>(response: { data?: TData }, fallback: TData): TData => response.data ?? fallback,
}))
afterAll(() => { mock.restore() })
const { getLastAgentFromSession } = await import("./session-last-agent")
async function importFreshSessionLastAgentModule() {
mock.module("../../shared/opencode-message-dir", () => ({
getMessageDir: () => null,
}))
mock.module("../../shared/opencode-storage-detection", () => ({
isSqliteBackend: () => true,
}))
const module = await import(`./session-last-agent?test=${Date.now()}-${Math.random()}`)
mock.restore()
return module
}
const { getLastAgentFromSession } = await importFreshSessionLastAgentModule()
function createMockClient(messages: Array<{ info?: { agent?: string } }>) {
return {