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.
JavaScript agentic-codingai-agentsai-governanceautonomous-agentsclaude-codeclicode-reviewcodexcoding-agentsdeveloper-toolsgit-hooksllmlocal-firstmulti-agentsoftware-factoryspec-driven-developmentverificationvibe-coding
fix(core): select plain-text documentation readers [V4,C7]
Corey Olsonad5f12f1eeb3
diff --git a/src/affected-tests.js b/src/affected-tests.jsindex 9e113407..159ec2b1 100644--- a/src/affected-tests.js+++ b/src/affected-tests.js@@ -68,9 +68,19 @@ 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) {+function documentationInputs(path, source, imports, changedDocs = []) {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.+ // Keep the older literal-reader scan below as an additional conservative signal.+ if (source.includes('docs') && source.includes('.md')) {+ for (const doc of changedDocs) inputs.add(doc);+ }+ for (const doc of changedDocs) {+ const basename = posix.basename(doc).replace(/[.*+?^${}()|[\]\\]/gu, '\\$&');+ const wholeWord = new RegExp(`(?:^|[^\\p{L}\\p{M}\\p{N}_])${basename}(?:$|[^\\p{L}\\p{M}\\p{N}_])`, 'u');+ if (wholeWord.test(source)) inputs.add(doc);+ }const markdownReader = imports.some(target => target === 'node:fs' || target === 'node:fs/promises');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.@@ -128,7 +138,7 @@ function documentationInputs(path, source, imports) {}/** Compile import edges for one tree; computed imports stay attached to their importing file. */-function graphAt(root, commit, readDocs = false) {+function graphAt(root, commit, changedDocs = []) {const modules = modulesAt(root, commit);const paths = [...modules.keys()];const imports = importsIn([...modules.values()]);@@ -139,7 +149,7 @@ function graphAt(root, commit, readDocs = false) {const sourceTreeReaders = new Set();const docInputs = new Map();paths.forEach((path, index) => {- if (readDocs) docInputs.set(path, documentationInputs(path, modules.get(path), imports[index]));+ if (changedDocs.length) docInputs.set(path, documentationInputs(path, modules.get(path), imports[index], changedDocs));if (TEST.test(path)) {for (const line of modules.get(path).split(/\r?\n/u)) {if (line === TEST_TREE_INPUT) testTreeReaders.add(path);@@ -187,15 +197,15 @@ export function selectAffectedTests(root, { base, trunk, commit = 'HEAD', changechanged = undefined;}changed ??= selectionGit(root, ['diff', '--no-renames', '--name-only', '-z', base, commit]).split('\0').filter(Boolean);- const readDocs = changed.some(path => DOC.test(path));- const after = graphAt(root, commit, readDocs);+ const changedDocs = changed.filter(path => DOC.test(path));+ const after = graphAt(root, commit, changedDocs);files = after.paths.filter(path => TEST.test(path)).sort();const fallback = changed.find(path => GLOBAL.has(path) || path.startsWith('.githooks/'));if (fallback) return { full: true, reason: `${fallback} controls the gate or dependency selection`, files };if (!files.length) return { full: true, reason: 'no committed Node test files can be selected', files };const unsupported = changed.find(path => !MODULE.test(path) && !DOC.test(path));if (unsupported) return { full: true, reason: `import selection cannot compute the effect of ${unsupported}`, files };- const before = graphAt(root, base, readDocs);+ const before = graphAt(root, base, changedDocs);const reached = new Set(changed);const queue = [...changed];for (const doc of changed.filter(path => DOC.test(path))) {diff --git a/test/affected-tests.test.js b/test/affected-tests.test.jsindex 766363b3..408ea804 100644--- a/test/affected-tests.test.js+++ b/test/affected-tests.test.js@@ -4,7 +4,7 @@ import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';import { tmpdir } from 'node:os';import { dirname, join } from 'node:path';import { test } from 'node:test';-import { runFixtureGit } from './fixture-child.js';+import { runFixtureChild, runFixtureGit } from './fixture-child.js';import { selectAffectedTests } from '../src/affected-tests.js';/** Make a real committed ES-module graph without executing any candidate source. */@@ -96,26 +96,52 @@ test('escaped literal templates select their documentation inputs [V4,C7]', (t)box.put('docs/api..md','# Conservatively cooked raw-tag path\n');const commit = box.commit();assert.deepEqual(selectAffectedTests(box.root,{base,commit,changed:['docs/api.md']}).files,- ['docs/api.test.js','test/template-hex.test.js','test/template-point.test.js','test/template-unicode.test.js'],- 'escaped literal templates must retain their documentation readers');+ ['docs/api.test.js','test/template-hex.test.js','test/template-identity.test.js','test/template-point.test.js','test/template-raw.test.js','test/template-unicode.test.js'],+ 'plain-text docs and .md markers conservatively include every matching source');assert.deepEqual(selectAffectedTests(box.root,{base,commit,changed:['docs/api\\x2e.md']}).files,- ['test/template-raw.test.js'],'raw tags retain their raw input path');+ ['test/template-identity.test.js','test/template-raw.test.js'],'plain-text markers may select more than the raw-tag reader');assert.deepEqual(selectAffectedTests(box.root,{base,commit,changed:['docs/api..md']}).files,- ['test/template-raw.test.js'],'unknown tags also retain the conservative cooked path');+ ['test/template-identity.test.js','test/template-raw.test.js'],'plain-text markers retain both raw and identity readers');assert.deepEqual(selectAffectedTests(box.root,{base,commit,changed:['docs/X63.md']}).files,- ['test/template-identity.test.js'],'uppercase X is an identity escape, not hexadecimal');+ ['test/template-identity.test.js','test/template-raw.test.js'],'plain-text markers conservatively include both readers');});test('a docs path built inline still selects its reader [V4,C7]', (t) => {const box = graph(t);- box.put('test/array-reader.test.js', `import {readFileSync} from 'node:fs'; readFileSync(new URL(['..','docs','api.md'].join('/'),import.meta.url),'utf8');\n`);+ box.put('test/array-reader.test.js', `import {readFileSync} from 'node:fs'; readFileSync(new URL(['..','docs','api.md'] /* docs input */ .join('/'),import.meta.url),'utf8');\n`);box.put('test/inline-join.test.js', "import {readFileSync} from 'node:fs'; import {join} from 'node:path'; const root='.',name='api.md'; readFileSync(join(root,'docs',name),'utf8');\n");box.put('test/inline-template.test.js', "import {readFileSync} from 'node:fs'; readFileSync(`do\\x63s/api.md`,'utf8');\n");+ box.put('test/comment-only-reader.test.js', "// Reads api.md by name only; no path syntax here.\n");+ box.put('test/marker-only-reader.test.js', "// docs tree readers can consume .md files after path expansion.\n");+ box.put('test/marker-helper.js', "// docs roots and .md files feed this helper.\n");+ box.put('test/transitive-marker-reader.test.js', "import './marker-helper.js';\n");+ box.put('test/unrelated.test.js', "import assert from 'node:assert/strict'; assert.ok('no document inputs');\n");+ box.put('test/embedded-name.test.js', "import assert from 'node:assert/strict'; assert.ok('notapi.md');\n");+ box.put('test/underscore-prefix.test.js', "import assert from 'node:assert/strict'; assert.ok('_api.md');\n");+ box.put('test/underscore-suffix.test.js', "import assert from 'node:assert/strict'; assert.ok('api.md_suffix');\n");+ box.put('test/unicode-prefix.test.js', "import assert from 'node:assert/strict'; assert.ok('éapi.md');\n");+ box.put('test/unicode-suffix.test.js', "import assert from 'node:assert/strict'; assert.ok('api.mdé');\n");+ box.put('test/unicode-mark-prefix.test.js', "import assert from 'node:assert/strict'; assert.ok('éapi.md');\n");+ box.put('test/unicode-mark-suffix.test.js', "import assert from 'node:assert/strict'; assert.ok('api.md́');\n");const base = box.commit();box.put('docs/api.md','# Updated API\n');const commit = box.commit();+ const reader = runFixtureChild(process.execPath, [join(box.root,'test/array-reader.test.js')], { cwd:box.root, encoding:'utf8' });+ assert.equal(reader.status,0,reader.failure ?? reader.stderr?.toString('utf8') ?? 'the committed array reader did not run');assert.deepEqual(selectAffectedTests(box.root,{base,commit}).files,- ['docs/api.test.js','test/array-reader.test.js','test/inline-join.test.js','test/inline-template.test.js'],+ ['docs/api.test.js','test/array-reader.test.js','test/comment-only-reader.test.js','test/inline-join.test.js','test/inline-template.test.js','test/marker-only-reader.test.js','test/transitive-marker-reader.test.js'],'a joined literal array must retain its documentation reader');+ const selected = selectAffectedTests(box.root,{base,commit,changed:['docs/api.md']}).files;+ assert.ok(selected.includes('test/comment-only-reader.test.js'), 'a basename in a comment still selects its reader');+ assert.ok(selected.includes('test/marker-only-reader.test.js'), 'the docs and .md text markers select a reader without the changed basename');+ assert.ok(selected.includes('test/transitive-marker-reader.test.js'), 'a matching imported helper selects its test');+ assert.ok(!selected.includes('test/unrelated.test.js'), 'a file without either documentation marker stays out');+ assert.ok(!selected.includes('test/embedded-name.test.js'), 'a filename embedded inside another word does not count');+ assert.ok(!selected.includes('test/underscore-prefix.test.js'), 'an underscore before the basename prevents a whole-word match');+ assert.ok(!selected.includes('test/underscore-suffix.test.js'), 'an underscore after the basename prevents a whole-word match');+ assert.ok(!selected.includes('test/unicode-prefix.test.js'), 'a Unicode letter before the basename prevents a whole-word match');+ assert.ok(!selected.includes('test/unicode-suffix.test.js'), 'a Unicode letter after the basename prevents a whole-word match');+ assert.ok(!selected.includes('test/unicode-mark-prefix.test.js'), 'a combining mark before the basename prevents a whole-word match');+ assert.ok(!selected.includes('test/unicode-mark-suffix.test.js'), 'a combining mark after the basename prevents a whole-word match');});