From 12bfd88f3b6d18e95267725422e08f8bf529f357 Mon Sep 17 00:00:00 2001 From: Its-My-Work Date: Tue, 22 Sep 2026 08:49:18 +0000 Subject: [PATCH] fix(test): task-backlog's HOST=localhost server is probed on both loopback families MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In some sandboxes this container's own dual-stack resolution is split: the third test server binds `net.Server.listen(PORT3, 'localhost')` to ::1, while the test client's plain `fetch('http://localhost:PORT3/...')` resolves 'localhost' to 127.0.0.1 only (confirmed with `getent ahosts localhost`) and gets ECONNREFUSED against a server that is, in fact, up — so the readiness loop times out and the whole file is reported as failed, although the feature under test (create_task backlog/todo/done on the Kanban board, the CCS_TASK_MANAGER_SECRET refusal on a non-loopback-literal HOST) is fine. GitHub Actions CI was green throughout, so this is environment-specific, not a bug in server.js: the server's HOST=localhost decision does not depend on which literal address the test then uses to reach it. The two requests to that server now try both 127.0.0.1 and [::1] and use whichever answered. Ran 3x clean, then the whole suite. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01Y2ZSHUdJHqVsvSNQ5ZeQ3f --- test/task-backlog.test.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/test/task-backlog.test.js b/test/task-backlog.test.js index 860bae1d..b7a7a8e4 100644 --- a/test/task-backlog.test.js +++ b/test/task-backlog.test.js @@ -343,13 +343,21 @@ const NEVER = new Date(Date.now() + 365 * 24 * 3600 * 1000).toISOString(); refuse.stdout.on('data', d => { refuseLog += d; }); refuse.stderr.on('data', d => { refuseLog += d; }); process.on('exit', () => { try { refuse.kill('SIGTERM'); } catch {} try { fs.rmSync(APP3, { recursive: true, force: true }); } catch {} }); - let refuseUp = false; - for (let i = 0; i < 80; i++) { - try { const r = await fetch(`http://localhost:${PORT3}/api/health`); if (r.ok) { refuseUp = true; break; } } catch {} - await sleep(250); + // HOST=localhost is a NAME, and this sandbox's own dual-stack resolution is split: the server's + // net.Server.listen('localhost') and the test client's own DNS lookup of 'localhost' do not agree on + // which loopback family to use (observed here: the server binds ::1, a plain lookup of 'localhost' + // answers 127.0.0.1 only) — so a client that also just asks for 'localhost' can get ECONNREFUSED + // against a server that is, in fact, up. The server's HOST=localhost decision (the thing under test) + // does not depend on which literal address the test then uses to reach it, so the client tries both. + let refuseUp = false, refuseHost = null; + for (let i = 0; i < 80 && !refuseUp; i++) { + for (const host of ['127.0.0.1', '[::1]']) { + try { const r = await fetch(`http://${host}:${PORT3}/api/health`); if (r.ok) { refuseUp = true; refuseHost = host; break; } } catch {} + } + if (!refuseUp) await sleep(250); } if (!refuseUp) die(`the refusing server on port ${PORT3} did not start\n${refuseLog}`); - const refuseRes = await fetch(`http://localhost:${PORT3}/api/internal/task-manager`, { + const refuseRes = await fetch(`http://${refuseHost}:${PORT3}/api/internal/task-manager`, { method: 'POST', headers: { 'content-type': 'application/json', authorization: 'Bearer short-secret' }, body: JSON.stringify({ action: 'list_tasks' }),