/** * run-ui-test — the verdict and the reachability probe. A `--module` that did * not match the manifest (or a `--test-id` matching nothing) used to answer * `totalTests: 0, failed: 0` → `success: true`, exit 0 (D-WARN-10); the SKILL * promised a `/health` pre-check nothing implemented. */ import { describe, it, expect } from 'vitest' import { probeHealth, verdict } from '../execute.js' describe('verdict — a run of zero tests is not a pass', () => { it('fails when no test matched, naming the filter', () => { const v = verdict({ totalTests: 0, passed: 0, failed: 0 }, { module: 'hrm' }) expect(v.success).toBe(false) expect(v.errors[0]).toContain('--module "hrm"') expect(verdict({ totalTests: 0, passed: 0, failed: 0 }, { testId: 'T-9' }).errors[0]).toContain('--test-id "T-9"') expect(verdict({ totalTests: 0, passed: 0, failed: 0 }).errors[0]).toContain('declares no test') }) it('passes only when every matched test passed', () => { expect(verdict({ totalTests: 3, passed: 3, failed: 0 })).toEqual({ success: true, errors: [] }) const v = verdict({ totalTests: 3, passed: 2, failed: 1 }) expect(v.success).toBe(false) expect(v.errors[0]).toContain('1/3') }) }) describe('probeHealth — fails clear when a server is down', () => { const spec = { frontendUrl: 'http://localhost:3000', apiUrl: 'http://localhost:5000/' } it('resolves when both answer below 500', async () => { const seen: string[] = [] const fetchImpl = (async (url: string | URL) => { seen.push(String(url)); return new Response('', { status: 401 }) }) as unknown as typeof fetch await expect(probeHealth(spec, fetchImpl)).resolves.toBeUndefined() expect(seen).toEqual(['http://localhost:5000/health', 'http://localhost:3000']) }) it('throws a clear error when the API is unreachable', async () => { const fetchImpl = (async () => { throw new Error('ECONNREFUSED') }) as unknown as typeof fetch await expect(probeHealth(spec, fetchImpl)).rejects.toThrow(/API not reachable at http:\/\/localhost:5000\/health/) }) it('throws when a server answers 5xx', async () => { const fetchImpl = (async (url: string | URL) => new Response('', { status: String(url).includes('health') ? 200 : 503 })) as unknown as typeof fetch await expect(probeHealth(spec, fetchImpl)).rejects.toThrow(/frontend answered HTTP 503/) }) })