100 lines
4.1 KiB
TypeScript
100 lines
4.1 KiB
TypeScript
/**
|
|
* Regression tests for the agent health-check page (TSK-0230, HOF-0085).
|
|
* - GET /agent-health serves the page with the per-agent traffic light
|
|
* (same agentLight data as /health — reused, not duplicated).
|
|
* - The test-message wiring + cross-messaging data ship with the page.
|
|
* - The page surfaces the transport mode (SSE vs polling fallback).
|
|
*/
|
|
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
|
import { mkdtempSync, rmSync } from 'fs';
|
|
import { tmpdir } from 'os';
|
|
import { join } from 'path';
|
|
import { buildApp } from '../src/server/index.js';
|
|
import { init } from '../src/cli/commands/init.js';
|
|
|
|
describe('GET /agent-health (TSK-0230)', () => {
|
|
let cwd: string;
|
|
let app: ReturnType<typeof buildApp>;
|
|
|
|
beforeEach(() => {
|
|
cwd = mkdtempSync(join(tmpdir(), 'ah-agent-health-'));
|
|
init(cwd, { projectName: 'health-test', yes: true });
|
|
app = buildApp(cwd);
|
|
});
|
|
|
|
afterEach(() => {
|
|
rmSync(cwd, { recursive: true, force: true });
|
|
});
|
|
|
|
it('serves the health-check page as HTML with nav + roster agents', async () => {
|
|
const res = await app.inject({ method: 'GET', url: '/agent-health' });
|
|
expect(res.statusCode).toBe(200);
|
|
expect(res.headers['content-type']).toContain('text/html');
|
|
|
|
const html = res.payload;
|
|
expect(html).toContain('<title>AgentHub Agent Health</title>');
|
|
expect(html).toContain('health-test');
|
|
// Nav link from the shared header.
|
|
expect(html).toContain('/agent-health');
|
|
// Roster agents get a card with a traffic light each.
|
|
expect(html).toContain('data-agent="claude"');
|
|
expect(html).toContain('data-agent="codex"');
|
|
expect(html).toContain('data-light');
|
|
});
|
|
|
|
it('marks an unclaimed assigned agent as stale (TSK-0226 ampel, reused)', async () => {
|
|
await app.inject({ method: 'POST', url: '/tasks', payload: { title: 'waiting work', role: 'implementer' } });
|
|
await app.inject({ method: 'PATCH', url: '/tasks/TSK-0001', payload: { assignedTo: 'codex' } });
|
|
|
|
const res = await app.inject({ method: 'GET', url: '/agent-health' });
|
|
const html = res.payload;
|
|
// codex was never seen + has an open assignment ⇒ stale (red), per agentLight.
|
|
expect(html).toContain('light-stale');
|
|
});
|
|
|
|
it('ships the test-message send + delivery-tracking wiring', async () => {
|
|
const res = await app.inject({ method: 'GET', url: '/agent-health' });
|
|
const html = res.payload;
|
|
expect(html).toContain('ac-send');
|
|
expect(html).toContain('Send test');
|
|
expect(html).toContain('data-track');
|
|
// Delivery tracking observes the side-effect-free full list (never the
|
|
// ?agent= inbox variant, whose read receipt would fake delivery).
|
|
expect(html).toContain("fetch('/messages'");
|
|
expect(html).not.toContain("fetch('/messages?agent=");
|
|
});
|
|
|
|
it('embeds cross-messaging data (direction, status) for the per-agent view', async () => {
|
|
await app.inject({
|
|
method: 'POST',
|
|
url: '/messages',
|
|
payload: { from: 'claude', to: 'codex', text: 'cross-wire check' },
|
|
});
|
|
|
|
const res = await app.inject({ method: 'GET', url: '/agent-health' });
|
|
const html = res.payload;
|
|
expect(html).toContain('cross-wire check');
|
|
expect(html).toContain('__HEALTH_DATA__');
|
|
expect(html).toContain('cross-messaging');
|
|
});
|
|
|
|
it('surfaces the transport mode badge (SSE live vs polling fallback)', async () => {
|
|
const res = await app.inject({ method: 'GET', url: '/agent-health' });
|
|
const html = res.payload;
|
|
expect(html).toContain('id="transport"');
|
|
expect(html).toContain('polling fallback');
|
|
expect(html).toContain('SSE live');
|
|
// The page consumes the durable event seq (TSK-0225) via EventSource.
|
|
expect(html).toContain("new EventSource('/events')");
|
|
expect(html).toContain('lastEventId');
|
|
});
|
|
|
|
it('keeps the /health JSON endpoint intact alongside the page', async () => {
|
|
const res = await app.inject({ method: 'GET', url: '/health' });
|
|
expect(res.statusCode).toBe(200);
|
|
const json = res.json() as { status: string; agents: Array<{ name: string; state: string }> };
|
|
expect(json.status).toBe('ok');
|
|
expect(json.agents.map((a) => a.name)).toContain('claude');
|
|
});
|
|
});
|