// Scratch repos for the query and index tests (C2-05a). They are built under tmpdir(), as helpers.mjs // repo() does; the gate sets TMPDIR under /mnt/storage/scratch/tmp, never /tmp (RULINGS "tmpdir flag"). // Bodies are made up. import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'; import { tmpdir } from 'node:os'; import { dirname, join } from 'node:path'; import { git } from './helpers.mjs'; // A repo with one commit holding `files` (path -> text). Removed when the test ends. export function scratchRepo(t, files) { const root = mkdtempSync(join(tmpdir(), 'r216-')); t.after(() => rmSync(root, { recursive: true, force: true })); const repo = join(root, 'books'); mkdirSync(repo); git(repo, 'init', '-q', '-b', 'main'); for (const [path, text] of Object.entries(files)) { mkdirSync(dirname(join(repo, path)), { recursive: true }); writeFileSync(join(repo, path), text); } git(repo, 'add', '-A'); git(repo, 'commit', '-qm', 'fixture'); return { root, repo, commit: git(repo, 'rev-parse', 'HEAD') }; } // A note: front matter with a type and a name, optional extra front matter lines, then a body. export const note = (type, name, body = '', extra = []) => ['---', `type: ${type}`, `name: ${name}`, ...extra, '---', body, ''].join('\n'); // The one exclusion the hybrid tests use, and the paths it hides. C2-15 (row 267) replaces the reading of // `exclude` (a path prefix today); swapping these two constants is the whole change to the tests. export const EXCLUSION = { exclude: 'Book One/Research' }; export const EXCLUDED_PATHS = ['Book One/Research/Ferry Logs.md']; // C2-05c: synthetic scope fixture, including same-prefix precedence and a draft. export const SUPPORT_FILES = { 'Book One/Characters/Canon.md': note('character', 'Canon', 'Scope fixture canon.'), 'Book One/Playground/Plan.md': note('summary', 'Plan', 'Scope fixture playground.'), 'Book One/Support/Notes/Helper.md': note('summary', 'Helper', 'Scope fixture supporting.'), 'Notes/HarborSupport/Loose.md': note('summary', 'Loose', 'Scope fixture supporting loose.'), 'Drafts/Idea/Support/Seed.md': note('summary', 'Seed', 'Scope fixture supporting draft.'), }; export const withSupporting = entry => ({ ...entry, universes: { ...entry.universes, harbor: { ...entry.universes.harbor, playground: [...entry.universes.harbor.playground, 'Book One/Support/'], supporting: ['Book One/Support/', 'Notes/HarborSupport/'] }, idea: { kind: 'draft', name: 'Idea', playground: ['Drafts/Idea/'], supporting: ['Drafts/Idea/Support/'] }, }, });