




















@@ -15,6 +15,14 @@ vi.mock("../agent-scope.js", async () => {
1515import { createCronTool } from "./cron-tool.js";
16161717describe("cron tool", () => {
18+type TestDelivery = {
19+mode?: string;
20+channel?: string;
21+to?: string;
22+accountId?: string;
23+threadId?: string | number;
24+};
25+1826function createTestCronTool(
1927opts?: Parameters<typeof createCronTool>[0],
2028): ReturnType<typeof createCronTool> {
@@ -64,7 +72,7 @@ describe("cron tool", () => {
6472currentDeliveryContext?: NonNullable<
6573Parameters<typeof createCronTool>[0]
6674>["currentDeliveryContext"];
67-delivery?: { mode?: string; channel?: string; to?: string } | null;
75+delivery?: TestDelivery | null;
6876}) {
6977const tool = createTestCronTool({
7078agentSessionKey: params.agentSessionKey,
@@ -79,7 +87,7 @@ describe("cron tool", () => {
7987});
80888189const call = callGatewayMock.mock.calls[0]?.[0] as {
82-params?: { delivery?: { mode?: string; channel?: string; to?: string } };
90+params?: { delivery?: TestDelivery };
8391};
8492return call?.params?.delivery;
8593}
@@ -464,6 +472,53 @@ describe("cron tool", () => {
464472});
465473});
466474475+it("keeps explicit delivery account and thread while filling target from context", async () => {
476+expect(
477+await executeAddAndReadDelivery({
478+callId: "call-explicit-delivery-fields-win",
479+agentSessionKey: "agent:main:matrix:channel:!abcdef1234567890:example.org",
480+currentDeliveryContext: {
481+channel: "matrix",
482+to: "!AbCdEf1234567890:example.org",
483+accountId: "context-bot",
484+threadId: "$ContextThread:Example.Org",
485+},
486+delivery: {
487+mode: "announce",
488+accountId: "explicit-bot",
489+threadId: "$ExplicitThread:Example.Org",
490+},
491+}),
492+).toEqual({
493+mode: "announce",
494+channel: "matrix",
495+to: "!AbCdEf1234567890:example.org",
496+accountId: "explicit-bot",
497+threadId: "$ExplicitThread:Example.Org",
498+});
499+});
500+501+it("trims current context fields without changing provider target casing", async () => {
502+expect(
503+await executeAddAndReadDelivery({
504+callId: "call-trim-current-context",
505+agentSessionKey: "agent:main:matrix:channel:!abcdef1234567890:example.org",
506+currentDeliveryContext: {
507+channel: " Matrix ",
508+to: " !AbCdEf1234567890:Example.Org ",
509+accountId: " Bot-A ",
510+threadId: " $RootEvent:Example.Org ",
511+},
512+}),
513+).toEqual({
514+mode: "announce",
515+channel: "matrix",
516+to: "!AbCdEf1234567890:Example.Org",
517+accountId: "bot-a",
518+threadId: "$RootEvent:Example.Org",
519+});
520+});
521+467522it("infers delivery from current context even when no session key is available", async () => {
468523expect(
469524await executeAddAndReadDelivery({
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。