test: remove remaining session recovery module leaks
This commit is contained in:
@@ -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 * as storageDetection from "../../shared/opencode-storage-detection"
|
||||
import * as storage from "./storage"
|
||||
import { recoverToolResultMissing } from "./recover-tool-result-missing"
|
||||
|
||||
let sqliteBackend = false
|
||||
let storedParts: Array<{ type: string; id?: string; callID?: string; [key: string]: unknown }> = []
|
||||
|
||||
afterAll(() => {
|
||||
mock.restore()
|
||||
})
|
||||
|
||||
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 failedAssistantMsg: MessageData = {
|
||||
info: { id: "msg_failed", role: "assistant" },
|
||||
parts: [],
|
||||
}
|
||||
|
||||
const { recoverToolResultMissing } = await importFreshRecoverToolResultMissingModule()
|
||||
|
||||
function createMockClient(messages: MessageData[] = []) {
|
||||
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", () => {
|
||||
beforeEach(() => {
|
||||
sqliteBackend = false
|
||||
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 () => {
|
||||
|
||||
Reference in New Issue
Block a user