@@ -323,7 +323,7 @@ describe("validateAnthropicTurns", () => {
|
323 | 323 | ]); |
324 | 324 | }); |
325 | 325 | |
326 | | -it("should not merge consecutive assistant messages", () => { |
| 326 | +it("merges consecutive assistant messages", () => { |
327 | 327 | const msgs = asMessages([ |
328 | 328 | { role: "user", content: [{ type: "text", text: "Question" }] }, |
329 | 329 | { |
@@ -338,7 +338,60 @@ describe("validateAnthropicTurns", () => {
|
338 | 338 | |
339 | 339 | const result = validateAnthropicTurns(msgs); |
340 | 340 | |
341 | | -expect(result).toEqual(msgs); |
| 341 | +expect(result).toEqual([ |
| 342 | +{ role: "user", content: [{ type: "text", text: "Question" }] }, |
| 343 | +{ |
| 344 | +role: "assistant", |
| 345 | +content: [ |
| 346 | +{ type: "text", text: "Answer 1" }, |
| 347 | +{ type: "text", text: "Answer 2" }, |
| 348 | +], |
| 349 | +}, |
| 350 | +]); |
| 351 | +}); |
| 352 | + |
| 353 | +it("merges an injected assistant turn before validating signed tool-result pairing", () => { |
| 354 | +const msgs = asMessages([ |
| 355 | +{ role: "user", content: [{ type: "text", text: "Use the gateway" }] }, |
| 356 | +{ |
| 357 | +role: "assistant", |
| 358 | +content: makeSignedThinkingGatewayToolCall("tool-1"), |
| 359 | +stopReason: "toolUse", |
| 360 | +}, |
| 361 | +{ |
| 362 | +role: "assistant", |
| 363 | +content: [{ type: "text", text: "Subagent completion delivered." }], |
| 364 | +stopReason: "stop", |
| 365 | +}, |
| 366 | +{ |
| 367 | +role: "toolResult", |
| 368 | +toolUseId: "tool-1", |
| 369 | +toolName: "gateway", |
| 370 | +content: [{ type: "text", text: "done" }], |
| 371 | +isError: false, |
| 372 | +}, |
| 373 | +]); |
| 374 | + |
| 375 | +const result = validateAnthropicTurns(msgs); |
| 376 | + |
| 377 | +expect(result).toEqual([ |
| 378 | +{ role: "user", content: [{ type: "text", text: "Use the gateway" }] }, |
| 379 | +{ |
| 380 | +role: "assistant", |
| 381 | +content: [ |
| 382 | + ...makeSignedThinkingGatewayToolCall("tool-1"), |
| 383 | +{ type: "text", text: "Subagent completion delivered." }, |
| 384 | +], |
| 385 | +stopReason: "stop", |
| 386 | +}, |
| 387 | +{ |
| 388 | +role: "toolResult", |
| 389 | +toolUseId: "tool-1", |
| 390 | +toolName: "gateway", |
| 391 | +content: [{ type: "text", text: "done" }], |
| 392 | +isError: false, |
| 393 | +}, |
| 394 | +]); |
342 | 395 | }); |
343 | 396 | |
344 | 397 | it("should handle mixed scenario with steering messages", () => { |
|