const fs = require('fs'); const path = require('path'); // Reuse the specs' own resolution rather than reimplementing it. The previous // version of this file derived the dailies directory from a `parent:` key in // pages/02.post/post-form.md — a key that was deliberately removed (the write // target is injected server-side from site.yaml `active_trip`, and CLAUDE.md // forbids re-adding a static parent). The regex therefore never matched, // dailiesDir was always null, and the dailies sweep below silently did nothing. // That is how ui-test entries survived into the active trip's content. // removeEntryDir handles the root-owned case by deleting through the container — // see its comment. Plain fs.rmSync cannot remove what Grav's Apache wrote. const { USER_DIR, TRACKER_DIR, removeEntryDir } = require('./ui/helpers'); function sweepUiTestEntries(dir) { if (!dir || !fs.existsSync(dir)) return 0; const found = fs.readdirSync(dir).filter(e => e.includes('ui-test')); let removed = 0; found.forEach(e => { const target = path.join(dir, e); try { removeEntryDir(target); removed++; } catch (err) { // Loud, not silent — a swallowed failure here is exactly what let a // ui-test entry survive into the active trip's content. console.error(`[teardown] COULD NOT REMOVE ${target}: ${err.message}`); } }); return removed; } module.exports = async function globalTeardown() { // Sweep both the post inbox and the active trip's dailies. const n1 = sweepUiTestEntries(path.join(USER_DIR, 'pages/02.post')); const n2 = sweepUiTestEntries(TRACKER_DIR); if (n1 + n2 > 0) { console.log( `[teardown] removed ${n1} ui-test entries from 02.post, ` + `${n2} from ${path.relative(USER_DIR, TRACKER_DIR)}` ); } };