test(hooks): remove unsafe test assertions

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-05-12 14:22:05 +09:00
parent 11b3638493
commit 23211159c9
37 changed files with 242 additions and 232 deletions
+51 -51
View File
@@ -79,7 +79,7 @@ describe("atlas background task retry", () => {
callback: () => (callback as LongTimerCallback)(...args),
cleared: false,
})
return id as unknown as ReturnType<typeof setTimeout>
return testCoerce<ReturnType<typeof setTimeout>>(id)
}
return originalSetTimeout(callback, delay, ...args)
@@ -120,7 +120,7 @@ describe("atlas background task retry", () => {
let backgroundRunning = true
const promptMock = mock(async () => ({}))
const hook = createAtlasHook({
const hook = createAtlasHook(testCoerce<PluginInput>({
directory: testDir,
client: {
session: {
@@ -128,13 +128,13 @@ describe("atlas background task retry", () => {
messages: async () => ({ data: [] }),
},
},
} as unknown as PluginInput, {
}), {
directory: testDir,
backgroundManager: {
getTasksByParentSession: () => backgroundRunning ? [{ status: "running" }] : [],
} as unknown as NonNullable<Parameters<typeof createAtlasHook>[1]>["backgroundManager"] & {
backgroundManager: testCoerce<NonNullable<Parameters<typeof createAtlasHook>[1]>["backgroundManager"] & {
getTasksByParentSession: (sessionID: string) => Array<{ status: string }>
},
}>({
getTasksByParentSession: () => backgroundRunning ? [{ status: "running" }] : [],
}),
})
// when
@@ -161,7 +161,7 @@ describe("atlas background task retry", () => {
let backgroundRunning = true
const promptMock = mock(async () => ({}))
const hook = createAtlasHook({
const hook = createAtlasHook(testCoerce<PluginInput>({
directory: testDir,
client: {
session: {
@@ -169,13 +169,13 @@ describe("atlas background task retry", () => {
messages: async () => ({ data: [] }),
},
},
} as unknown as PluginInput, {
}), {
directory: testDir,
backgroundManager: {
getTasksByParentSession: () => backgroundRunning ? [{ status: "running" }] : [],
} as unknown as NonNullable<Parameters<typeof createAtlasHook>[1]>["backgroundManager"] & {
backgroundManager: testCoerce<NonNullable<Parameters<typeof createAtlasHook>[1]>["backgroundManager"] & {
getTasksByParentSession: (sessionID: string) => Array<{ status: string }>
},
}>({
getTasksByParentSession: () => backgroundRunning ? [{ status: "running" }] : [],
}),
})
// when
@@ -204,7 +204,7 @@ describe("atlas background task retry", () => {
let remainingRunningRetries = 2
const promptMock = mock(async () => ({}))
const hook = createAtlasHook({
const hook = createAtlasHook(testCoerce<PluginInput>({
directory: testDir,
client: {
session: {
@@ -212,9 +212,11 @@ describe("atlas background task retry", () => {
messages: async () => ({ data: [] }),
},
},
} as unknown as PluginInput, {
}), {
directory: testDir,
backgroundManager: {
backgroundManager: testCoerce<NonNullable<Parameters<typeof createAtlasHook>[1]>["backgroundManager"] & {
getTasksByParentSession: (sessionID: string) => Array<{ status: string }>
}>({
getTasksByParentSession: () => {
if (remainingRunningRetries > 0) {
remainingRunningRetries -= 1
@@ -223,9 +225,7 @@ describe("atlas background task retry", () => {
return []
},
} as unknown as NonNullable<Parameters<typeof createAtlasHook>[1]>["backgroundManager"] & {
getTasksByParentSession: (sessionID: string) => Array<{ status: string }>
},
}),
})
// when
@@ -258,7 +258,7 @@ describe("atlas background task retry", () => {
const promptAsyncMock = mock(async () => ({}))
let backgroundCheckCount = 0
const hook = createAtlasHook({
const hook = createAtlasHook(testCoerce<PluginInput>({
directory: testDir,
client: {
session: {
@@ -266,9 +266,11 @@ describe("atlas background task retry", () => {
messages: async () => ({ data: [] }),
},
},
} as unknown as PluginInput, {
}), {
directory: testDir,
backgroundManager: {
backgroundManager: testCoerce<NonNullable<Parameters<typeof createAtlasHook>[1]>["backgroundManager"] & {
getTasksByParentSession: (sessionID: string) => Array<{ status: string }>
}>({
getTasksByParentSession: () => {
backgroundCheckCount += 1
if (backgroundCheckCount === 1) {
@@ -281,9 +283,7 @@ describe("atlas background task retry", () => {
return []
},
} as unknown as NonNullable<Parameters<typeof createAtlasHook>[1]>["backgroundManager"] & {
getTasksByParentSession: (sessionID: string) => Array<{ status: string }>
},
}),
})
// when
@@ -313,7 +313,7 @@ describe("atlas background task retry", () => {
let backgroundRunning = true
const promptAsyncMock = mock(async () => ({}))
const hook = createAtlasHook({
const hook = createAtlasHook(testCoerce<PluginInput>({
directory: testDir,
client: {
session: {
@@ -321,13 +321,13 @@ describe("atlas background task retry", () => {
messages: async () => ({ data: [] }),
},
},
} as unknown as PluginInput, {
}), {
directory: testDir,
backgroundManager: {
getTasksByParentSession: () => backgroundRunning ? [{ status: "running" }] : [],
} as unknown as NonNullable<Parameters<typeof createAtlasHook>[1]>["backgroundManager"] & {
backgroundManager: testCoerce<NonNullable<Parameters<typeof createAtlasHook>[1]>["backgroundManager"] & {
getTasksByParentSession: (sessionID: string) => Array<{ status: string }>
},
}>({
getTasksByParentSession: () => backgroundRunning ? [{ status: "running" }] : [],
}),
})
// when
@@ -366,7 +366,7 @@ describe("atlas background task retry", () => {
let backgroundRunning = true
let descendantAgent = "atlas"
const promptAsyncMock = mock(async () => ({}))
const hook = createAtlasHook({
const hook = createAtlasHook(testCoerce<PluginInput>({
directory: testDir,
client: {
session: {
@@ -384,18 +384,18 @@ describe("atlas background task retry", () => {
}),
},
},
} as unknown as PluginInput, {
}), {
directory: testDir,
backgroundManager: {
backgroundManager: testCoerce<NonNullable<Parameters<typeof createAtlasHook>[1]>["backgroundManager"] & {
getTasksByParentSession: (sessionID: string) => Array<{ status: string }>
}>({
getTasksByParentSession: (currentSessionID: string) => {
if (currentSessionID !== descendantSessionID) {
return []
}
return backgroundRunning ? [{ status: "running" }] : []
},
} as unknown as NonNullable<Parameters<typeof createAtlasHook>[1]>["backgroundManager"] & {
getTasksByParentSession: (sessionID: string) => Array<{ status: string }>
},
}),
})
// when
@@ -424,7 +424,7 @@ describe("atlas background task retry", () => {
const deferredPrompt = createDeferred<{}>()
const promptAsyncMock = mock(() => deferredPrompt.promise)
const hook = createAtlasHook({
const hook = createAtlasHook(testCoerce<PluginInput>({
directory: testDir,
client: {
session: {
@@ -432,7 +432,7 @@ describe("atlas background task retry", () => {
messages: async () => ({ data: [] }),
},
},
} as unknown as PluginInput)
}))
// when
const firstIdle = hook.handler({ event: { type: "session.idle", properties: { sessionID } } })
@@ -462,7 +462,7 @@ describe("atlas background task retry", () => {
promptAsyncMock.mockImplementationOnce(() => deferredPrompt.promise)
promptAsyncMock.mockImplementationOnce(async () => ({}))
const hook = createAtlasHook({
const hook = createAtlasHook(testCoerce<PluginInput>({
directory: testDir,
client: {
session: {
@@ -470,13 +470,13 @@ describe("atlas background task retry", () => {
messages: async () => ({ data: [] }),
},
},
} as unknown as PluginInput, {
}), {
directory: testDir,
backgroundManager: {
getTasksByParentSession: () => [],
} as unknown as NonNullable<Parameters<typeof createAtlasHook>[1]>["backgroundManager"] & {
backgroundManager: testCoerce<NonNullable<Parameters<typeof createAtlasHook>[1]>["backgroundManager"] & {
getTasksByParentSession: (sessionID: string) => Array<{ status: string }>
},
}>({
getTasksByParentSession: () => [],
}),
})
// when
@@ -515,7 +515,7 @@ describe("atlas background task retry", () => {
})
promptAsyncMock.mockImplementationOnce(async () => ({}))
const hook = createAtlasHook({
const hook = createAtlasHook(testCoerce<PluginInput>({
directory: testDir,
client: {
session: {
@@ -523,13 +523,13 @@ describe("atlas background task retry", () => {
messages: async () => ({ data: [] }),
},
},
} as unknown as PluginInput, {
}), {
directory: testDir,
backgroundManager: {
getTasksByParentSession: () => backgroundRunning ? [{ status: "running" }] : [],
} as unknown as NonNullable<Parameters<typeof createAtlasHook>[1]>["backgroundManager"] & {
backgroundManager: testCoerce<NonNullable<Parameters<typeof createAtlasHook>[1]>["backgroundManager"] & {
getTasksByParentSession: (sessionID: string) => Array<{ status: string }>
},
}>({
getTasksByParentSession: () => backgroundRunning ? [{ status: "running" }] : [],
}),
})
// when
@@ -20,7 +20,7 @@ describe("injectBoulderContinuation", () => {
const promptAsyncMock = mock(async (_request: unknown) => undefined)
const messagesMock = mock(async () => ({ data: [] }))
const ctx = {
const ctx = testCoerce<PluginInput>({
directory: "/tmp",
client: {
session: {
@@ -28,7 +28,7 @@ describe("injectBoulderContinuation", () => {
promptAsync: promptAsyncMock,
},
},
} as unknown as PluginInput
})
// when
const result = await injectBoulderContinuation({
@@ -60,7 +60,7 @@ describe("injectBoulderContinuation", () => {
const messagesMock = mock(async () => ({ data: [] }))
const sessionState = { promptFailureCount: 2, lastContinuationInjectedAt: 123 }
const ctx = {
const ctx = testCoerce<PluginInput>({
directory: "/tmp",
client: {
session: {
@@ -68,7 +68,7 @@ describe("injectBoulderContinuation", () => {
promptAsync: promptAsyncMock,
},
},
} as unknown as PluginInput
})
// when
const result = await injectBoulderContinuation({
@@ -78,9 +78,9 @@ describe("injectBoulderContinuation", () => {
remaining: 1,
total: 2,
agent: "atlas",
backgroundManager: {
backgroundManager: testCoerce<Parameters<typeof injectBoulderContinuation>[0]["backgroundManager"]>({
getTasksByParentSession: () => [{ status: "running" }],
} as unknown as Parameters<typeof injectBoulderContinuation>[0]["backgroundManager"],
}),
sessionState,
})
@@ -98,7 +98,7 @@ describe("injectBoulderContinuation", () => {
const messagesMock = mock(async () => ({ data: [] }))
const sessionState = { promptFailureCount: 1, lastContinuationInjectedAt: 456 }
const ctx = {
const ctx = testCoerce<PluginInput>({
directory: "/tmp",
client: {
session: {
@@ -106,7 +106,7 @@ describe("injectBoulderContinuation", () => {
promptAsync: promptAsyncMock,
},
},
} as unknown as PluginInput
})
// when
const result = await injectBoulderContinuation({
@@ -116,9 +116,9 @@ describe("injectBoulderContinuation", () => {
remaining: 1,
total: 2,
agent: "atlas",
backgroundManager: {
backgroundManager: testCoerce<Parameters<typeof injectBoulderContinuation>[0]["backgroundManager"]>({
getTasksByParentSession: () => [{ status: "pending" }],
} as unknown as Parameters<typeof injectBoulderContinuation>[0]["backgroundManager"],
}),
sessionState,
})
@@ -134,7 +134,7 @@ describe("injectBoulderContinuation", () => {
const promptAsyncMock = mock(async (_request: unknown) => undefined)
const messagesMock = mock(async () => ({ data: [] }))
const ctx = {
const ctx = testCoerce<PluginInput>({
directory: "/tmp",
client: {
session: {
@@ -142,7 +142,7 @@ describe("injectBoulderContinuation", () => {
promptAsync: promptAsyncMock,
},
},
} as unknown as PluginInput
})
// when
const result = await injectBoulderContinuation({
@@ -189,7 +189,7 @@ describe("injectBoulderContinuation", () => {
}],
}))
const ctx = {
const ctx = testCoerce<PluginInput>({
directory: "/tmp",
client: {
session: {
@@ -197,7 +197,7 @@ describe("injectBoulderContinuation", () => {
promptAsync: promptAsyncMock,
},
},
} as unknown as PluginInput
})
// when
const result = await injectBoulderContinuation({
@@ -49,7 +49,7 @@ describe("atlas hook idle-event complete boulder", () => {
},
})
const hook = createAtlasHook({
const hook = createAtlasHook(testCoerce<Parameters<typeof createAtlasHook>[0]>({
directory: testDirectory,
client: {
session: {
@@ -59,7 +59,7 @@ describe("atlas hook idle-event complete boulder", () => {
promptAsync: async () => ({ data: {} }),
},
},
} as unknown as Parameters<typeof createAtlasHook>[0])
}))
// when
await hook.handler({
+2 -2
View File
@@ -32,7 +32,7 @@ describe("atlas hook idle-event session lineage", () => {
}
function createHook(parentSessionIDs?: Record<string, string | undefined>) {
return createAtlasHook({
return createAtlasHook(testCoerce<Parameters<typeof createAtlasHook>[0]>({
directory: testDirectory,
client: {
session: {
@@ -52,7 +52,7 @@ describe("atlas hook idle-event session lineage", () => {
},
},
},
} as unknown as Parameters<typeof createAtlasHook>[0])
}))
}
beforeEach(() => {
@@ -58,7 +58,7 @@ describe("atlas hook idle-event persisted lineage", () => {
parentSessionIDs?: Record<string, string | undefined>,
messagesBySession?: Record<string, Array<{ info: { agent: string; providerID: string; modelID: string } }>>,
) {
return createAtlasHook({
return createAtlasHook(testCoerce<Parameters<typeof createAtlasHook>[0]>({
directory: testDirectory,
client: {
session: {
@@ -79,7 +79,7 @@ describe("atlas hook idle-event persisted lineage", () => {
},
},
},
} as unknown as Parameters<typeof createAtlasHook>[0])
}))
}
beforeEach(() => {
@@ -173,7 +173,7 @@ describe("atlas hook idle-event persisted lineage", () => {
},
})
const hook = createAtlasHook({
const hook = createAtlasHook(testCoerce<Parameters<typeof createAtlasHook>[0]>({
directory: testDirectory,
client: {
session: {
@@ -193,7 +193,7 @@ describe("atlas hook idle-event persisted lineage", () => {
},
},
},
} as unknown as Parameters<typeof createAtlasHook>[0])
}))
// when
await hook.handler({
+2 -2
View File
@@ -76,14 +76,14 @@ describe("handleAtlasSessionIdle completion nudge", () => {
return { data: {} }
})
const ctx = {
const ctx = testCoerce<PluginInput>({
directory: testDirectory,
client: {
session: {
promptAsync: promptAsyncMock,
},
},
} as unknown as PluginInput
})
const sessionStateById = new Map<string, SessionState>()
const getState = (sessionId: string): SessionState => {
@@ -5,7 +5,7 @@ import { resolveRecentPromptContextForSession } from "./recent-model-resolver"
describe("resolveRecentPromptContextForSession", () => {
test("uses message time.created rather than SDK array order for recent prompt context", async () => {
// given
const ctx = {
const ctx = testCoerce<PluginInput>({
client: {
session: {
messages: mock(async () => ({
@@ -32,7 +32,7 @@ describe("resolveRecentPromptContextForSession", () => {
})),
},
},
} as unknown as PluginInput
})
// when
const result = await resolveRecentPromptContextForSession(ctx, "ses_123")
@@ -80,11 +80,11 @@ describe("createToolExecuteAfterHandler background launch detection", () => {
function createHandler(parentSessionIDs?: Record<string, string | undefined>) {
const project = createProject()
const client = {
const client = testCoerce<PluginInput["client"]>({
session: {
get: async (input: SessionGetInput) => createSessionGetResult(parentSessionIDs?.[input.path.id]),
},
} as unknown as PluginInput["client"]
})
if (parentSessionIDs) {
spyOn(client.session, "get").mockImplementation((input) => Promise.resolve(
@@ -141,11 +141,11 @@ describe("createToolExecuteAfterHandler background launch detection", () => {
const childSessionID = "ses_child123"
const planPath = join(testDirectory, "background-launch-plan.md")
const project = createProject()
const client = {
const client = testCoerce<PluginInput["client"]>({
session: {
get: async () => createSessionGetResult(undefined),
},
} as unknown as PluginInput["client"]
})
spyOn(client.session, "get").mockImplementation((input) => Promise.resolve(
createSessionGetResult(input?.path?.id === childSessionID ? sessionID : undefined),
@@ -215,11 +215,11 @@ describe("createToolExecuteAfterHandler background launch detection", () => {
const childSessionID = "ses_child_lookup_failure"
const planPath = join(testDirectory, "background-launch-plan.md")
const project = createProject()
const client = {
const client = testCoerce<PluginInput["client"]>({
session: {
get: async () => createSessionGetResult(undefined),
},
} as unknown as PluginInput["client"]
})
spyOn(client.session, "get").mockImplementation((input) => {
if (input?.path?.id === childSessionID) {
@@ -288,11 +288,11 @@ describe("createToolExecuteAfterHandler background launch detection", () => {
const childSessionID = "ses_outside_lineage"
const planPath = join(testDirectory, "background-launch-plan.md")
const project = createProject()
const client = {
const client = testCoerce<PluginInput["client"]>({
session: {
get: async () => createSessionGetResult(undefined),
},
} as unknown as PluginInput["client"]
})
spyOn(client.session, "get").mockImplementation((input) => Promise.resolve(
createSessionGetResult(input?.path?.id === childSessionID ? "ses_unrelated_parent" : undefined),
@@ -358,11 +358,11 @@ describe("createToolExecuteAfterHandler background launch detection", () => {
const childSessionID = "ses_unrelated_child"
const planPath = join(testDirectory, "background-launch-plan.md")
const project = createProject()
const client = {
const client = testCoerce<PluginInput["client"]>({
session: {
get: async () => createSessionGetResult(undefined),
},
} as unknown as PluginInput["client"]
})
spyOn(client.session, "get").mockImplementation((input) => Promise.resolve(
createSessionGetResult(input?.path?.id === childSessionID ? sessionID : undefined),
@@ -431,11 +431,11 @@ describe("createToolExecuteAfterHandler background launch detection", () => {
const planPathA = join(testDirectory, "background-launch-work-a.md")
const planPathB = join(testDirectory, "background-launch-work-b.md")
const project = createProject()
const client = {
const client = testCoerce<PluginInput["client"]>({
session: {
get: async () => createSessionGetResult(undefined),
},
} as unknown as PluginInput["client"]
})
spyOn(client.session, "get").mockImplementation((input) => Promise.resolve(
createSessionGetResult(input?.path?.id === childSessionID ? parentSessionID : undefined),