Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion packages/mcp/channels-catch-up.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const buildMessage = (
readonly channel?: string
readonly thread?: string
readonly mentions?: ReadonlyArray<Identity>
readonly sender?: Identity
} = {},
): Message => ({
ref: {
Expand All @@ -73,7 +74,7 @@ const buildMessage = (
`https://zulip.example.com/#narrow/channel/${opts.channel ?? 'general'}/near/${ts}`,
),
},
sender: human,
sender: opts.sender ?? human,
body: decodeMessageBodySync(body),
ts: decodeTimestampSync(ts),
mentions: userMentions(opts.mentions ?? []),
Expand Down Expand Up @@ -267,6 +268,25 @@ describe('catchUpChannels', () => {
expect(notifier.payloads[0]?.meta['mentioned']).toBe('true')
})

test("the bound bot's own posts are not dispatched back to it", async () => {
const history = buildHistorySpy({
general: [
buildMessage(4800, 'from-carol'),
buildMessage(4850, 'from-me', { sender: botIdentity }),
buildMessage(4900, 'carol-again'),
],
})
const notifier = buildNotifierSpy()
await runCatchUp({
intents: [{ kind: 'channel', channelName: decodeChannelNameSync('general') }],
history: history.history,
notifier: notifier.notifier,
botIdentityId: botIdentity.id,
windowSeconds: 400,
})
expect(notifier.payloads.map((p) => p.content)).toEqual(['from-carol', 'carol-again'])
})

test('botIdentityId undefined → payload omits mentioned meta but still dispatches', async () => {
const history = buildHistorySpy({
general: [buildMessage(4900, 'hi', { mentions: [botIdentity] })],
Expand Down
4 changes: 3 additions & 1 deletion packages/mcp/channels-catch-up.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,10 @@ export const catchUpChannels = (deps: ChannelsCatchUpDeps): Effect.Effect<void,
fetchForIntent(intent, deps.history, since, newTopicsSince).pipe(catchUpAt('history')),
{ concurrency: 2 },
)
// The live pump drops the seat's own posts as self-echo; a catch-up that
// did not would hand them back to their author.
const messages = Arr.sort(
Arr.flatten(batches),
Arr.filter(Arr.flatten(batches), (m) => m.sender.id !== deps.botIdentityId),
Order.mapInput(Order.number, (m: Message) => m.ts),
)
yield* Effect.forEach(
Expand Down
Loading