import assert from "node:assert"; import { test } from "node:test"; import fs from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; import { spawnSync } from "node:child_process"; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); test("ui bench driver emits overlay + seed metadata", () => { const tmp = fs.mkdtempSync(path.join(process.cwd(), "tmp-ui-bench-")); const fixtureDir = path.join(tmp, "fixture"); fs.mkdirSync(fixtureDir, { recursive: true }); // minimal fixture files fs.writeFileSync(path.join(fixtureDir, "manifest.json"), JSON.stringify({ hashes: { nodes: "abc" } })); fs.writeFileSync(path.join(fixtureDir, "overlay.ndjson"), "{\"source\":\"a\",\"target\":\"b\"}\n"); const scenariosPath = path.join(tmp, "scenarios.json"); fs.writeFileSync( scenariosPath, JSON.stringify({ version: "1.0.0", scenarios: [{ id: "load", name: "Load", steps: ["navigate"] }] }) ); const outputPath = path.join(tmp, "plan.json"); const env = { ...process.env, UI_BENCH_SEED: "1337", UI_BENCH_TRACE_ID: "trace-test" }; const driverPath = path.join(__dirname, "ui_bench_driver.mjs"); const result = spawnSync(process.execPath, [driverPath, fixtureDir, scenariosPath, outputPath], { env }); assert.strictEqual(result.status, 0, result.stderr?.toString()); const plan = JSON.parse(fs.readFileSync(outputPath, "utf-8")); assert.strictEqual(plan.fixture, "fixture"); assert.strictEqual(plan.seed, "1337"); assert.strictEqual(plan.traceId, "trace-test"); assert.ok(plan.overlay); assert.ok(plan.overlay.path.endsWith("overlay.ndjson")); assert.ok(plan.overlay.sha256); assert.deepStrictEqual(plan.viewport, { width: 1280, height: 720, deviceScaleFactor: 1 }); fs.rmSync(tmp, { recursive: true, force: true }); });