























@@ -147,6 +147,14 @@ function expectEmbeddedRunFields(expected: Record<string, unknown>): Record<stri
147147);
148148}
149149150+function expectEmbeddedRunPrompt(): string {
151+const prompt = expectEmbeddedRunFields({}).prompt;
152+if (typeof prompt !== "string") {
153+throw new Error("expected embedded run prompt to be a string");
154+}
155+return prompt;
156+}
157+150158function expectDispatchFields(expected: Record<string, unknown>): Record<string, unknown> {
151159return expectRecordFields(
152160getMockCallArg(dispatchCronDeliveryMock, 0, 0, "cron delivery dispatch"),
@@ -175,8 +183,10 @@ describe("runCronIsolatedAgentTurn message tool policy", () => {
175183resolveCronDeliveryPlanMock.mockReturnValue(plan);
176184await runCronIsolatedAgentTurn(makeParams());
177185expect(runEmbeddedPiAgentMock).toHaveBeenCalledTimes(1);
178-expect(runEmbeddedPiAgentMock.mock.calls[0]?.[0]?.disableMessageTool).toBe(true);
179-expect(runEmbeddedPiAgentMock.mock.calls[0]?.[0]?.forceMessageTool).toBe(false);
186+expectEmbeddedRunFields({
187+disableMessageTool: true,
188+forceMessageTool: false,
189+});
180190}
181191182192async function expectMessageToolEnabledForPlan(plan: {
@@ -189,8 +199,10 @@ describe("runCronIsolatedAgentTurn message tool policy", () => {
189199resolveCronDeliveryPlanMock.mockReturnValue(plan);
190200await runCronIsolatedAgentTurn(makeParams());
191201expect(runEmbeddedPiAgentMock).toHaveBeenCalledTimes(1);
192-expect(runEmbeddedPiAgentMock.mock.calls[0]?.[0]?.disableMessageTool).toBe(false);
193-expect(runEmbeddedPiAgentMock.mock.calls[0]?.[0]?.forceMessageTool).toBe(true);
202+expectEmbeddedRunFields({
203+disableMessageTool: false,
204+forceMessageTool: true,
205+});
194206}
195207196208async function runModeNoneDeliveryCase(params: {
@@ -352,12 +364,12 @@ describe("runCronIsolatedAgentTurn message tool policy", () => {
352364353365expect(resolveDeliveryTargetMock).not.toHaveBeenCalled();
354366expect(runEmbeddedPiAgentMock).toHaveBeenCalledTimes(1);
355-expectEmbeddedRunFields({
367+const embeddedRun = expectEmbeddedRunFields({
356368disableMessageTool: false,
357369forceMessageTool: true,
358370});
359-expect(runEmbeddedPiAgentMock.mock.calls[0]?.[0]?.messageChannel).toBeUndefined();
360-expect(runEmbeddedPiAgentMock.mock.calls[0]?.[0]?.messageTo).toBeUndefined();
371+expect(embeddedRun.messageChannel).toBeUndefined();
372+expect(embeddedRun.messageTo).toBeUndefined();
361373});
362374363375it('suppresses automatic exec completion notifications when delivery.mode is "none"', async () => {
@@ -474,12 +486,12 @@ describe("runCronIsolatedAgentTurn message tool policy", () => {
474486475487expect(resolveDeliveryTargetMock).not.toHaveBeenCalled();
476488expect(runEmbeddedPiAgentMock).toHaveBeenCalledTimes(1);
477-expectEmbeddedRunFields({
489+const embeddedRun = expectEmbeddedRunFields({
478490disableMessageTool: false,
479491forceMessageTool: true,
480492});
481-expect(runEmbeddedPiAgentMock.mock.calls[0]?.[0]?.messageChannel).toBeUndefined();
482-expect(runEmbeddedPiAgentMock.mock.calls[0]?.[0]?.messageTo).toBeUndefined();
493+expect(embeddedRun.messageChannel).toBeUndefined();
494+expect(embeddedRun.messageTo).toBeUndefined();
483495});
484496485497it("resolves implicit last-target context for delivery.mode none with only accountId", async () => {
@@ -561,7 +573,7 @@ describe("runCronIsolatedAgentTurn message tool policy", () => {
561573});
562574563575expect(runEmbeddedPiAgentMock).toHaveBeenCalledTimes(1);
564-expect(runEmbeddedPiAgentMock.mock.calls[0]?.[0]?.execOverrides).toBeUndefined();
576+expect(expectEmbeddedRunFields({}).execOverrides).toBeUndefined();
565577});
566578567579it("keeps automatic exec completion notifications when webhook delivery is active", async () => {
@@ -581,7 +593,7 @@ describe("runCronIsolatedAgentTurn message tool policy", () => {
581593});
582594583595expect(runEmbeddedPiAgentMock).toHaveBeenCalledTimes(1);
584-expect(runEmbeddedPiAgentMock.mock.calls[0]?.[0]?.execOverrides).toBeUndefined();
596+expect(expectEmbeddedRunFields({}).execOverrides).toBeUndefined();
585597});
586598587599it("disables the message tool when webhook delivery is active", async () => {
@@ -602,7 +614,7 @@ describe("runCronIsolatedAgentTurn message tool policy", () => {
602614await runCronIsolatedAgentTurn(makeParams());
603615604616expect(runEmbeddedPiAgentMock).toHaveBeenCalledTimes(1);
605-expect(runEmbeddedPiAgentMock.mock.calls[0]?.[0]?.disableMessageTool).toBe(false);
617+expectEmbeddedRunFields({ disableMessageTool: false });
606618});
607619608620it("skips cron delivery when output is heartbeat-only", async () => {
@@ -883,7 +895,7 @@ describe("runCronIsolatedAgentTurn delivery instruction", () => {
883895await runCronIsolatedAgentTurn(makeParams());
884896885897expect(runEmbeddedPiAgentMock).toHaveBeenCalledTimes(1);
886-const prompt: string = runEmbeddedPiAgentMock.mock.calls[0]?.[0]?.prompt ?? "";
898+const prompt = expectEmbeddedRunPrompt();
887899expect(prompt).toContain("Use the message tool");
888900expect(prompt).toContain("will be delivered automatically");
889901expect(prompt).not.toContain("note who/where");
@@ -907,7 +919,7 @@ describe("runCronIsolatedAgentTurn delivery instruction", () => {
907919});
908920909921expect(runEmbeddedPiAgentMock).toHaveBeenCalledTimes(1);
910-const prompt: string = runEmbeddedPiAgentMock.mock.calls[0]?.[0]?.prompt ?? "";
922+const prompt = expectEmbeddedRunPrompt();
911923expect(prompt).not.toContain("Use the message tool");
912924expect(prompt).toContain("Return your response as plain text");
913925});
@@ -919,7 +931,7 @@ describe("runCronIsolatedAgentTurn delivery instruction", () => {
919931await runCronIsolatedAgentTurn(makeParams());
920932921933expect(runEmbeddedPiAgentMock).toHaveBeenCalledTimes(1);
922-const prompt: string = runEmbeddedPiAgentMock.mock.calls[0]?.[0]?.prompt ?? "";
934+const prompt = expectEmbeddedRunPrompt();
923935expect(prompt).not.toContain("Return your response as plain text");
924936expect(prompt).not.toContain("it will be delivered automatically");
925937});
@@ -939,7 +951,7 @@ describe("runCronIsolatedAgentTurn delivery instruction", () => {
939951await runCronIsolatedAgentTurn(makeParams());
940952941953expect(runEmbeddedPiAgentMock).toHaveBeenCalledTimes(1);
942-const prompt: string = runEmbeddedPiAgentMock.mock.calls[0]?.[0]?.prompt ?? "";
954+const prompt = expectEmbeddedRunPrompt();
943955expect(prompt).not.toMatch(/\bsummary\b/i);
944956});
945957});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。