|
5 | 5 | makeEmbeddedRunnerAttempt, |
6 | 6 | } from "../../test-helpers/embedded-agent-runner-e2e-fixtures.js"; |
7 | 7 | import { createEmbeddedRunContextRecoveryState } from "./context-recovery-state.js"; |
| 8 | +import { TRUNCATED_REPLY_NOTICE_TEXT } from "./incomplete-turn-resolution.js"; |
8 | 9 | import { resolveEmbeddedRunAttemptTerminalState } from "./terminal-outcome.js"; |
9 | 10 | import { |
10 | 11 | copyAttemptDeliveryState, |
@@ -247,6 +248,40 @@ describe("terminal resolution", () => { |
247 | 248 | expect(activateInternalPrompt).not.toHaveBeenCalled(); |
248 | 249 | }); |
249 | 250 |
|
| 251 | + it("keeps a length-stopped silent cron result silent", async () => { |
| 252 | + // The only payload is the synthesized silent result of a successful tool and |
| 253 | + // the assistant produced no prose, so there is no partial reply to label; a |
| 254 | + // truncation notice here would turn intentional silence into a message. |
| 255 | + const assistant = emptyAssistant({ stopReason: "length" }); |
| 256 | + const attempt = makeEmbeddedRunnerAttempt({ |
| 257 | + assistantTexts: [], |
| 258 | + toolMetas: [{ toolName: "exec" }], |
| 259 | + messagesSnapshot: [ |
| 260 | + { |
| 261 | + role: "toolResult", |
| 262 | + content: [{ type: "text", text: SILENT_REPLY_TOKEN }], |
| 263 | + details: { aggregated: SILENT_REPLY_TOKEN }, |
| 264 | + } as never, |
| 265 | + assistant, |
| 266 | + ], |
| 267 | + lastAssistant: assistant, |
| 268 | + currentAttemptAssistant: assistant, |
| 269 | + }); |
| 270 | + const input = makeTerminalInput({ |
| 271 | + attempt, |
| 272 | + attemptAssistant: assistant, |
| 273 | + runParams: { trigger: "cron", terminalReplyExpectation: "required" }, |
| 274 | + }); |
| 275 | + |
| 276 | + const resolved = await resolveEmbeddedRunTerminal(input); |
| 277 | + |
| 278 | + expect(resolved.action).toBe("complete"); |
| 279 | + if (resolved.action !== "complete") { |
| 280 | + return; |
| 281 | + } |
| 282 | + expect(resolved.result.payloads).toEqual([{ text: SILENT_REPLY_TOKEN }]); |
| 283 | + }); |
| 284 | + |
250 | 285 | it("completes a reply-optional side-effecting turn as intentional silence", async () => { |
251 | 286 | const assistant = emptyAssistant(); |
252 | 287 | const attempt = makeEmbeddedRunnerAttempt({ |
@@ -575,4 +610,85 @@ describe("terminal resolution", () => { |
575 | 610 | expect(resolved.action).toBe("complete"); |
576 | 611 | expect(activateInternalPrompt).not.toHaveBeenCalled(); |
577 | 612 | }); |
| 613 | + |
| 614 | + it("delivers partial text with a truncation notice when the output budget ends", async () => { |
| 615 | + const assistant = buildEmbeddedRunnerAssistant({ |
| 616 | + stopReason: "length", |
| 617 | + content: [{ type: "text", text: "Here is the first half of the answer" }], |
| 618 | + }); |
| 619 | + const attempt = makeEmbeddedRunnerAttempt({ |
| 620 | + assistantTexts: ["Here is the first half of the answer"], |
| 621 | + lastAssistant: assistant, |
| 622 | + currentAttemptAssistant: assistant, |
| 623 | + currentAttemptReplayMetadata: { hadPotentialSideEffects: false, replaySafe: true }, |
| 624 | + }); |
| 625 | + const resolved = await resolveEmbeddedRunTerminal( |
| 626 | + makeTerminalInput({ |
| 627 | + attempt, |
| 628 | + attemptAssistant: assistant, |
| 629 | + payloadsWithToolMedia: [{ text: "Here is the first half of the answer" }], |
| 630 | + }), |
| 631 | + ); |
| 632 | + |
| 633 | + expect(resolved.action).toBe("complete"); |
| 634 | + if (resolved.action !== "complete") { |
| 635 | + return; |
| 636 | + } |
| 637 | + expect(resolved.result.payloads).toEqual([ |
| 638 | + { text: "Here is the first half of the answer" }, |
| 639 | + { text: TRUNCATED_REPLY_NOTICE_TEXT }, |
| 640 | + ]); |
| 641 | + expect(resolved.result.meta.error).toBeUndefined(); |
| 642 | + expect(resolved.result.meta.livenessState).toBe("working"); |
| 643 | + }); |
| 644 | + |
| 645 | + it("does not add a truncation notice to a length stop that already has terminal output", async () => { |
| 646 | + // Terminal tool media was already a complete outcome before this fix, so it |
| 647 | + // must not gain a notice telling the user to ask for a continuation. |
| 648 | + const assistant = buildEmbeddedRunnerAssistant({ |
| 649 | + stopReason: "length", |
| 650 | + content: [{ type: "text", text: "Chart attached" }], |
| 651 | + }); |
| 652 | + const attempt = makeEmbeddedRunnerAttempt({ |
| 653 | + assistantTexts: ["Chart attached"], |
| 654 | + lastAssistant: assistant, |
| 655 | + currentAttemptAssistant: assistant, |
| 656 | + toolMediaUrls: ["https://example.invalid/chart.png"], |
| 657 | + currentAttemptReplayMetadata: { hadPotentialSideEffects: false, replaySafe: true }, |
| 658 | + }); |
| 659 | + const resolved = await resolveEmbeddedRunTerminal( |
| 660 | + makeTerminalInput({ |
| 661 | + attempt, |
| 662 | + attemptAssistant: assistant, |
| 663 | + payloadsWithToolMedia: [{ text: "Chart attached" }], |
| 664 | + }), |
| 665 | + ); |
| 666 | + |
| 667 | + expect(resolved.action).toBe("complete"); |
| 668 | + if (resolved.action !== "complete") { |
| 669 | + return; |
| 670 | + } |
| 671 | + expect(resolved.result.payloads).toEqual([{ text: "Chart attached" }]); |
| 672 | + }); |
| 673 | + |
| 674 | + it("still reports an incomplete turn when the output budget ends with no text", async () => { |
| 675 | + const assistant = emptyAssistant({ stopReason: "length" }); |
| 676 | + const attempt = makeEmbeddedRunnerAttempt({ |
| 677 | + assistantTexts: [], |
| 678 | + lastAssistant: assistant, |
| 679 | + currentAttemptAssistant: assistant, |
| 680 | + currentAttemptReplayMetadata: { hadPotentialSideEffects: false, replaySafe: true }, |
| 681 | + }); |
| 682 | + const resolved = await resolveEmbeddedRunTerminal( |
| 683 | + makeTerminalInput({ attempt, attemptAssistant: assistant }), |
| 684 | + ); |
| 685 | + |
| 686 | + expect(resolved.action).toBe("complete"); |
| 687 | + if (resolved.action !== "complete") { |
| 688 | + return; |
| 689 | + } |
| 690 | + expect(resolved.result.payloads?.[0]).toMatchObject({ isError: true }); |
| 691 | + expect(resolved.result.meta.error?.kind).toBe("incomplete_turn"); |
| 692 | + expect(resolved.result.meta.livenessState).toBe("abandoned"); |
| 693 | + }); |
578 | 694 | }); |
0 commit comments