test(hooks): update multiple hook test suites

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
YeonGyu-Kim
2026-04-10 15:53:32 +09:00
parent 4180a0ba0a
commit 8a4eacfd24
14 changed files with 316 additions and 259 deletions
+21 -7
View File
@@ -1,10 +1,24 @@
import { existsSync, readFileSync, rmSync } from "node:fs"
import { randomUUID } from "node:crypto"
import { tmpdir } from "node:os"
import { join } from "node:path"
import { describe, expect, it, mock } from "bun:test"
import { detectErrorType } from "./index"
import { prependThinkingPart, prependThinkingPartAsync } from "./storage/thinking-prepend"
import { PART_STORAGE } from "../../shared/opencode-storage-paths"
const { describe, expect, it, mock } = require("bun:test")
const TEST_STORAGE_ROOT = join(tmpdir(), `session-recovery-thinking-prepend-${randomUUID()}`)
const TEST_PART_STORAGE = join(TEST_STORAGE_ROOT, "part")
mock.module("../../shared", () => ({
OPENCODE_STORAGE: TEST_STORAGE_ROOT,
MESSAGE_STORAGE: join(TEST_STORAGE_ROOT, "message"),
PART_STORAGE: TEST_PART_STORAGE,
log: () => {},
isSqliteBackend: () => false,
patchPart: async () => true,
normalizeSDKResponse: <TData>(response: { data?: TData }, fallback: TData) => response.data ?? fallback,
}))
const { prependThinkingPart, prependThinkingPartAsync } = await import("./storage/thinking-prepend")
describe("detectErrorType", () => {
describe("thinking_block_order errors", () => {
@@ -295,7 +309,7 @@ type StoredPartRecord = {
}
function cleanupParts(messageID: string): void {
rmSync(join(PART_STORAGE, messageID), { recursive: true, force: true })
rmSync(join(TEST_PART_STORAGE, messageID), { recursive: true, force: true })
}
describe("thinking-prepend", () => {
@@ -322,7 +336,7 @@ describe("thinking-prepend", () => {
})
expect(result).toBe(true)
const writtenPath = join(PART_STORAGE, targetMessageID, `${originalPart.id}.json`)
const writtenPath = join(TEST_PART_STORAGE, targetMessageID, `${originalPart.id}.json`)
expect(existsSync(writtenPath)).toBe(true)
expect(JSON.parse(readFileSync(writtenPath, "utf-8"))).toEqual(originalPart)
@@ -344,7 +358,7 @@ describe("thinking-prepend", () => {
})
expect(result).toBe(false)
expect(existsSync(join(PART_STORAGE, targetMessageID))).toBe(false)
expect(existsSync(join(TEST_PART_STORAGE, targetMessageID))).toBe(false)
cleanupParts(targetMessageID)
})
@@ -386,7 +400,7 @@ describe("thinking-prepend", () => {
})
expect(result).toBe(false)
expect(existsSync(join(PART_STORAGE, targetMessageID))).toBe(false)
expect(existsSync(join(TEST_PART_STORAGE, targetMessageID))).toBe(false)
})
it("patches the original signed thinking part verbatim for sdk-backed recovery", async () => {
@@ -1,13 +1,20 @@
const { describe, it, expect, mock, beforeEach, afterEach, spyOn } = require("bun:test")
import { afterEach, beforeEach, describe, expect, it, mock } from "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 }> = []
mock.module("../../shared/opencode-storage-detection", () => ({
isSqliteBackend: () => sqliteBackend,
}))
mock.module("./storage", () => ({
readParts: () => storedParts,
}))
const { recoverToolResultMissing } = await import("./recover-tool-result-missing")
const failedAssistantMsg: MessageData = {
info: { id: "msg_failed", role: "assistant" },
parts: [],
@@ -31,9 +38,6 @@ describe("recoverToolResultMissing", () => {
beforeEach(() => {
sqliteBackend = false
storedParts = []
spyOn(storageDetection, "isSqliteBackend").mockImplementation(() => sqliteBackend)
spyOn(storage, "readParts").mockImplementation(() => storedParts)
})
afterEach(() => {