wishforge-ide/tests/runner-log.test.ts
eust-w ddb4cf5b5f 🐛 Stop the Runner reporting the control plane's own start-up as errors
The local service starts the Runner together with the control plane,
so its first polls were refused until the API listened, and every
restart left an ECONNREFUSED error line every five seconds in
runner.log that looked like a failure.

Until the Runner has reached the control plane once, and for two
minutes at most, a refused connection is now noted once as waiting for
it to start; reaching it is noted too. A control plane that never
comes up, and any other failure, are still errors.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 14:54:01 +08:00

20 lines
1.1 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import { STARTUP_GRACE_MS, startingUp } from '../apps/runner/src/log.js';
describe('Runner log while the local service starts', () => {
const refused = Object.assign(new Error('connect ECONNREFUSED 127.0.0.1:4000'), { code: 'ECONNREFUSED' });
const started = 1_000_000;
it('treats a refused connection as the control plane still starting, only before it first answers', () => {
expect(startingUp(refused, false, started, started + 5_000)).toBe(true);
// fetch wraps the socket error as its cause.
expect(startingUp(new TypeError('fetch failed', { cause: refused }), false, started, started + 5_000)).toBe(true);
expect(startingUp(refused, true, started, started + 5_000)).toBe(false);
});
it('reports a control plane that never comes up, and any other failure, as errors', () => {
expect(startingUp(refused, false, started, started + STARTUP_GRACE_MS)).toBe(false);
expect(startingUp(new Error('Runner token rejected'), false, started, started + 5_000)).toBe(false);
expect(startingUp(undefined, false, started, started + 5_000)).toBe(false);
});
});