























@@ -49,6 +49,18 @@ describe("runEmbeddedPiAgent incomplete-turn safety", () => {
4949mockedGlobalHookRunner.hasHooks.mockImplementation(() => false);
5050});
515152+function warnMessages(): string[] {
53+return mockedLog.warn.mock.calls.map(([message]) => String(message));
54+}
55+56+function expectWarnMessageWith(text: string): void {
57+expect(warnMessages().some((message) => message.includes(text))).toBe(true);
58+}
59+60+function expectNoWarnMessageWith(text: string): void {
61+expect(warnMessages().some((message) => message.includes(text))).toBe(false);
62+}
63+5264it("emits the before_agent_run hook block message as the agent payload", async () => {
5365mockedRunEmbeddedAttempt.mockResolvedValueOnce(
5466makeAttemptResult({
@@ -207,9 +219,7 @@ describe("runEmbeddedPiAgent incomplete-turn safety", () => {
207219expect(mockedRunEmbeddedAttempt).toHaveBeenCalledTimes(1);
208220expect(result.payloads).toEqual([{ text: "NO_REPLY" }]);
209221expect(result.meta.livenessState).toBe("working");
210-expect(mockedLog.warn).not.toHaveBeenCalledWith(
211-expect.stringContaining("incomplete turn detected"),
212-);
222+expectNoWarnMessageWith("incomplete turn detected");
213223});
214224215225it("uses explicit agentId without a session key before surfacing the strict-agentic blocked state", async () => {
@@ -429,9 +439,7 @@ describe("runEmbeddedPiAgent incomplete-turn safety", () => {
429439expect(mockedRunEmbeddedAttempt).toHaveBeenCalledTimes(2);
430440const secondCall = mockedRunEmbeddedAttempt.mock.calls[1]?.[0] as { prompt?: string };
431441expect(secondCall.prompt).toContain(REASONING_ONLY_RETRY_INSTRUCTION);
432-expect(mockedLog.warn).toHaveBeenCalledWith(
433-expect.stringContaining("reasoning-only assistant turn detected"),
434-);
442+expectWarnMessageWith("reasoning-only assistant turn detected");
435443});
436444437445it("returns NO_REPLY without retrying reasoning-only assistant turns when silence is allowed", async () => {
@@ -467,9 +475,7 @@ describe("runEmbeddedPiAgent incomplete-turn safety", () => {
467475const onlyCall = mockedRunEmbeddedAttempt.mock.calls[0]?.[0] as { prompt?: string };
468476expect(onlyCall.prompt).not.toContain(REASONING_ONLY_RETRY_INSTRUCTION);
469477expect(onlyCall.prompt).not.toContain(EMPTY_RESPONSE_RETRY_INSTRUCTION);
470-expect(mockedLog.warn).not.toHaveBeenCalledWith(
471-expect.stringContaining("reasoning-only assistant turn detected"),
472-);
478+expectNoWarnMessageWith("reasoning-only assistant turn detected");
473479expect(result.payloads).toEqual([{ text: "NO_REPLY" }]);
474480expect(result.meta.terminalReplyKind).toBe("silent-empty");
475481expect(result.meta.livenessState).toBe("working");
@@ -616,7 +622,7 @@ describe("runEmbeddedPiAgent incomplete-turn safety", () => {
616622expect(mockedRunEmbeddedAttempt).toHaveBeenCalledTimes(2);
617623const secondCall = mockedRunEmbeddedAttempt.mock.calls[1]?.[0] as { prompt?: string };
618624expect(secondCall.prompt).toContain(EMPTY_RESPONSE_RETRY_INSTRUCTION);
619-expect(mockedLog.warn).toHaveBeenCalledWith(expect.stringContaining("empty response detected"));
625+expectWarnMessageWith("empty response detected");
620626});
621627622628it("retries zero-token empty Claude stop turns with a visible-answer continuation instruction", async () => {
@@ -670,7 +676,7 @@ describe("runEmbeddedPiAgent incomplete-turn safety", () => {
670676expect(mockedRunEmbeddedAttempt).toHaveBeenCalledTimes(2);
671677const secondCall = mockedRunEmbeddedAttempt.mock.calls[1]?.[0] as { prompt?: string };
672678expect(secondCall.prompt).toContain(EMPTY_RESPONSE_RETRY_INSTRUCTION);
673-expect(mockedLog.warn).toHaveBeenCalledWith(expect.stringContaining("empty response detected"));
679+expectWarnMessageWith("empty response detected");
674680});
675681676682it("retries empty openai-compatible stop turns even when the backend reports output tokens", async () => {
@@ -739,7 +745,7 @@ describe("runEmbeddedPiAgent incomplete-turn safety", () => {
739745expect(mockedRunEmbeddedAttempt).toHaveBeenCalledTimes(2);
740746const secondCall = mockedRunEmbeddedAttempt.mock.calls[1]?.[0] as { prompt?: string };
741747expect(secondCall.prompt).toContain(EMPTY_RESPONSE_RETRY_INSTRUCTION);
742-expect(mockedLog.warn).toHaveBeenCalledWith(expect.stringContaining("empty response detected"));
748+expectWarnMessageWith("empty response detected");
743749});
744750745751it("surfaces an error after exhausting empty-response retries", async () => {
@@ -767,9 +773,7 @@ describe("runEmbeddedPiAgent incomplete-turn safety", () => {
767773expect(mockedRunEmbeddedAttempt).toHaveBeenCalledTimes(2);
768774expect(result.payloads?.[0]?.isError).toBe(true);
769775expect(result.payloads?.[0]?.text).toContain("Please try again");
770-expect(mockedLog.warn).toHaveBeenCalledWith(
771-expect.stringContaining("empty response retries exhausted"),
772-);
776+expectWarnMessageWith("empty response retries exhausted");
773777});
774778775779it("surfaces an error after exhausting reasoning-only retries without a visible answer", async () => {
@@ -807,9 +811,7 @@ describe("runEmbeddedPiAgent incomplete-turn safety", () => {
807811expect(mockedRunEmbeddedAttempt).toHaveBeenCalledTimes(3);
808812expect(result.payloads?.[0]?.isError).toBe(true);
809813expect(result.payloads?.[0]?.text).toContain("Please try again");
810-expect(mockedLog.warn).toHaveBeenCalledWith(
811-expect.stringContaining("reasoning-only retries exhausted"),
812-);
814+expectWarnMessageWith("reasoning-only retries exhausted");
813815});
814816815817it("detects structured bullet-only plans with intent cues as planning-only GPT turns", () => {
@@ -1068,7 +1070,7 @@ describe("runEmbeddedPiAgent incomplete-turn safety", () => {
10681070}),
10691071});
107010721071-expect(incompleteTurnText).toEqual(expect.stringContaining("couldn't generate a response"));
1073+expect(incompleteTurnText).toContain("couldn't generate a response");
10721074});
1073107510741076it("surfaces tool-use terminal with pre-tool text and side effects as replay-unsafe (#76477)", () => {
@@ -1146,9 +1148,7 @@ describe("runEmbeddedPiAgent incomplete-turn safety", () => {
11461148expect(mockedRunEmbeddedAttempt).toHaveBeenCalledTimes(1);
11471149expect(result.payloads?.[0]?.isError).toBe(true);
11481150expect(result.payloads?.[0]?.text).toContain("couldn't generate a response");
1149-expect(mockedLog.warn).toHaveBeenCalledWith(
1150-expect.stringContaining("incomplete turn detected"),
1151-);
1151+expectWarnMessageWith("incomplete turn detected");
11521152});
1153115311541154it("treats missing replay metadata as replay-invalid", () => {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。