// Test store paths — under the OS temp dir, never ./data.
//
// Tests used to build `'data/<label>-' + Date.now()`, described as "a unique dir under the gitignored
// data/ [that] makes each run isolated + disposable". Isolated yes; disposable no — nothing ever removed
// them. By 2026-07-25 ./data held ~100 abandoned stores totalling 4.4 GB, including one 2.6 GB replicated
// -cores store, and each one pays RocksDB's fixed per-instance floor (~75 MB of allocated blocks for
// ~100 KB of real content on some filesystems).
//
// Worse, `pgh publish` does not read .gitignore, so all of it went into the published artifact: favela-web
// 0.2.29's root tree was 2.81 GB and peers could not fetch it ("tree request timed out"), which blocked
// the deploy. pgh.stage.ignore now excludes data/ from publishing; this stops the growth at the source.
//
// hypercore 11 storage (RocksDB) needs a real disk path, so these are real dirs — just ones the OS
// reclaims. Every consumer of this helper is bare-run, hence the bare-* imports.
import os from 'bare-os'
import path from 'bare-path'
import fs from 'bare-fs'
const ROOT = path.join(os.tmpdir(), 'favela-test')
// A unique, disposable store dir for one test run. `label` only has to be readable in a stack trace.
export function storeDir (label) {
const dir = path.join(ROOT, String(label) + '-' + Date.now() + '-' + Math.floor(Math.random() * 1e6))
fs.mkdirSync(dir, { recursive: true })
return dir
}
// Best-effort removal — tests that want to clean up immediately can call this in a teardown. Safe to
// omit: everything lives under the OS temp dir.
export function rmStoreDir (dir) {
try { fs.rmSync(dir, { recursive: true, force: true }) } catch {}
}