test(todo-continuation): add promptAsync mocks for migrated hook

This commit is contained in:
Peïo Thibault 2026-02-07 13:51:28 +01:00
parent fad7354b13
commit 6451b212f8

View File

@ -152,6 +152,15 @@ describe("todo-continuation-enforcer", () => {
}) })
return {} return {}
}, },
promptAsync: async (opts: any) => {
promptCalls.push({
sessionID: opts.path.id,
agent: opts.body.agent,
model: opts.body.model,
text: opts.body.parts[0].text,
})
return {}
},
}, },
tui: { tui: {
showToast: async (opts: any) => { showToast: async (opts: any) => {
@ -977,32 +986,41 @@ describe("todo-continuation-enforcer", () => {
data: [{ id: "1", content: "Task 1", status: "pending", priority: "high" }], data: [{ id: "1", content: "Task 1", status: "pending", priority: "high" }],
}), }),
messages: async () => ({ data: mockMessagesWithAssistant }), messages: async () => ({ data: mockMessagesWithAssistant }),
prompt: async (opts: any) => { prompt: async (opts: any) => {
promptCalls.push({ promptCalls.push({
sessionID: opts.path.id, sessionID: opts.path.id,
agent: opts.body.agent, agent: opts.body.agent,
model: opts.body.model, model: opts.body.model,
text: opts.body.parts[0].text, text: opts.body.parts[0].text,
}) })
return {} return {}
}, },
}, promptAsync: async (opts: any) => {
tui: { showToast: async () => ({}) }, promptCalls.push({
}, sessionID: opts.path.id,
directory: "/tmp/test", agent: opts.body.agent,
} as any model: opts.body.model,
text: opts.body.parts[0].text,
})
return {}
},
},
tui: { showToast: async () => ({}) },
},
directory: "/tmp/test",
} as any
const hook = createTodoContinuationEnforcer(mockInput, { const hook = createTodoContinuationEnforcer(mockInput, {
backgroundManager: createMockBackgroundManager(false), backgroundManager: createMockBackgroundManager(false),
}) })
// when - session goes idle // when - session goes idle
await hook.handler({ event: { type: "session.idle", properties: { sessionID } } }) await hook.handler({ event: { type: "session.idle", properties: { sessionID } } })
await fakeTimers.advanceBy(2500) await fakeTimers.advanceBy(2500)
// then - model should be extracted from assistant message's flat modelID/providerID // then - model should be extracted from assistant message's flat modelID/providerID
expect(promptCalls.length).toBe(1) expect(promptCalls.length).toBe(1)
expect(promptCalls[0].model).toEqual({ providerID: "openai", modelID: "gpt-5.2" }) expect(promptCalls[0].model).toEqual({ providerID: "openai", modelID: "gpt-5.2" })
}) })
// ============================================================ // ============================================================
@ -1028,32 +1046,41 @@ describe("todo-continuation-enforcer", () => {
todo: async () => ({ todo: async () => ({
data: [{ id: "1", content: "Task 1", status: "pending", priority: "high" }], data: [{ id: "1", content: "Task 1", status: "pending", priority: "high" }],
}), }),
messages: async () => ({ data: mockMessagesWithCompaction }), messages: async () => ({ data: mockMessagesWithCompaction }),
prompt: async (opts: any) => { prompt: async (opts: any) => {
promptCalls.push({ promptCalls.push({
sessionID: opts.path.id, sessionID: opts.path.id,
agent: opts.body.agent, agent: opts.body.agent,
model: opts.body.model, model: opts.body.model,
text: opts.body.parts[0].text, text: opts.body.parts[0].text,
}) })
return {} return {}
}, },
}, promptAsync: async (opts: any) => {
tui: { showToast: async () => ({}) }, promptCalls.push({
}, sessionID: opts.path.id,
directory: "/tmp/test", agent: opts.body.agent,
} as any model: opts.body.model,
text: opts.body.parts[0].text,
})
return {}
},
},
tui: { showToast: async () => ({}) },
},
directory: "/tmp/test",
} as any
const hook = createTodoContinuationEnforcer(mockInput, { const hook = createTodoContinuationEnforcer(mockInput, {
backgroundManager: createMockBackgroundManager(false), backgroundManager: createMockBackgroundManager(false),
}) })
// when - session goes idle // when - session goes idle
await hook.handler({ event: { type: "session.idle", properties: { sessionID } } }) await hook.handler({ event: { type: "session.idle", properties: { sessionID } } })
await fakeTimers.advanceBy(2500) await fakeTimers.advanceBy(2500)
// then - continuation uses Sisyphus (skipped compaction agent) // then - continuation uses Sisyphus (skipped compaction agent)
expect(promptCalls.length).toBe(1) expect(promptCalls.length).toBe(1)
expect(promptCalls[0].agent).toBe("sisyphus") expect(promptCalls[0].agent).toBe("sisyphus")
}) })
@ -1072,32 +1099,41 @@ describe("todo-continuation-enforcer", () => {
todo: async () => ({ todo: async () => ({
data: [{ id: "1", content: "Task 1", status: "pending", priority: "high" }], data: [{ id: "1", content: "Task 1", status: "pending", priority: "high" }],
}), }),
messages: async () => ({ data: mockMessagesOnlyCompaction }), messages: async () => ({ data: mockMessagesOnlyCompaction }),
prompt: async (opts: any) => { prompt: async (opts: any) => {
promptCalls.push({ promptCalls.push({
sessionID: opts.path.id, sessionID: opts.path.id,
agent: opts.body.agent, agent: opts.body.agent,
model: opts.body.model, model: opts.body.model,
text: opts.body.parts[0].text, text: opts.body.parts[0].text,
}) })
return {} return {}
}, },
}, promptAsync: async (opts: any) => {
tui: { showToast: async () => ({}) }, promptCalls.push({
}, sessionID: opts.path.id,
directory: "/tmp/test", agent: opts.body.agent,
} as any model: opts.body.model,
text: opts.body.parts[0].text,
})
return {}
},
},
tui: { showToast: async () => ({}) },
},
directory: "/tmp/test",
} as any
const hook = createTodoContinuationEnforcer(mockInput, {}) const hook = createTodoContinuationEnforcer(mockInput, {})
// when - session goes idle // when - session goes idle
await hook.handler({ await hook.handler({
event: { type: "session.idle", properties: { sessionID } }, event: { type: "session.idle", properties: { sessionID } },
}) })
await fakeTimers.advanceBy(3000) await fakeTimers.advanceBy(3000)
// then - no continuation (compaction is in default skipAgents) // then - no continuation (compaction is in default skipAgents)
expect(promptCalls).toHaveLength(0) expect(promptCalls).toHaveLength(0)
}) })
@ -1118,32 +1154,41 @@ describe("todo-continuation-enforcer", () => {
todo: async () => ({ todo: async () => ({
data: [{ id: "1", content: "Task 1", status: "pending", priority: "high" }], data: [{ id: "1", content: "Task 1", status: "pending", priority: "high" }],
}), }),
messages: async () => ({ data: mockMessagesPrometheusCompacted }), messages: async () => ({ data: mockMessagesPrometheusCompacted }),
prompt: async (opts: any) => { prompt: async (opts: any) => {
promptCalls.push({ promptCalls.push({
sessionID: opts.path.id, sessionID: opts.path.id,
agent: opts.body.agent, agent: opts.body.agent,
model: opts.body.model, model: opts.body.model,
text: opts.body.parts[0].text, text: opts.body.parts[0].text,
}) })
return {} return {}
}, },
}, promptAsync: async (opts: any) => {
tui: { showToast: async () => ({}) }, promptCalls.push({
}, sessionID: opts.path.id,
directory: "/tmp/test", agent: opts.body.agent,
} as any model: opts.body.model,
text: opts.body.parts[0].text,
})
return {}
},
},
tui: { showToast: async () => ({}) },
},
directory: "/tmp/test",
} as any
const hook = createTodoContinuationEnforcer(mockInput, {}) const hook = createTodoContinuationEnforcer(mockInput, {})
// when - session goes idle // when - session goes idle
await hook.handler({ await hook.handler({
event: { type: "session.idle", properties: { sessionID } }, event: { type: "session.idle", properties: { sessionID } },
}) })
await fakeTimers.advanceBy(3000) await fakeTimers.advanceBy(3000)
// then - no continuation (prometheus found after filtering compaction, prometheus is in skipAgents) // then - no continuation (prometheus found after filtering compaction, prometheus is in skipAgents)
expect(promptCalls).toHaveLength(0) expect(promptCalls).toHaveLength(0)
}) })
@ -1164,32 +1209,41 @@ describe("todo-continuation-enforcer", () => {
todo: async () => ({ todo: async () => ({
data: [{ id: "1", content: "Task 1", status: "pending", priority: "high" }], data: [{ id: "1", content: "Task 1", status: "pending", priority: "high" }],
}), }),
messages: async () => ({ data: mockMessagesNoAgent }), messages: async () => ({ data: mockMessagesNoAgent }),
prompt: async (opts: any) => { prompt: async (opts: any) => {
promptCalls.push({ promptCalls.push({
sessionID: opts.path.id, sessionID: opts.path.id,
agent: opts.body.agent, agent: opts.body.agent,
model: opts.body.model, model: opts.body.model,
text: opts.body.parts[0].text, text: opts.body.parts[0].text,
}) })
return {} return {}
}, },
}, promptAsync: async (opts: any) => {
tui: { showToast: async () => ({}) }, promptCalls.push({
}, sessionID: opts.path.id,
directory: "/tmp/test", agent: opts.body.agent,
} as any model: opts.body.model,
text: opts.body.parts[0].text,
})
return {}
},
},
tui: { showToast: async () => ({}) },
},
directory: "/tmp/test",
} as any
const hook = createTodoContinuationEnforcer(mockInput, { const hook = createTodoContinuationEnforcer(mockInput, {
skipAgents: [], skipAgents: [],
}) })
// when - session goes idle // when - session goes idle
await hook.handler({ await hook.handler({
event: { type: "session.idle", properties: { sessionID } }, event: { type: "session.idle", properties: { sessionID } },
}) })
await wait(2500) await wait(2500)
// then - continuation injected (no agents to skip) // then - continuation injected (no agents to skip)
expect(promptCalls.length).toBe(1) expect(promptCalls.length).toBe(1)