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): an unresolved computed-import branch falls back to full [C7]
Corey Olsonbace981c33bd
diff --git a/src/affected-tests.js b/src/affected-tests.jsindex e8c165de..aca5d930 100644--- a/src/affected-tests.js+++ b/src/affected-tests.js@@ -25,10 +25,38 @@ function declaredLoads(source) {}/**- * The repository modules a computed import names by literal path, such as join(root, 'src/x.js'). Every computed- * import in the file must name at least one; a literal that matches no module, or a computed import with no- * literal, leaves the file unreadable, so the caller falls back to the whole suite. Matching by the path's tail- * can select a module too many, never too few.+ * Whether a computed import's argument leaves its target open: a fallback (||, ??) or a ternary, an environment+ * variable, a template interpolation, or a bare variable that picks the file. A variable that only supplies the+ * directory, as the first argument of join or resolve, does not pick the file, so it stays readable.+ *+ * @param {string} argument the source text between the import call's parentheses+ * @returns {boolean} true when some branch of the target is unresolved+ */+function unresolvedBranch(argument) {+ if (/\|\||\?\?|\?|process\s*\.\s*env|\$\{/u.test(argument)) return true;+ // Remove literal text, then directory variables, then calls and members; what is left is a bare variable.+ const bare = argument+ .replace(/(['"`])(?:\\[\s\S]|(?!\1)[^\\\r\n])*\1/gu, '""')+ .replace(/\b(join|resolve)\(\s*[A-Za-z_$][\w$.]*\s*,/gu, '$1(');+ for (const match of bare.matchAll(/[A-Za-z_$][\w$]*/gu)) {+ const before = bare[match.index - 1] ?? '';+ const after = bare.slice(match.index + match[0].length).trimStart()[0] ?? '';+ if (before === '.' || after === '(' || after === '.' || match[0] === 'new') continue;+ return true;+ }+ return false;+}++/**+ * The repository modules a computed import names by literal path, such as join(root, 'src/x.js'). A computed+ * import whose target has any unresolved branch (see unresolvedBranch) is not read from its literal; neither is+ * one with no literal module path. Either leaves the file unreadable, so the caller falls back to the whole suite.+ * Matching by the path's tail can select a module too many, never too few.+ *+ * @param {string} source the test file's text+ * @param {string} path the test file's repository path+ * @param {string[]} modulePaths every module path in the committed tree+ * @returns {string[] | null} the modules it reads, or null when some computed import cannot be read*/function literalLoads(source, path, modulePaths) {const targets = new Set();@@ -38,6 +66,7 @@ function literalLoads(source, path, modulePaths) {let depth = 1, end = start;for (; end < source.length && depth; end += 1) depth += source[end] === '(' ? 1 : source[end] === ')' ? -1 : 0;const argument = source.slice(start, end);+ if (unresolvedBranch(argument)) return null;const values = [...argument.matchAll(/(['"`])((?:\\.|(?!\1)[^\\\r\n])*)\1/gu)].map(match => match[2].split(/[?#]/u)[0]);const modules = values.filter(value => MODULE.test(value) && posix.basename(value).replace(MODULE, '') !== '');if (!modules.length) return null;diff --git a/test/affected-tests.test.js b/test/affected-tests.test.jsindex b8d21877..665744c5 100644--- a/test/affected-tests.test.js+++ b/test/affected-tests.test.js@@ -247,3 +247,16 @@ test('a change to one test file selects only what reads it [V4,C7]', (t) => {assert.equal(selection.full, true, 'an undeclared computed import falls back to the whole suite');assert.match(selection.reason, /test\/guess\.test\.js/u, 'the fallback names the file that cannot be read');});++test('a computed import with an environment fallback reads every candidate, not one literal [V4,C7]', (t) => {+ const box = graph(t);+ box.put('src/b.js', 'export const value = 1;\n');+ // The loader reads src/b.js whenever CASE_MODULE names it, so the literal fallback alone is not its read set.+ box.put('test/loader.test.js', "await import(new URL(process.env.CASE_MODULE || '../src/api.js', import.meta.url).href);\n");+ const base = box.commit();+ box.put('src/b.js', 'export const value = 2;\n');+ const commit = box.commit();+ const selection = selectAffectedTests(box.root, { base, commit, changed: ['src/b.js'] });+ assert.equal(selection.full, true, 'an unresolved branch falls back to the whole suite instead of a partial read set');+ assert.match(selection.reason, /test\/loader\.test\.js/u, 'the fallback names the loader it cannot read');+});