fix: prevent isolated watchers from blocking chat

This commit is contained in:
Eyejoker
2026-03-23 05:30:58 +09:00
parent cad6ec309c
commit 2eebe3c7f4
2 changed files with 54 additions and 2 deletions

View File

@@ -106,9 +106,52 @@ describe('task scheduler', () => {
await vi.advanceTimersByTimeAsync(10);
expect(enqueueTask).toHaveBeenCalledTimes(1);
expect(enqueueTask.mock.calls[0][0]).toBe('shared@g.us::task:task-codex');
expect(enqueueTask.mock.calls[0][1]).toBe('task-codex');
});
it('keeps group-context tasks on the chat queue key', async () => {
const dueAt = new Date(Date.now() - 60_000).toISOString();
createTask({
id: 'task-group-context',
group_folder: 'shared-group',
chat_jid: 'shared@g.us',
agent_type: 'codex',
prompt: 'group context task',
schedule_type: 'once',
schedule_value: dueAt,
context_mode: 'group',
next_run: dueAt,
status: 'active',
created_at: '2026-02-22T00:00:00.000Z',
});
const enqueueTask = vi.fn();
startSchedulerLoop({
serviceAgentType: 'codex',
registeredGroups: () => ({
'shared@g.us': {
name: 'Shared',
folder: 'shared-group',
trigger: '@Codex',
added_at: '2026-02-22T00:00:00.000Z',
agentType: 'codex',
},
}),
getSessions: () => ({}),
queue: { enqueueTask } as any,
onProcess: () => {},
sendMessage: async () => {},
});
await vi.advanceTimersByTimeAsync(10);
expect(enqueueTask).toHaveBeenCalledTimes(1);
expect(enqueueTask.mock.calls[0][0]).toBe('shared@g.us');
expect(enqueueTask.mock.calls[0][1]).toBe('task-group-context');
});
it('renders watcher heartbeat messages with target and timing', () => {
const prompt = `
[BACKGROUND CI WATCH]