@@ -151,6 +151,44 @@ describe("mapFullStreamToTurnEvents", () => {
151151 ]);
152152 });
153153
154+ test("prefers explicit reasoning events over duplicate openai commentary text in the same step", async () => {
155+ const events = await collectEvents([
156+ { type: "start-step" },
157+ { type: "reasoning-start", id: "rs-1" },
158+ { type: "reasoning-delta", id: "rs-1", delta: "real reasoning" },
159+ { type: "reasoning-end", id: "rs-1" },
160+ {
161+ type: "text-start",
162+ id: "msg-commentary",
163+ providerMetadata: {
164+ openai: { itemId: "msg-commentary", phase: "commentary" },
165+ },
166+ },
167+ {
168+ type: "text-delta",
169+ id: "msg-commentary",
170+ text: "to=functions.shell json{...}",
171+ },
172+ { type: "text-end", id: "msg-commentary" },
173+ {
174+ type: "tool-call",
175+ toolCallId: "call-4",
176+ toolName: "shell",
177+ input: { command: "echo hi" },
178+ },
179+ ]);
180+
181+ expect(events).toEqual([
182+ { type: "reasoning-delta", delta: "real reasoning" },
183+ {
184+ type: "tool-call-start",
185+ toolCallId: "call-4",
186+ toolName: "shell",
187+ args: { command: "echo hi" },
188+ },
189+ ]);
190+ });
191+
154192 test("keeps unphased text deltas visible", async () => {
155193 const events = await collectEvents([
156194 { type: "text-delta", id: "msg-plain", text: "visible" },