test(claude): split the thinking-restart regression into two tests

Each case now states its own setup instead of branching inside one test body.
This commit is contained in:
paseo-bot[bot]
2026-10-13 16:42:51 +02:00
parent 870c8dc9c5
commit f02537727a
@@ -278,45 +278,63 @@ afterEach(() => {
queryFactory.mockReset();
});
test.each([false, true])(
"submits after a thinking change with no live query (previous query ended: %s)",
async (previousQueryEnded) => {
const queries: ScriptedQuery[] = [];
queryFactory.mockImplementation(({ prompt }: { prompt: AsyncIterable<unknown> }) => {
const scriptedQuery = createScriptedQuery({
prompt,
sessionId: "thinking-restart-session",
handlePrompt: ({ query }) => query.emit(buildSuccessResult("thinking-restart-session")),
});
queries.push(scriptedQuery);
return scriptedQuery;
async function createThinkingRestartSession() {
const queries: ScriptedQuery[] = [];
queryFactory.mockImplementation(({ prompt }: { prompt: AsyncIterable<unknown> }) => {
const scriptedQuery = createScriptedQuery({
prompt,
sessionId: "thinking-restart-session",
handlePrompt: ({ query }) => query.emit(buildSuccessResult("thinking-restart-session")),
});
const session = await new ClaudeAgentClient({
logger: createTestLogger(),
queryFactory,
resolveBinary: async () => "/test/claude/bin",
}).createSession({ provider: "claude", cwd: process.cwd() });
queries.push(scriptedQuery);
return scriptedQuery;
});
const session = await new ClaudeAgentClient({
logger: createTestLogger(),
queryFactory,
resolveBinary: async () => "/test/claude/bin",
}).createSession({ provider: "claude", cwd: process.cwd() });
return { session, queries };
}
try {
if (previousQueryEnded) {
await collectUntilTerminal(streamSession(session, "first prompt"));
queries[0].end();
// Let the pump retire the old query before changing thinking.
await new Promise((resolve) => setTimeout(resolve, 0));
}
await session.setThinkingOption!("medium");
const events = await collectUntilTerminal(
streamSession(session, "continue", { clientMessageId: "client-continue" }),
);
expect(events.filter((event) => event.type === "turn_failed")).toEqual([]);
expect(events.at(-1)?.type).toBe("turn_completed");
expect(queryFactory).toHaveBeenCalledTimes(previousQueryEnded ? 2 : 1);
expect(queries.at(-1)?.prompts.map((prompt) => prompt.text)).toEqual(["continue"]);
} finally {
await session.close();
}
},
);
test("submits after a thinking change before the first turn", async () => {
const { session, queries } = await createThinkingRestartSession();
try {
await session.setThinkingOption!("medium");
const events = await collectUntilTerminal(
streamSession(session, "continue", { clientMessageId: "client-continue" }),
);
expect(events.filter((event) => event.type === "turn_failed")).toEqual([]);
expect(events.at(-1)?.type).toBe("turn_completed");
expect(queryFactory).toHaveBeenCalledTimes(1);
expect(queries[0].prompts.map((prompt) => prompt.text)).toEqual(["continue"]);
} finally {
await session.close();
}
});
test("submits after a thinking change once the previous query ended", async () => {
const { session, queries } = await createThinkingRestartSession();
try {
await collectUntilTerminal(streamSession(session, "first prompt"));
queries[0].end();
// Let the pump retire the old query before changing thinking.
await new Promise((resolve) => setTimeout(resolve, 0));
await session.setThinkingOption!("medium");
const events = await collectUntilTerminal(
streamSession(session, "continue", { clientMessageId: "client-continue" }),
);
expect(events.filter((event) => event.type === "turn_failed")).toEqual([]);
expect(events.at(-1)?.type).toBe("turn_completed");
expect(queryFactory).toHaveBeenCalledTimes(2);
expect(queries[1].prompts.map((prompt) => prompt.text)).toEqual(["continue"]);
} finally {
await session.close();
}
});
test("interrupt only calls query.interrupt and leaves the query open", async () => {
const logger = createTestLogger();