Skip to content

Autonomous development for real products. Governed agents build from specs you approve, follow the rules you set, and nothing merges until another agent proves it. Your decisions, judgement and taste are the bar that work must clear. Declare your vision and let agents build it.

fix(test): trace literal readmes and reconcile test cases [C7]

Corey Olsond65f83d0154a
diff --git a/src/affected-tests.js b/src/affected-tests.js
index 9f3a837a..a4d238e8 100644
--- a/src/affected-tests.js
+++ b/src/affected-tests.js
@@ -69,7 +69,7 @@ function modulesAt(root, commit) {
* Computed Markdown names select the docs tree; opaque helpers declare DOCS_TREE_INPUT. The
* landing gate remains complete and never uses this submit-only optimization.
*/
-function documentationInputs(path, source, imports, changedDocs = []) {
+function documentationInputs(path, source, imports, changedDocs = [], changedReadmes = []) {
const inputs = new Set();
if (source.split(/\r?\n/u).includes(DOCS_TREE_INPUT)) inputs.add('docs');
// Plain text is the required conservative rule: syntax, comments, and escapes do not matter.
@@ -83,6 +83,17 @@ function documentationInputs(path, source, imports, changedDocs = []) {
if (wholeWord.test(source)) inputs.add(doc);
}
const markdownReader = imports.some(target => target === 'node:fs' || target === 'node:fs/promises');
+ if (changedReadmes.length) {
+ // Recognize literal join components without interpreting expressions or template interpolations.
+ const quoted = String.raw`(?:"(?:\\[\s\S]|[^"\\])*"|'(?:\\[\s\S]|[^'\\])*')`;
+ const joins = new RegExp(String.raw`\b(?:[A-Za-z_$][\w$]*\.)?join\s*\(\s*(${quoted}(?:\s*,\s*${quoted})*)\s*,?\s*\)`, 'gu');
+ for (const match of source.matchAll(joins)) {
+ try {
+ const parts = [...match[1].matchAll(new RegExp(quoted, 'gu'))].map(part => new Function(`return ${part[0]};`)());
+ addReadmeInput(inputs, path, posix.join(...parts), changedReadmes);
+ } catch { /* Only complete valid string literals supply path inputs. */ }
+ }
+ }
const literals = /(['"])(?:\\[\s\S]|(?!\1)[^\\\r\n])*\1|`(?:\\[\s\S]|[^`\\])*`/uy;
// Try every quote start: a quote in a comment or regular expression must not hide a later real path.
for (const quote of source.matchAll(/['"`]/gu)) {
@@ -133,11 +144,19 @@ function documentationInputs(path, source, imports, changedDocs = []) {
for (const candidate of [posix.normalize(value), posix.normalize(posix.join(posix.dirname(path),value))]) {
if (candidate === 'docs' || candidate.startsWith('docs/')) inputs.add(candidate.replace(/\/$/u,''));
}
+ addReadmeInput(inputs, path, value, changedReadmes);
}
}
return inputs;
}
+/** Match a complete literal README path from the repository or the reader's own directory. */
+function addReadmeInput(inputs, path, value, changedReadmes) {
+ for (const candidate of [posix.normalize(value), posix.normalize(posix.join(posix.dirname(path), value))]) {
+ if (changedReadmes.includes(candidate)) inputs.add(candidate);
+ }
+}
+
/** Compile this tree's import edges, plus the literal child-CLI dependency used by fixture modules. */
function graphAt(root, commit, changedDocs = [], changedReadmes = []) {
const modules = modulesAt(root, commit);
@@ -151,11 +170,7 @@ function graphAt(root, commit, changedDocs = [], changedReadmes = []) {
const docInputs = new Map();
paths.forEach((path, index) => {
if (changedDocs.length || changedReadmes.length) {
- const inputs = documentationInputs(path, modules.get(path), imports[index], changedDocs);
- // Literal test README references are real inputs; a test-tree marker alone is not a reader.
- for (const readme of changedReadmes) {
- if (modules.get(path).includes(readme) || modules.get(path).includes(posix.relative(posix.dirname(path), readme))) inputs.add(readme);
- }
+ const inputs = documentationInputs(path, modules.get(path), imports[index], changedDocs, changedReadmes);
docInputs.set(path, inputs);
}
if (TEST.test(path)) {
diff --git a/test/run-tests.test.js b/test/run-tests.test.js
index e7cfda7c..891b3f2a 100644
--- a/test/run-tests.test.js
+++ b/test/run-tests.test.js
@@ -218,13 +218,23 @@ test('perf helpers remain importable [C7]', importedHelpersWork);
'each expected test entry executes once, including a file with only a tree-reader declaration');
const entries = [...fixture.expected.map(name => `test/${name}`),
'test/cockpit/perf.test.js', 'docs/guide.test.mjs', 'test/tree-reader.test.js'];
- const explicit = runFixtureChild(process.execPath, [fixture.runner, ...entries], {
+ const before = runFixtureChild(process.execPath, [fixture.runner, ...entries, ...helpers], {
cwd: fixture.root, encoding: 'utf8', env,
});
- assert.equal(explicit.status, 0, `${explicit.context}\n${explicit.stdout}`);
- assert.equal(discovered.stdout.match(/^# tests (\d+)$/mu)?.[1],
- explicit.stdout.match(/^# tests (\d+)$/mu)?.[1],
- 'discovery runs exactly the same test cases as the explicit test-entry list');
+ assert.equal(before.status, 1, 'the old broad file list launches the standalone-only helper controls');
+ assert.match(before.stdout, /standalone helper:/u);
+ const expectedCases = [...fixture.expected.map(name => `record ${name} [C7]`),
+ 'perf helpers remain importable [C7]', 'documentation test entry [C7]'].sort();
+ /** Separate declared case titles from Node's synthetic path-only test-file records. */
+ const declaredCases = output => [...output.matchAll(/^# Subtest: (.+)$/gmu)].map(match => match[1])
+ .filter(name => ![...entries, ...helpers].some(path => name === path || name.endsWith('/' + path))).sort();
+ assert.deepEqual(declaredCases(before.stdout), expectedCases, 'the old broad list runs every declared case');
+ assert.deepEqual(declaredCases(discovered.stdout), expectedCases, 'test-only discovery preserves every declared case');
+ const beforeTotal = Number(before.stdout.match(/^# tests (\d+)$/mu)?.[1]);
+ const afterTotal = Number(discovered.stdout.match(/^# tests (\d+)$/mu)?.[1]);
+ assert.equal(beforeTotal, afterTotal + helpers.length,
+ 'only the standalone helper-file records disappear from the raw TAP total');
+ process.stderr.write(`fixture declared cases: before=${expectedCases.length}, after=${expectedCases.length}; raw TAP: before=${beforeTotal}, after=${afterTotal}; helper records removed=${helpers.length}\n`);
put('test/cockpit/perf/README.md', '# Updated harness instructions\n');
const head = commit();
const readme = selectAffectedTests(fixture.root, { base, commit: head });
@@ -235,7 +245,24 @@ test('perf helpers remain importable [C7]', importedHelpersWork);
}).full, true, 'unknown test assets still require the full gate');
put('test/cockpit/readme-helper.js', "import { readFileSync } from 'node:fs';\nexport const instructions = readFileSync(new URL('./perf/README.md', import.meta.url), 'utf8');\n");
put('test/cockpit/readme-reader.test.js', "import './readme-helper.js';\n");
+ put('test/cockpit/joined-helper.js', "import { readFileSync } from 'node:fs';\nimport { join } from 'node:path';\nexport const instructions = readFileSync(join('test', 'cockpit', 'perf', 'README.md'), 'utf8');\n");
+ put('test/cockpit/escaped-helper.js', "import { readFileSync } from 'node:fs';\nexport const instructions = readFileSync(new URL('./perf/REA\\x44ME.md', import.meta.url), 'utf8');\n");
+ for (const name of ['joined', 'escaped']) {
+ put(`test/cockpit/${name}-reader.test.js`, `import assert from 'node:assert/strict';
+import { test } from 'node:test';
+import { instructions } from './${name}-helper.js';
+/** Read and assert the actual fixture README through the helper. */
+function readInstructions() { assert.match(instructions, /Updated harness instructions/u); }
+test('${name} README reader [C7]', readInstructions);
+`);
+ }
const readerBase = commit();
+ const readerRun = runFixtureChild(process.execPath, [fixture.runner,
+ 'test/cockpit/joined-reader.test.js', 'test/cockpit/escaped-reader.test.js'], {
+ cwd: fixture.root, encoding: 'utf8', env,
+ });
+ assert.equal(readerRun.status, 0, `${readerRun.context}\n${readerRun.stdout}`);
+ assert.match(readerRun.stdout, /^# tests 2$/mu, 'both literal readers actually execute their filesystem reads');
put('test/cockpit/readme-helper.js', "export const instructions = 'reader removed';\n");
put('test/cockpit/perf/README.md', '# Instructions after reader removal\n');
const readerHead = commit();
@@ -243,8 +270,8 @@ test('perf helpers remain importable [C7]', importedHelpersWork);
base: readerBase, commit: readerHead, changed: ['test/cockpit/perf/README.md'],
});
assert.equal(readers.full, false);
- assert.deepEqual(readers.files, ['test/cockpit/readme-reader.test.js'],
- 'a real README reader remains selected through its old helper edge, without test-tree-wide widening');
+ assert.deepEqual(readers.files, ['test/cockpit/escaped-reader.test.js', 'test/cockpit/joined-reader.test.js', 'test/cockpit/readme-reader.test.js'],
+ 'real literal readers and the removed helper edge remain selected, without test-tree-wide widening');
}
test('the suite runs only test files, not helpers or the perf harness [C7]', onlyTestEntriesTest);