test: remove remaining session recovery module leaks
This commit is contained in:
@@ -5,10 +5,6 @@ const injectTextPartAsync = mock(() => Promise.resolve(false))
|
|||||||
const findMessagesWithEmptyTextPartsFromSDK = mock(() => Promise.resolve([] as string[]))
|
const findMessagesWithEmptyTextPartsFromSDK = mock(() => Promise.resolve([] as string[]))
|
||||||
|
|
||||||
async function importFreshMessageBuilder(): Promise<typeof import("./message-builder")> {
|
async function importFreshMessageBuilder(): Promise<typeof import("./message-builder")> {
|
||||||
mock.module("../../shared/normalize-sdk-response", () => ({
|
|
||||||
normalizeSDKResponse: (response: { data?: unknown[] }) => response.data ?? [],
|
|
||||||
}))
|
|
||||||
|
|
||||||
mock.module("../../shared/logger", () => ({
|
mock.module("../../shared/logger", () => ({
|
||||||
log: () => {},
|
log: () => {},
|
||||||
}))
|
}))
|
||||||
@@ -17,21 +13,21 @@ async function importFreshMessageBuilder(): Promise<typeof import("./message-bui
|
|||||||
isSqliteBackend: () => true,
|
isSqliteBackend: () => true,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
mock.module("../session-recovery/storage.ts", () => ({
|
const emptyTextMockFactory = () => ({
|
||||||
findEmptyMessages: () => [],
|
|
||||||
findMessagesWithEmptyTextParts: () => [],
|
findMessagesWithEmptyTextParts: () => [],
|
||||||
injectTextPart: () => false,
|
|
||||||
replaceEmptyTextParts: () => false,
|
replaceEmptyTextParts: () => false,
|
||||||
}))
|
|
||||||
|
|
||||||
mock.module("../session-recovery/storage/empty-text.ts", () => ({
|
|
||||||
replaceEmptyTextPartsAsync,
|
replaceEmptyTextPartsAsync,
|
||||||
findMessagesWithEmptyTextPartsFromSDK,
|
findMessagesWithEmptyTextPartsFromSDK,
|
||||||
}))
|
})
|
||||||
|
mock.module("../session-recovery/storage/empty-text", emptyTextMockFactory)
|
||||||
|
mock.module("../session-recovery/storage/empty-text.ts", emptyTextMockFactory)
|
||||||
|
|
||||||
mock.module("../session-recovery/storage/text-part-injector.ts", () => ({
|
const textPartInjectorMockFactory = () => ({
|
||||||
|
injectTextPart: () => false,
|
||||||
injectTextPartAsync,
|
injectTextPartAsync,
|
||||||
}))
|
})
|
||||||
|
mock.module("../session-recovery/storage/text-part-injector", textPartInjectorMockFactory)
|
||||||
|
mock.module("../session-recovery/storage/text-part-injector.ts", textPartInjectorMockFactory)
|
||||||
|
|
||||||
const module = await import(`./message-builder?test=${Date.now()}-${Math.random()}`)
|
const module = await import(`./message-builder?test=${Date.now()}-${Math.random()}`)
|
||||||
mock.restore()
|
mock.restore()
|
||||||
|
|||||||
@@ -1,30 +1,18 @@
|
|||||||
const { describe, it, expect, mock, beforeEach, afterAll } = require("bun:test")
|
const { describe, it, expect, mock, beforeEach, afterEach, spyOn } = require("bun:test")
|
||||||
|
|
||||||
import type { MessageData } from "./types"
|
import type { MessageData } from "./types"
|
||||||
|
import * as storageDetection from "../../shared/opencode-storage-detection"
|
||||||
|
import * as storage from "./storage"
|
||||||
|
import { recoverToolResultMissing } from "./recover-tool-result-missing"
|
||||||
|
|
||||||
let sqliteBackend = false
|
let sqliteBackend = false
|
||||||
let storedParts: Array<{ type: string; id?: string; callID?: string; [key: string]: unknown }> = []
|
let storedParts: Array<{ type: string; id?: string; callID?: string; [key: string]: unknown }> = []
|
||||||
|
|
||||||
afterAll(() => {
|
const failedAssistantMsg: MessageData = {
|
||||||
mock.restore()
|
info: { id: "msg_failed", role: "assistant" },
|
||||||
})
|
parts: [],
|
||||||
|
|
||||||
async function importFreshRecoverToolResultMissingModule() {
|
|
||||||
mock.module("../../shared/opencode-storage-detection", () => ({
|
|
||||||
isSqliteBackend: () => sqliteBackend,
|
|
||||||
}))
|
|
||||||
|
|
||||||
mock.module("./storage", () => ({
|
|
||||||
readParts: () => storedParts,
|
|
||||||
}))
|
|
||||||
|
|
||||||
const module = await import(`./recover-tool-result-missing?test=${Date.now()}-${Math.random()}`)
|
|
||||||
mock.restore()
|
|
||||||
return module
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const { recoverToolResultMissing } = await importFreshRecoverToolResultMissingModule()
|
|
||||||
|
|
||||||
function createMockClient(messages: MessageData[] = []) {
|
function createMockClient(messages: MessageData[] = []) {
|
||||||
const promptAsync = mock(() => Promise.resolve({}))
|
const promptAsync = mock(() => Promise.resolve({}))
|
||||||
|
|
||||||
@@ -39,15 +27,17 @@ function createMockClient(messages: MessageData[] = []) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const failedAssistantMsg: MessageData = {
|
|
||||||
info: { id: "msg_failed", role: "assistant" },
|
|
||||||
parts: [],
|
|
||||||
}
|
|
||||||
|
|
||||||
describe("recoverToolResultMissing", () => {
|
describe("recoverToolResultMissing", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
sqliteBackend = false
|
sqliteBackend = false
|
||||||
storedParts = []
|
storedParts = []
|
||||||
|
|
||||||
|
spyOn(storageDetection, "isSqliteBackend").mockImplementation(() => sqliteBackend)
|
||||||
|
spyOn(storage, "readParts").mockImplementation(() => storedParts)
|
||||||
|
})
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
mock.restore()
|
||||||
})
|
})
|
||||||
|
|
||||||
it("returns false for sqlite fallback when tool part has no valid callID", async () => {
|
it("returns false for sqlite fallback when tool part has no valid callID", async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user