Skip to content

Commit 2853ed7

Browse files
committed
addressing codex review
1 parent e7bc597 commit 2853ed7

2 files changed

Lines changed: 58 additions & 3 deletions

File tree

extensions/mattermost/src/mattermost/monitor.inbound-system-event.test.ts

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,59 @@ describe("mattermost inbound user posts", () => {
432432
expect(ctx?.Provider).toBe("mattermost");
433433
});
434434

435-
it("drops posts when channel type cannot be resolved", async () => {
435+
it("uses websocket channel type when REST channel lookup fails", async () => {
436+
const socket = new FakeWebSocket();
437+
const abortController = new AbortController();
438+
mockState.abortController = abortController;
439+
const runtimeCore = createRuntimeCore(testConfig);
440+
mockState.runtimeCore = runtimeCore;
441+
mockState.resolveChannelInfo.mockResolvedValue(null);
442+
443+
const monitor = monitorMattermostProvider({
444+
config: testConfig,
445+
runtime: testRuntime(),
446+
abortSignal: abortController.signal,
447+
webSocketFactory: () => socket,
448+
});
449+
450+
await vi.waitFor(() => {
451+
expect(socket.openListenerCount).toBeGreaterThan(0);
452+
});
453+
socket.emitOpen();
454+
455+
await socket.emitMessage({
456+
event: "posted",
457+
data: {
458+
channel_id: "chan-1",
459+
channel_name: "town-square",
460+
channel_display_name: "Town Square",
461+
channel_type: "O",
462+
sender_name: "alice",
463+
post: JSON.stringify({
464+
id: "post-ws-kind",
465+
channel_id: "chan-1",
466+
user_id: "user-1",
467+
message: "hello with websocket kind",
468+
create_at: 1_714_000_000_000,
469+
}),
470+
},
471+
broadcast: {
472+
channel_id: "chan-1",
473+
user_id: "user-1",
474+
},
475+
});
476+
socket.emitClose(1000);
477+
await monitor;
478+
479+
expect(mockState.dispatchReplyFromConfig).toHaveBeenCalledTimes(1);
480+
const ctx = mockState.dispatchReplyFromConfig.mock.calls.at(0)?.[0].ctx;
481+
expect(ctx?.BodyForAgent).toBe("hello with websocket kind");
482+
expect(ctx?.ChatType).toBe("channel");
483+
expect(ctx?.ConversationLabel).toBe("Town Square id:chan-1");
484+
expect(runtimeCore.channel.session.recordInboundSession).toHaveBeenCalledTimes(1);
485+
});
486+
487+
it("drops posts when neither REST nor websocket channel type can be resolved", async () => {
436488
const socket = new FakeWebSocket();
437489
const abortController = new AbortController();
438490
mockState.abortController = abortController;

extensions/mattermost/src/mattermost/monitor.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,12 +1297,15 @@ export async function monitorMattermostProvider(opts: MonitorMattermostOpts = {}
12971297
}
12981298

12991299
const channelInfo = await resolveChannelInfo(channelId);
1300-
if (!channelInfo?.type) {
1300+
const channelType =
1301+
normalizeOptionalString(channelInfo?.type) ??
1302+
normalizeOptionalString(payload.data?.channel_type);
1303+
if (!channelType) {
13011304
logVerboseMessage(`mattermost: drop post (cannot resolve channel type for ${channelId})`);
13021305
return;
13031306
}
13041307
const kind = resolveMattermostTrustedChatKind({
1305-
channelType: channelInfo.type,
1308+
channelType,
13061309
});
13071310
const chatType = channelChatType(kind);
13081311

0 commit comments

Comments
 (0)