






















@@ -60,10 +60,16 @@ describe("cron tool", () => {
60606161async function executeAddAndReadDelivery(params: {
6262callId: string;
63-agentSessionKey: string;
63+agentSessionKey?: string;
64+currentDeliveryContext?: NonNullable<
65+Parameters<typeof createCronTool>[0]
66+>["currentDeliveryContext"];
6467delivery?: { mode?: string; channel?: string; to?: string } | null;
6568}) {
66-const tool = createTestCronTool({ agentSessionKey: params.agentSessionKey });
69+const tool = createTestCronTool({
70+agentSessionKey: params.agentSessionKey,
71+currentDeliveryContext: params.currentDeliveryContext,
72+});
6773await tool.execute(params.callId, {
6874action: "add",
6975job: {
@@ -415,6 +421,114 @@ describe("cron tool", () => {
415421});
416422});
417423424+it("prefers current delivery context over lowercased session-key targets", async () => {
425+expect(
426+await executeAddAndReadDelivery({
427+callId: "call-current-context",
428+agentSessionKey: "agent:main:matrix:channel:!abcdef1234567890:example.org",
429+currentDeliveryContext: {
430+channel: "matrix",
431+to: "room:!AbCdEf1234567890:example.org",
432+accountId: "bot-a",
433+threadId: "$RootEvent:Example.Org",
434+},
435+}),
436+).toEqual({
437+mode: "announce",
438+channel: "matrix",
439+to: "room:!AbCdEf1234567890:example.org",
440+accountId: "bot-a",
441+threadId: "$RootEvent:Example.Org",
442+});
443+});
444+445+it("does not let current delivery context override explicit delivery targets", async () => {
446+expect(
447+await executeAddAndReadDelivery({
448+callId: "call-explicit-target-wins",
449+agentSessionKey: "agent:main:matrix:channel:!abcdef1234567890:example.org",
450+currentDeliveryContext: {
451+channel: "matrix",
452+to: "room:!AbCdEf1234567890:example.org",
453+},
454+delivery: {
455+mode: "announce",
456+channel: "telegram",
457+to: "-100123",
458+},
459+}),
460+).toEqual({
461+mode: "announce",
462+channel: "telegram",
463+to: "-100123",
464+});
465+});
466+467+it("infers delivery from current context even when no session key is available", async () => {
468+expect(
469+await executeAddAndReadDelivery({
470+callId: "call-context-no-session",
471+currentDeliveryContext: {
472+channel: "matrix",
473+to: "!AbCdEf1234567890:example.org",
474+},
475+}),
476+).toEqual({
477+mode: "announce",
478+channel: "matrix",
479+to: "!AbCdEf1234567890:example.org",
480+});
481+});
482+483+it("uses current delivery context when delivery is null", async () => {
484+expect(
485+await executeAddAndReadDelivery({
486+callId: "call-null-delivery-current-context",
487+agentSessionKey: "agent:main:matrix:channel:!abcdef1234567890:example.org",
488+currentDeliveryContext: {
489+channel: "matrix",
490+to: "!AbCdEf1234567890:example.org",
491+},
492+delivery: null,
493+}),
494+).toEqual({
495+mode: "announce",
496+channel: "matrix",
497+to: "!AbCdEf1234567890:example.org",
498+});
499+});
500+501+it("falls back to session-key inference when current context has no target", async () => {
502+expect(
503+await executeAddAndReadDelivery({
504+callId: "call-empty-current-context",
505+agentSessionKey: "agent:main:telegram:group:-1001234567890:topic:99",
506+currentDeliveryContext: {
507+channel: "matrix",
508+to: " ",
509+},
510+}),
511+).toEqual({
512+mode: "announce",
513+channel: "telegram",
514+to: "-1001234567890:topic:99",
515+});
516+});
517+518+it("does not infer current delivery context when delivery mode is none", async () => {
519+expect(
520+await executeAddAndReadDelivery({
521+callId: "call-current-context-mode-none",
522+agentSessionKey: "agent:main:matrix:channel:!abcdef1234567890:example.org",
523+currentDeliveryContext: {
524+channel: "matrix",
525+to: "!AbCdEf1234567890:example.org",
526+},
527+delivery: { mode: "none" },
528+}),
529+).toEqual({ mode: "none" });
530+});
531+418532it("infers delivery when delivery is null", async () => {
419533expect(
420534await executeAddAndReadDelivery({
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。