|
1 | 1 | // Tests prompt prelude construction for sender, routing, and context metadata. |
2 | 2 | import { describe, expect, it } from "vitest"; |
| 3 | +import { MESSAGE_TOOL_ONLY_DELIVERY_HINT } from "../../plugin-sdk/message-tool-delivery-hints.js"; |
3 | 4 | import { finalizeInboundContext } from "./inbound-context.js"; |
4 | 5 | import { buildReplyPromptEnvelope } from "./prompt-prelude.js"; |
5 | 6 |
|
| 7 | +function countOccurrences(text: string | undefined, needle: string): number { |
| 8 | + return (text?.split(needle).length ?? 1) - 1; |
| 9 | +} |
| 10 | + |
6 | 11 | describe("buildReplyPromptEnvelope", () => { |
7 | 12 | it("keeps bare reset runtime context in the model prompt and out of transcript/current-turn context", () => { |
8 | 13 | const sessionCtx = finalizeInboundContext({ |
@@ -58,6 +63,64 @@ describe("buildReplyPromptEnvelope", () => { |
58 | 63 | }); |
59 | 64 | }); |
60 | 65 |
|
| 66 | + it("adds one message-tool delivery hint to user-request runtime context only", () => { |
| 67 | + const sessionCtx = finalizeInboundContext({ |
| 68 | + Body: "@bot what changed?", |
| 69 | + BodyStripped: "what changed?", |
| 70 | + Provider: "telegram", |
| 71 | + ChatType: "group", |
| 72 | + InboundEventKind: "user_request", |
| 73 | + }); |
| 74 | + |
| 75 | + const envelope = buildReplyPromptEnvelope({ |
| 76 | + ctx: sessionCtx, |
| 77 | + sessionCtx, |
| 78 | + baseBody: "what changed?", |
| 79 | + prefixedBody: "what changed?", |
| 80 | + hasUserBody: true, |
| 81 | + inboundUserContext: "Current message:\nchat_id=-100123", |
| 82 | + isBareSessionReset: false, |
| 83 | + startupAction: "new", |
| 84 | + inboundEventKind: "user_request", |
| 85 | + sourceReplyDeliveryMode: "message_tool_only", |
| 86 | + }); |
| 87 | + |
| 88 | + expect( |
| 89 | + countOccurrences(envelope.currentInboundContext?.text, MESSAGE_TOOL_ONLY_DELIVERY_HINT), |
| 90 | + ).toBe(1); |
| 91 | + expect(envelope.prefixedCommandBody).toBe("what changed?"); |
| 92 | + expect(envelope.transcriptCommandBody).toBe("what changed?"); |
| 93 | + expect(envelope.transcriptCommandBody).not.toContain(MESSAGE_TOOL_ONLY_DELIVERY_HINT); |
| 94 | + }); |
| 95 | + |
| 96 | + it.each([undefined, "automatic"] as const)( |
| 97 | + "omits user-request delivery hints for %s delivery", |
| 98 | + (sourceReplyDeliveryMode) => { |
| 99 | + const sessionCtx = finalizeInboundContext({ |
| 100 | + Body: "@bot what changed?", |
| 101 | + BodyStripped: "what changed?", |
| 102 | + Provider: "telegram", |
| 103 | + ChatType: "group", |
| 104 | + InboundEventKind: "user_request", |
| 105 | + }); |
| 106 | + |
| 107 | + const envelope = buildReplyPromptEnvelope({ |
| 108 | + ctx: sessionCtx, |
| 109 | + sessionCtx, |
| 110 | + baseBody: "what changed?", |
| 111 | + prefixedBody: "what changed?", |
| 112 | + hasUserBody: true, |
| 113 | + inboundUserContext: "Current message:\nchat_id=-100123", |
| 114 | + isBareSessionReset: false, |
| 115 | + startupAction: "new", |
| 116 | + inboundEventKind: "user_request", |
| 117 | + sourceReplyDeliveryMode, |
| 118 | + }); |
| 119 | + |
| 120 | + expect(envelope.currentInboundContext?.text).not.toContain(MESSAGE_TOOL_ONLY_DELIVERY_HINT); |
| 121 | + }, |
| 122 | + ); |
| 123 | + |
61 | 124 | it("projects room events as context instead of user requests", () => { |
62 | 125 | const sessionCtx = finalizeInboundContext({ |
63 | 126 | Body: "No wtf", |
|
0 commit comments