fix: wake origin workflow after discussion callback

This commit is contained in:
zhi
2026-04-02 08:20:23 +00:00
parent 29f1f01219
commit 7bccb660df
4 changed files with 69 additions and 19 deletions

View File

@@ -2,7 +2,9 @@ import test from 'node:test';
import assert from 'node:assert/strict';
import { registerBeforeMessageWriteHook } from '../plugin/hooks/before-message-write.ts';
import { registerMessageReceivedHook } from '../plugin/hooks/message-received.ts';
import { registerMessageSentHook } from '../plugin/hooks/message-sent.ts';
import { buildDiscussionOriginCallbackMessage } from '../plugin/core/discussion-messages.ts';
import { initTurnOrder, onNewMessage, getTurnDebugInfo, resetTurn } from '../plugin/turn-manager.ts';
type Handler = (event: Record<string, unknown>, ctx: Record<string, unknown>) => unknown;
@@ -86,6 +88,48 @@ test('before_message_write leaves ordinary channels dormant without sending a di
assert.equal(getTurnDebugInfo(channelId).dormant, true);
});
test('message_received lets moderator discussion callback notifications wake the origin channel workflow', async () => {
const channelId = '1474327736242798612';
resetTurn(channelId);
initTurnOrder(channelId, ['agent-a', 'agent-b']);
assert.equal(getTurnDebugInfo(channelId).currentSpeaker, null);
const api = makeApi();
registerMessageReceivedHook({
api: api as any,
baseConfig: {
moderatorUserId: 'moderator-user',
humanList: ['human-user'],
} as any,
shouldDebugLog: () => false,
debugCtxSummary: () => ({}),
ensureTurnOrder: () => {},
getModeratorUserId: (cfg) => (cfg as any).moderatorUserId,
recordChannelAccount: () => false,
extractMentionedUserIds: () => [],
buildUserIdToAccountIdMap: () => new Map(),
enterMultiMessageMode: () => {},
exitMultiMessageMode: () => {},
discussionService: {
maybeReplyClosedChannel: async () => false,
},
});
const messageReceived = api.handlers.get('message_received');
assert.ok(messageReceived);
await messageReceived?.({
content: buildDiscussionOriginCallbackMessage('/workspace/plans/discussion-summary.md', 'discussion-42'),
from: 'moderator-user',
}, {
conversationId: channelId,
});
const state = getTurnDebugInfo(channelId);
assert.equal(state.currentSpeaker, state.turnOrder[0]);
assert.equal(state.dormant, false);
});
test('message_sent skips handoff after discuss-callback has closed the discussion channel', async () => {
const channelId = 'discussion-closed-channel';
resetTurn(channelId);