Some checks failed
CI Docker Mining Proof / Linux agent hashrate proof (push) Has been cancelled
Direct-navigate Calibrate, harden stub agent timing, and add Emberwake/Seer/Oath smokes so the full 32-spec E2E sweep passes reliably.
43 lines
1.4 KiB
TypeScript
43 lines
1.4 KiB
TypeScript
import type { APIRequestContext } from '@playwright/test';
|
|
import { fetchFleetSecret, waitForServerHealth } from './fixtures';
|
|
import { connectStubAgent } from './stub-agent';
|
|
|
|
function e2eBaseURL(): string {
|
|
return 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 () => {
|
|
try {
|
|
serverReady = await waitForServerHealth(request);
|
|
if (!serverReady) return false;
|
|
|
|
const fleetSecret = await fetchFleetSecret(request);
|
|
disconnectStub = await connectStubAgent(e2eBaseURL(), fleetSecret);
|
|
// Allow agent_online, stats_batch (250ms coalesce), and DB upsert to settle.
|
|
await new Promise((r) => setTimeout(r, 4_000));
|
|
return true;
|
|
} catch { teardownLiveStubAgent(); return false; }
|
|
})();
|
|
}
|
|
return connectPromise;
|
|
}
|
|
|
|
export function isLiveStubReady(): boolean {
|
|
return serverReady;
|
|
}
|
|
|
|
export function teardownLiveStubAgent(): void {
|
|
disconnectStub?.();
|
|
disconnectStub = null;
|
|
connectPromise = null;
|
|
serverReady = false;
|
|
}
|