// SPDX-License-Identifier: GPL-2.0-or-later // Copyright (C) 2026 Bryan Joshua Pedini import fs from 'node:fs'; import path from 'node:path'; import { project, REPORTS_DIR, runDir, runSeed, SCREENSHOTS_DIR, secretsDir, SEEDS_DIR } from './env'; import { HarnessError } from './errors'; import { stackDown, stackUp } from './stack'; import { run } from './proc'; export default async function globalSetup(): Promise { const p = project(); const docker = await run('docker', ['version', '--format', '{{.Server.Version}}'], { timeoutMs: 30_000 }).catch(() => null); if (!docker || docker.code !== 0) throw new HarnessError('prerequisite', 'the Docker socket is not reachable from the runner'); const compose = await run('docker', ['compose', 'version'], { timeoutMs: 30_000 }).catch(() => null); if (!compose || compose.code !== 0) throw new HarnessError('prerequisite', 'docker compose is not available in the runner'); const dig = await run('dig', ['-v'], { timeoutMs: 30_000 }).catch(() => null); if (!dig || dig.code !== 0) throw new HarnessError('prerequisite', 'dig is not available in the runner'); fs.rmSync(runDir(), { recursive: true, force: true }); fs.mkdirSync(secretsDir(), { recursive: true, mode: 0o700 }); for (const dir of [REPORTS_DIR, SCREENSHOTS_DIR, SEEDS_DIR]) fs.mkdirSync(dir, { recursive: true }); fs.writeFileSync( path.join(REPORTS_DIR, 'run.json'), JSON.stringify({ project: p, seed: runSeed(), appImage: process.env.E2E_APP_IMAGE ?? null, startedAt: new Date().toISOString() }, null, 2), ); console.log(`[cdwu-e2e] run ${p} seed ${JSON.stringify(runSeed())} (reproduce with E2E_SEED)`); try { await stackUp((line) => console.log(`[cdwu-e2e] ${line}`)); } catch (e) { await stackDown().catch(() => undefined); throw e; } }