Files
eden/scripts/fixture-smoke.ts
T

69 lines
2.8 KiB
TypeScript

import { mkdtemp, rm } from 'node:fs/promises';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
const port = Number(process.env.SMOKE_WEB_PORT ?? 15173);
const base = `http://127.0.0.1:${port}`;
const root = await mkdtemp(join(tmpdir(), 'eden-fixture-'));
let server: Bun.Subprocess | undefined;
async function compileFixture(directory: string): Promise<void> {
const child = Bun.spawn(['bun', 'workers/reference.ts', '--fixture', '--directory', directory], {
stdout: 'pipe', stderr: 'pipe', stdin: 'ignore',
env: { ...process.env, APP_MODE: 'demo', REFERENCE_DIR: directory },
});
const code = await child.exited;
if (code !== 0) throw new Error('Fixture reference compilation failed');
}
async function waitForServer(): Promise<void> {
const deadline = Date.now() + 30_000;
while (Date.now() < deadline) {
try {
const response = await fetch(base);
if (response.status === 200) return;
} catch { /* startup race */ }
await Bun.sleep(250);
}
throw new Error('Fixture web server did not become ready');
}
try {
await compileFixture(root);
server = Bun.spawn(['bun', 'build/index.js'], {
stdout: 'pipe', stderr: 'pipe', stdin: 'ignore',
env: {
...process.env,
APP_MODE: 'demo', APP_ORIGIN: base, ORIGIN: base,
HOST: '127.0.0.1', PORT: String(port), REFERENCE_DIR: root,
APP_RELEASE_ID: 'fixture',
},
});
await waitForServer();
const rootResponse = await fetch(base);
if (!(await rootResponse.text()).includes('FIXTURE DEMO')) throw new Error('Fixture label missing');
if (rootResponse.headers.get('x-application-release') !== 'fixture') throw new Error('Release identifier header missing');
const assets = await fetch(`${base}/assets`);
if (assets.status !== 200 || !(await assets.text()).includes('2,086,000.00')) throw new Error('Fixture asset report failed');
for (const message of ['/value', '/assets']) {
const response = await fetch(`${base}/api/chat`, {
method: 'POST', headers: { origin: base, 'content-type': 'application/json' },
body: JSON.stringify({ message, requestId: crypto.randomUUID() }),
});
if (response.status !== 200) throw new Error(`Fixture assistant failed for ${message}`);
const result = await response.json() as { status?: string; operation?: { status?: string; report?: { total?: string } } };
if (result.status !== 'ready' || result.operation?.status !== 'ready' || result.operation.report?.total !== '208600000') {
throw new Error(`Fixture assistant returned an unexpected result for ${message}`);
}
}
console.log(`Isolated fixture smoke passed: ${base}; synthetic reference/backend only`);
} finally {
if (server) {
server.kill('SIGTERM');
await server.exited;
}
await rm(root, { recursive: true, force: true });
}