refactor: centralize visible phase mapping

This commit is contained in:
Eyejoker
2026-03-25 12:04:29 +09:00
parent 1ad23269fa
commit cc7cfbbc5f
4 changed files with 208 additions and 94 deletions

View File

@@ -2192,6 +2192,69 @@ describe('createMessageRuntime', () => {
);
});
it('treats missing streamed phase as final output', async () => {
const chatJid = 'group@test';
const group = makeGroup('claude-code');
const channel = makeChannel(chatJid);
vi.mocked(db.getMessagesSince).mockReturnValue([
{
id: 'msg-1',
chat_jid: chatJid,
sender: 'user@test',
sender_name: 'User',
content: 'hello',
timestamp: '2026-03-19T00:00:00.000Z',
},
]);
vi.mocked(agentRunner.runAgentProcess).mockImplementationOnce(
async (_group, _input, _onProcess, onOutput) => {
await onOutput?.({
status: 'success',
result: 'phase 없는 최종 응답입니다.',
});
return {
status: 'success',
result: null,
};
},
);
const runtime = createMessageRuntime({
assistantName: 'Andy',
idleTimeout: 1_000,
pollInterval: 1_000,
timezone: 'UTC',
triggerPattern: /^@Andy\b/i,
channels: [channel],
queue: {
registerProcess: vi.fn(),
closeStdin: vi.fn(),
notifyIdle: vi.fn(),
} as any,
getRegisteredGroups: () => ({ [chatJid]: group }),
getSessions: () => ({}),
getLastTimestamp: () => '',
setLastTimestamp: vi.fn(),
getLastAgentTimestamps: () => ({}),
saveState: vi.fn(),
persistSession: vi.fn(),
clearSession: vi.fn(),
});
const result = await runtime.processGroupMessages(chatJid, {
runId: 'run-missing-phase-final',
reason: 'messages',
});
expect(result).toBe(true);
expect(channel.sendMessage).toHaveBeenCalledWith(
chatJid,
'phase 없는 최종 응답입니다.',
);
});
it('recovery queues a group when an open work item is waiting for delivery', () => {
const chatJid = 'group@test';
const group = makeGroup('claude-code');