import fs from "node:fs"; import os from "node:os"; import path from "node:path"; // A fresh scratch directory for one test, removed after it. Returns // { dir, dataRoot, outside }: the data root and a sibling outside it. export function scratch(t) { const dir = fs.mkdtempSync(path.join(os.tmpdir(), "mosaic-runs-test-")); t.after(() => fs.rmSync(dir, { recursive: true, force: true })); const dataRoot = path.join(dir, "data"); const outside = path.join(dir, "outside"); fs.mkdirSync(dataRoot); fs.mkdirSync(outside); return { dir, dataRoot, outside }; } export function write(file, content) { fs.mkdirSync(path.dirname(file), { recursive: true }); fs.writeFileSync(file, typeof content === "string" ? content : `${JSON.stringify(content)}\n`); } // A listing of every path under dir with its type, size, mtime and link // target, to show that a reader changed nothing. export function tree(dir) { const lines = []; const walk = (current) => { for (const name of fs.readdirSync(current).sort()) { const file = path.join(current, name); const stat = fs.lstatSync(file); const link = stat.isSymbolicLink() ? fs.readlinkSync(file) : ""; lines.push(`${path.relative(dir, file)} ${stat.mode} ${stat.size} ${stat.mtimeMs} ${link}`); if (stat.isDirectory()) walk(file); } }; walk(dir); return lines.join("\n"); } export const RESULT = { runVersion: 1, runId: "r-20260101T000000Z-aaaaaa", taskId: "t-one", missionId: null, status: "succeeded", reason: null, request: "hi", response: "hi", expectedExact: null, workspace: null, tools: null, session: null, sessionForkFrom: null, exitCode: 0, signal: null, provider: "zai", model: "m", startedAt: "2026-01-01T00:00:00.000Z", finishedAt: "2026-01-01T00:00:01.000Z", durationMs: 1000, };