






















@@ -1,4 +1,4 @@
1-import { afterEach, beforeEach, describe, expect, it } from "vitest";
1+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
22import type { SkillSnapshot } from "../../agents/skills.js";
33import type { CronDeliveryMode } from "../types.js";
44import type { MutableCronSession } from "./run-session-state.js";
@@ -695,16 +695,17 @@ describe("runCronIsolatedAgentTurn message tool policy", () => {
695695resolveCronDeliveryPlanMock.mockReturnValue({
696696requested: true,
697697mode: "announce",
698-channel: "last",
698+channel: "messagechat",
699+to: "bad-target",
699700});
700701resolveDeliveryTargetMock.mockResolvedValue({
701702ok: false,
702-channel: undefined,
703+channel: "messagechat",
703704to: undefined,
704705accountId: undefined,
705706threadId: undefined,
706-mode: "implicit",
707-error: new Error("sessionKey is required to resolve delivery.channel=last"),
707+mode: "explicit",
708+error: new Error("Invalid delivery target: unknown recipient"),
708709});
709710runEmbeddedPiAgentMock.mockResolvedValue(
710711makeMessageToolRunResult([{ tool: "message", provider: "messagechat", to: "123" }]),
@@ -720,15 +721,64 @@ describe("runCronIsolatedAgentTurn message tool policy", () => {
720721unverifiedMessagingToolDelivery: true,
721722}),
722723);
724+expect(result.delivery).toEqual(
725+expect.objectContaining({
726+intended: { channel: "messagechat", to: "bad-target", source: "explicit" },
727+resolved: expect.objectContaining({
728+ok: false,
729+channel: "messagechat",
730+source: "explicit",
731+error: "Invalid delivery target: unknown recipient",
732+}),
733+messageToolSentTo: [{ channel: "messagechat", to: "123" }],
734+fallbackUsed: false,
735+delivered: false,
736+}),
737+);
738+});
739+740+it("fails implicit announce delivery before running the agent when last has no route", async () => {
741+const onExecutionStarted = vi.fn();
742+resolveCronDeliveryPlanMock.mockReturnValue({
743+requested: true,
744+mode: "announce",
745+channel: "last",
746+});
747+resolveDeliveryTargetMock.mockResolvedValue({
748+ok: false,
749+channel: undefined,
750+to: undefined,
751+accountId: undefined,
752+threadId: undefined,
753+mode: "implicit",
754+error: new Error("Channel is required when delivery.channel=last has no previous channel."),
755+});
756+757+const result = await runCronIsolatedAgentTurn({
758+ ...makeParams(),
759+ onExecutionStarted,
760+});
761+762+expect(runEmbeddedPiAgentMock).not.toHaveBeenCalled();
763+expect(dispatchCronDeliveryMock).not.toHaveBeenCalled();
764+expect(onExecutionStarted).not.toHaveBeenCalled();
765+expect(result).toEqual(
766+expect.objectContaining({
767+status: "error",
768+error: "Channel is required when delivery.channel=last has no previous channel.",
769+errorKind: "delivery-target",
770+delivered: false,
771+deliveryAttempted: false,
772+}),
773+);
723774expect(result.delivery).toEqual(
724775expect.objectContaining({
725776intended: { channel: "last", to: null, source: "last" },
726777resolved: expect.objectContaining({
727778ok: false,
728779source: "last",
729-error: "sessionKey is required to resolve delivery.channel=last",
780+error: "Channel is required when delivery.channel=last has no previous channel.",
730781}),
731-messageToolSentTo: [{ channel: "messagechat", to: "123" }],
732782fallbackUsed: false,
733783delivered: false,
734784}),
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。