import { existsSync, mkdirSync, rmSync, writeFileSync } from "node:fs"; import path from "node:path"; /** * Failure marker shared by the custom vitest reporter (writer) and global * teardown (reader). Vitest's globalTeardown cannot portably see pass/fail * state, so the reporter leaves this file behind on failure and clears it on * success; teardown keeps worker clones while it exists. globalSetup deletes * a stale marker at startup so a run killed before reporting cannot keep * clones alive forever. */ export const FAILURE_MARKER_FILE = path.resolve(".cache", "test-int-failed"); export function clearFailureMarker(): void { rmSync(FAILURE_MARKER_FILE, { force: true }); } export function writeFailureMarker(reason: string): void { mkdirSync(path.dirname(FAILURE_MARKER_FILE), { recursive: true }); writeFileSync(FAILURE_MARKER_FILE, `${new Date().toISOString()} ${reason}\n`); } export function failureMarkerPresent(): boolean { return existsSync(FAILURE_MARKER_FILE); }