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); }); });