From 624c2c7ec90c4983209699f0cc1440f05f8c4965 Mon Sep 17 00:00:00 2001 From: Lexus2016 Date: Mon, 16 Nov 2026 09:28:19 +0100 Subject: [PATCH] test(global-workspace): wait for startup recovery before seeding in_progress tasks server.js re-arms every in_progress task with no live worker in a setTimeout(..., 3000) after boot. The suite seeds in_progress fixtures as soon as setup completes, so on a slow run the recovery pass flipped them to todo before the overview was read (1 in ~7 runs failed the totals and Beta rollup checks). The recovery callback now prints an unconditional '[startup] in_progress recovery complete' line after processQueue(), and the test waits for it in the captured server output before creating fixtures, instead of relying on a fixed sleep. --- server.js | 3 +++ test/global-workspace.test.js | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/server.js b/server.js index 26cc6828..58bf3bfd 100644 --- a/server.js +++ b/server.js @@ -2955,6 +2955,9 @@ setTimeout(() => { console.log(`[startup] recovered task "${task.title}" (${task.id}): in_progress → ${newStatus || 're-armed'}`); } processQueue(); + // Unconditional and on console (not `log`, which LOG_LEVEL filters): tests that seed + // in_progress rows wait for this line, or this pass re-arms them mid-assertion. + console.log('[startup] in_progress recovery complete'); }, 3000); // Watchdog: detect tasks stuck in 'in_progress' with no live worker process. diff --git a/test/global-workspace.test.js b/test/global-workspace.test.js index 9aa47362..3f0daf37 100644 --- a/test/global-workspace.test.js +++ b/test/global-workspace.test.js @@ -137,6 +137,13 @@ const titles = rows => (rows || []).map(r => r.title).sort(); await api('POST', '/api/projects', { name: 'Gamma', workdir: wdC }); // no tasks at all check('three projects registered', [typeof A, typeof B], ['string', 'string']); + // server.js re-arms every in_progress task with no live worker ~3 s after boot. + // A fixture created before that pass is flipped to todo under the assertions, so + // wait for the line the pass prints when it is done — not a fixed sleep. + const recovered = await waitFor(() => srvLog.includes('[startup] in_progress recovery complete'), + { timeoutMs: 30000, intervalMs: 100 }); + if (!recovered) { console.error('startup recovery never finished:\n' + srvLog); stop(); process.exit(1); } + const now = Math.floor(Date.now() / 1000); const mk = (t) => api('POST', '/api/tasks', t); // Scheduled fixtures are created as in_progress / far-future todo on purpose: