Skip to content

Commit 71b7aec

Browse files
committed
fix(outbound): preserve visible text when chunkers return no parts
1 parent 7439cd3 commit 71b7aec

2 files changed

Lines changed: 35 additions & 4 deletions

File tree

‎src/infra/outbound/message-plan.test.ts‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,39 @@ describe("outbound message planning", () => {
3333
expect(units.map((unit) => unit.overrides.deliveryPartCount)).toEqual([2, 2]);
3434
});
3535

36+
it.each([
37+
{ label: "default", chunkMode: undefined },
38+
{ label: "length", chunkMode: "length" as const },
39+
{ label: "newline", chunkMode: "newline" as const },
40+
])("preserves nonempty text when a $label chunker returns nothing", ({ chunkMode }) => {
41+
const policy = createReplyToDeliveryPolicy({ replyToId: "reply-1", replyToMode: "first" });
42+
const reply = policy.resolveCurrentReplyTo({});
43+
const units = planOutboundTextMessageUnits({
44+
text: "visible reply",
45+
textLimit: 64,
46+
chunkMode,
47+
chunker: () => [],
48+
overrides: { replyToId: reply.replyToId, replyToIdSource: reply.source },
49+
consumeReplyTo: (overrides) =>
50+
policy.applyReplyToConsumption(overrides, {
51+
consumeImplicitReply: overrides.replyToIdSource === "implicit",
52+
}),
53+
});
54+
55+
expect(units).toEqual([
56+
{
57+
kind: "text",
58+
text: "visible reply",
59+
overrides: {
60+
replyToId: "reply-1",
61+
replyToIdSource: "implicit",
62+
deliveryPartIndex: 0,
63+
deliveryPartCount: 1,
64+
},
65+
},
66+
]);
67+
});
68+
3669
it("keeps explicit text replies from consuming the implicit slot", () => {
3770
const policy = createReplyToDeliveryPolicy({
3871
replyToId: "implicit-reply",

‎src/infra/outbound/message-plan.ts‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,10 @@ function chunkTextForPlan(params: {
8989
chunker: OutboundMessageChunker;
9090
formatting?: OutboundDeliveryFormattingOptions;
9191
}): string[] {
92-
return params.formatting
92+
const chunks = params.formatting
9393
? params.chunker(params.text, params.limit, { formatting: params.formatting })
9494
: params.chunker(params.text, params.limit);
95+
return chunks.length === 0 && params.text ? [params.text] : chunks;
9596
}
9697

9798
/**
@@ -158,9 +159,6 @@ export function planOutboundTextMessageUnits(params: {
158159
chunker: params.chunker,
159160
formatting: params.formatting,
160161
});
161-
if (!chunks.length && blockChunk) {
162-
chunks.push(blockChunk);
163-
}
164162
for (const chunk of chunks) {
165163
units.push(planTextUnit(chunk, units.length, params.chunkedTextFormatting));
166164
}

0 commit comments

Comments
 (0)