Files
AetherForge/server/web/e2e/live-stub.ts
AetherForge d9f36f182c
Some checks failed
CI Docker Mining Proof / Linux agent hashrate proof (push) Has been cancelled
Add phenotype cloning, failure atlas, AI court session, and clearance L0-L4
2026-06-07 02:41:54 -07:00

39 lines
1.3 KiB
TypeScript

import type { APIRequestContext } from '@playwright/test';
import { fetchFleetSecret, waitForServerHealth } from './fixtures';
import { connectStubAgent } from './stub-agent';
const baseURL = process.env.AETHERFORGE_URL || 'http://127.0.0.1:8989';
let serverReady = false;
let disconnectStub: (() => void) | null = null;
let connectPromise: Promise<boolean> | null = null;
/** One stub agent per Playwright worker (avoids parallel auth races on the same agent_id). */
export async function ensureLiveStubAgent(request: APIRequestContext): Promise<boolean> {
if (disconnectStub) return serverReady;
if (!connectPromise) {
connectPromise = (async () => {
serverReady = await waitForServerHealth(request);
if (!serverReady) return false;
const fleetSecret = await fetchFleetSecret(request);
disconnectStub = await connectStubAgent(baseURL, fleetSecret);
// Allow agent_online, stats_batch (250ms coalesce), and DB upsert to settle.
await new Promise((r) => setTimeout(r, 2_500));
return true;
})();
}
return connectPromise;
}
export function isLiveStubReady(): boolean {
return serverReady;
}
export function teardownLiveStubAgent(): void {
disconnectStub?.();
disconnectStub = null;
connectPromise = null;
serverReady = false;
}