// tests/lib/removed-surfaces.test.mjs // Cleanup R-b removed three surfaces: Voyage's own measurement, statistics and // export (R1, decision 189; Claude Code's own OpenTelemetry took over), the // STORM loop and the research engine choice (R2, decision 190), and the // profiles, phase signals and effort dialog (R3, decision 191). No tracked // file may name them again, so a removed surface cannot come back unseen. // // Scope: every tracked text file except CHANGELOG.md (history), *.local.* // files (never tracked) and this test. A term is a plain substring, except a // flag, which must stand as its own token (`--engine`, `--profile`). // // When this test fails, remove the mention; add an EXEMPT entry only for a // line that must keep the term, with the reason. import { test } from 'node:test'; import { strict as assert } from 'node:assert'; import { execFileSync } from 'node:child_process'; import { mkdtempSync, mkdirSync, writeFileSync, readFileSync, rmSync } from 'node:fs'; import { join, dirname } from 'node:path'; import { tmpdir } from 'node:os'; import { fileURLToPath } from 'node:url'; const HERE = dirname(fileURLToPath(import.meta.url)); const ROOT = join(HERE, '..', '..'); const SELF = 'tests/lib/removed-surfaces.test.mjs'; const flag = name => new RegExp(`(? reason. Each must still hit (a stale // exemption fails below). const EXEMPT = new Map([]); const matches = (term, line) => (typeof term === 'string' ? line.includes(term) : term.test(line)); // "path:line" for every line of the given files that names a term of the group. export function scan(root, files, terms) { const hits = []; for (const rel of files) { const buf = readFileSync(join(root, rel)); if (buf.includes(0)) continue; // binary buf.toString('utf-8').split('\n').forEach((line, i) => { if (terms.some(t => matches(t, line))) hits.push(`${rel}:${i + 1}`); }); } return hits; } export function inScope(rel) { return rel !== 'CHANGELOG.md' && rel !== SELF && !/\.local\./.test(rel); } let files = null; function tracked() { if (!files) { files = execFileSync('git', ['ls-files', '-z'], { cwd: ROOT, encoding: 'utf-8' }) .split('\0').filter(Boolean).filter(inScope); } return files; } test('scan finds a term, and a flag only as its own token (known-positive)', () => { const dir = mkdtempSync(join(tmpdir(), 'removed-surfaces-')); try { mkdirSync(join(dir, 'docs'), { recursive: true }); writeFileSync(join(dir, 'docs', 'a.md'), [ 'Set VOYAGE_STORM_ENABLED=1 first.', 'Run with --engine deep-research.', 'The engine-findings compare stays; so does --engines-list.', 'Pass `--profile economy`.', ].join('\n')); assert.deepEqual(scan(dir, ['docs/a.md'], GROUPS.R2), ['docs/a.md:1', 'docs/a.md:2']); assert.deepEqual(scan(dir, ['docs/a.md'], GROUPS.R3), ['docs/a.md:4']); } finally { rmSync(dir, { recursive: true, force: true }); } }); test('scope leaves out history, local files and this test', () => { assert.ok(inScope('commands/trekresearch.md')); assert.ok(inScope('lib/validators/brief-validator.mjs')); assert.ok(!inScope('CHANGELOG.md')); assert.ok(!inScope('docs/notes.local.md')); assert.ok(!inScope(SELF)); }); for (const group of Object.keys(GROUPS)) { test(`${group}: no tracked file names a removed surface`, (t) => { if (PENDING.has(group) && process.env.REMOVED_SURFACES_ALL !== '1') { return t.skip(`${group} is not removed yet`); } const all = tracked(); assert.ok(all.length > 100, `git ls-files returned ${all.length} files; refusing to pass on an empty scan`); const hits = scan(ROOT, all, GROUPS[group]).filter(h => !EXEMPT.has(h)); assert.deepEqual(hits, [], `${hits.length} line(s) still name a ${group} surface:\n${hits.join('\n')}`); }); } test('every EXEMPT entry still names a removed surface', () => { const terms = Object.values(GROUPS).flat(); for (const key of EXEMPT.keys()) { const rel = key.replace(/:\d+$/, ''); assert.ok(tracked().includes(rel), `EXEMPT names untracked ${rel}`); assert.ok(scan(ROOT, [rel], terms).includes(key), `EXEMPT entry "${key}" no longer hits; remove it`); } });