Skip to content

Commit f037cc7

Browse files
baxenmbot
andcommitted
test(goose): cover ending the turn after a final send
Co-authored-by: mbot <3754f8729004d95654c46dbab3129e4ab9ef05cc2534e2a3fbfc155983bd637b@buzz.block.builderlab.xyz> Signed-off-by: Bradley Axen <[email protected]>
1 parent e22ade0 commit f037cc7

2 files changed

Lines changed: 127 additions & 0 deletions

File tree

‎src/bundled/goose/goose.live.test.ts‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,37 @@ describe.skipIf(!BIN)("goose-acp", () => {
383383
}
384384
});
385385

386+
it("ends the turn after a final send, keeping the send's result", {
387+
timeout: 180_000,
388+
}, async () => {
389+
const { goose, cwd, tools, sends } = await live();
390+
const cancels: unknown[] = [];
391+
const notify = goose.notify.bind(goose);
392+
goose.notify = (method, params) => {
393+
if (method === "session/cancel") cancels.push(params);
394+
return notify(method, params);
395+
};
396+
try {
397+
const session = await goose.open({
398+
cwd,
399+
tools,
400+
systemPrompt:
401+
"You are a Buzz agent. You reply in Buzz only by calling the send tool, once, with final true.",
402+
});
403+
await session.send("Reply in Buzz with the word hello.");
404+
await session.idle();
405+
expect(cancels).toEqual([{ sessionId: session.id }]);
406+
// goose saved the send's result, not an interrupted call.
407+
await session.send(
408+
"Reply in Buzz with the exact text your last send tool call returned, or the word interrupted if it did not complete.",
409+
);
410+
await session.idle();
411+
expect(sends().at(-1)?.arguments?.text).toContain("Sent.");
412+
} finally {
413+
await goose.kill();
414+
}
415+
});
416+
386417
it("compacts a session, saying so in its text", {
387418
timeout: 180_000,
388419
}, async () => {

‎src/bundled/goose/goose.test.ts‎

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,102 @@ describe("GooseProcess", () => {
385385
},
386386
);
387387

388+
it("ends the turn once goose reports a final send's result", async () => {
389+
const { open, process } = await start();
390+
process.hold = true;
391+
const session = await open();
392+
const settled = session.send("hello");
393+
await flush();
394+
await process.mcp(session.id, "tools/call", {
395+
name: "send",
396+
arguments: { content: "hi", final: true },
397+
});
398+
await expect(settled).resolves.toEqual({ ok: true, answered: true });
399+
// Cancelled before goose has the result, the send would be saved as
400+
// interrupted.
401+
process.update(session.id, {
402+
sessionUpdate: "tool_call_update",
403+
toolCallId: "t1",
404+
status: "in_progress",
405+
});
406+
await flush();
407+
expect(process.cancelled).toEqual([]);
408+
process.update(session.id, {
409+
sessionUpdate: "tool_call_update",
410+
toolCallId: "t1",
411+
status: "completed",
412+
});
413+
await flush();
414+
expect(process.cancelled).toEqual([session.id]);
415+
await session.idle();
416+
expect(session.working).toBe(false);
417+
// The next turn is not cancelled by its own results.
418+
const next = session.send("again");
419+
await flush();
420+
process.update(session.id, {
421+
sessionUpdate: "tool_call_update",
422+
toolCallId: "t2",
423+
status: "completed",
424+
});
425+
await flush();
426+
expect(process.cancelled).toEqual([session.id]);
427+
process.turns[1]?.finish();
428+
await expect(next).resolves.toEqual({ ok: true });
429+
});
430+
431+
it("runs a message that arrives as a final send ends its turn as the next turn", async () => {
432+
const { open, process } = await start();
433+
process.hold = true;
434+
const session = await open();
435+
const first = session.send("one");
436+
await flush();
437+
await process.mcp(session.id, "tools/call", {
438+
name: "send",
439+
arguments: { content: "hi", final: true },
440+
});
441+
await expect(first).resolves.toEqual({ ok: true, answered: true });
442+
const second = session.send("two");
443+
await flush();
444+
expect(process.turns[0]?.steered).toEqual([]);
445+
process.update(session.id, {
446+
sessionUpdate: "tool_call_update",
447+
toolCallId: "t1",
448+
status: "completed",
449+
});
450+
await flush();
451+
expect(process.cancelled).toEqual([session.id]);
452+
expect(process.turns.map((turn) => turn.text)).toEqual(["one", "two"]);
453+
process.turns[1]?.finish();
454+
await expect(second).resolves.toEqual({ ok: true });
455+
});
456+
457+
it("keeps the turn going after a final send while another message waits", async () => {
458+
const { open, process } = await start();
459+
process.hold = true;
460+
const session = await open();
461+
const first = session.send("one");
462+
await flush();
463+
const second = session.send("two");
464+
await flush();
465+
expect(process.turns[0]?.steered).toEqual(["two"]);
466+
await process.mcp(session.id, "tools/call", {
467+
name: "send",
468+
arguments: { content: "hi", final: true },
469+
});
470+
process.update(session.id, {
471+
sessionUpdate: "tool_call_update",
472+
toolCallId: "t1",
473+
status: "completed",
474+
});
475+
await flush();
476+
expect(process.cancelled).toEqual([]);
477+
process.turns[0]?.finish();
478+
await expect(Promise.all([first, second])).resolves.toEqual([
479+
{ ok: true },
480+
{ ok: true, answered: true },
481+
]);
482+
});
483+
388484
it("steers a message that arrives mid-turn into it", async () => {
389485
const { open, process } = await start();
390486
process.hold = true;

0 commit comments

Comments
 (0)