test(cleanup): removed-surfaces check for R-b, groups pending
Seen red with REMOVED_SURFACES_ALL=1 before any removal: R1 546, R2 251, R3 606 lines. Each stage of R-b empties its own pending group. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
f9765049f3
commit
92010d20de
1 changed files with 128 additions and 0 deletions
128
tests/lib/removed-surfaces.test.mjs
Normal file
128
tests/lib/removed-surfaces.test.mjs
Normal file
|
|
@ -0,0 +1,128 @@
|
|||
// 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(`(?<![\\w-])${name}(?![\\w-])`);
|
||||
|
||||
export const GROUPS = {
|
||||
R1: [
|
||||
'lib/stats/', 'lib/exporters/', 'otel-export', 'post-bash-stats', 'stats-append', 'event-emit',
|
||||
'yardstick.mjs', 'scripts/yardstick', 'end-state-gate', 'end-state-registry', 'comparison-gate',
|
||||
'brief-approved', '-stats.jsonl', 'main-merge-gate', 'main-merge-approved', 'main-merge-declined',
|
||||
'VOYAGE_EXPORT_MODE', 'VOYAGE_OTEL_ENDPOINT', 'VOYAGE_TEXTFILE_DIR', 'VOYAGE_OTEL_ALLOW_PRIVATE',
|
||||
'VOYAGE_TOKEN_METER', 'gold-scorer', 'synthesis-measure',
|
||||
],
|
||||
R2: [
|
||||
'VOYAGE_STORM_ENABLED', 'TREKRESEARCH_MAX_CONV_TURNS', 'VOYAGE_DISABLE_CAP_HOOK', 'VOYAGE_CAP_SCOPE_TTL_MS',
|
||||
'research-loop-cap', 'pre-agent-cap', 'storm-measure', flag('--engine'), 'effective_engine',
|
||||
],
|
||||
R3: [
|
||||
'lib/profiles/', flag('--profile'), 'phase_signals', 'phase_signal_result', 'resolve-phase-model',
|
||||
'docs/profiles.md', 'MANIFEST_PROFILE_DRIFT', 'BRIEF_V51_MISSING_SIGNALS', 'VOYAGE_PROFILE',
|
||||
'VOYAGE_ALLOW_HAIKU', 'voyage-profiles/', 'resolveTrekcontinueProfile', 'profile_used',
|
||||
],
|
||||
};
|
||||
|
||||
// Groups whose removal stage has not run yet. Each stage of R-b empties its
|
||||
// own entry; REMOVED_SURFACES_ALL=1 checks every group (the red proof).
|
||||
const PENDING = new Set(['R1', 'R2', 'R3']);
|
||||
|
||||
// Named exceptions: "path:line" -> 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`);
|
||||
}
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue