@@ -71,7 +71,7 @@ function parseEventLines(lines: string[]): Array<Record<string, unknown>> {
7171 }
7272
7373 describe("headless", () => {
74- test("runHeadlessPrompt streams NDJSON events and persists the completed turn", async () => {
74+ test("runHeadlessPrompt streams only completed NDJSON events and persists the completed turn", async () => {
7575 faux.setResponses([
7676 fauxAssistantMessage([
7777 fauxThinking("Need to inspect the failing test."),
@@ -89,11 +89,10 @@ describe("headless", () => {
8989
9090 const events = parseEventLines(lines);
9191 expect(stopReason).toBe("stop");
92- expect(events.some((event) => event.type === "thinking_delta")).toBe(true);
93- expect(events.some((event) => event.type === "assistant_message")).toBe(
94- true,
95- );
96- expect(events.at(-1)?.type).toBe("done");
92+ expect(events.map((event) => event.type)).toEqual([
93+ "assistant_message",
94+ "done",
95+ ]);
9796
9897 const sessionId = state.session?.id;
9998 if (!sessionId) {
@@ -174,7 +173,7 @@ describe("headless", () => {
174173 expect(listPromptHistory(state.db, 1)).toEqual([]);
175174 });
176175
177- test("runHeadlessPrompt streams tool execution events for tool-use turns", async () => {
176+ test("runHeadlessPrompt streams only completed events for tool-use turns", async () => {
178177 faux.setResponses([
179178 fauxAssistantMessage(
180179 [fauxToolCall("shell", { command: "printf tool-output" })],
@@ -193,10 +192,12 @@ describe("headless", () => {
193192
194193 const events = parseEventLines(lines);
195194 expect(stopReason).toBe("stop");
196- expect(events.some((event) => event.type === "tool_start")).toBe(true);
197- expect(events.some((event) => event.type === "tool_delta")).toBe(true);
198- expect(events.some((event) => event.type === "tool_end")).toBe(true);
199- expect(events.some((event) => event.type === "tool_result")).toBe(true);
195+ expect(events.map((event) => event.type)).toEqual([
196+ "assistant_message",
197+ "tool_result",
198+ "assistant_message",
199+ "done",
200+ ]);
200201
201202 const sessionId = state.session?.id;
202203 if (!sessionId) {
@@ -221,7 +222,7 @@ describe("headless", () => {
221222 writeLine: (line) => {
222223 lines.push(line);
223224 const event = JSON.parse(line) as { type?: string };
224- if (event.type === "tool_start") {
225+ if (event.type === "assistant_message") {
225226 state.abortController?.abort();
226227 }
227228 },
@@ -229,8 +230,11 @@ describe("headless", () => {
229230
230231 const events = parseEventLines(lines);
231232 expect(stopReason).toBe("aborted");
232- expect(events.some((event) => event.type === "tool_result")).toBe(true);
233- expect(events.at(-1)?.type).toBe("aborted");
233+ expect(events.map((event) => event.type)).toEqual([
234+ "assistant_message",
235+ "tool_result",
236+ "aborted",
237+ ]);
234238
235239 const abortedEvent = events.at(-1);
236240 const message = abortedEvent?.message;