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(core): a helper call's result never bounds a computed import [C7]

Corey Olson0c822c488a94
diff --git a/src/affected-tests.js b/src/affected-tests.js
index aca5d930..e7614134 100644
--- a/src/affected-tests.js
+++ b/src/affected-tests.js
@@ -24,6 +24,9 @@ function declaredLoads(source) {
.filter(path => MODULE.test(path) && !path.startsWith('../') && !path.startsWith('/'));
}
+/** Calls whose result is a path built from their arguments, so a literal passed to them still bounds the target. */
+const PATH_CALLS = new Set(['join', 'resolve', 'URL', 'fileURLToPath', 'pathToFileURL']);
+
/**
* 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
@@ -41,7 +44,9 @@ function unresolvedBranch(argument) {
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;
+ // Only known path builders may be called: what any other call returns is decided at run time (#803).
+ if (after === '(') { if (PATH_CALLS.has(match[0])) continue; return true; }
+ if (before === '.' || after === '.' || match[0] === 'new') continue;
return true;
}
return false;
diff --git a/test/affected-tests.test.js b/test/affected-tests.test.js
index 665744c5..d15027a4 100644
--- a/test/affected-tests.test.js
+++ b/test/affected-tests.test.js
@@ -248,6 +248,24 @@ test('a change to one test file selects only what reads it [V4,C7]', (t) => {
assert.match(selection.reason, /test\/guess\.test\.js/u, 'the fallback names the file that cannot be read');
});
+test('a computed import through a helper call is not read from the literal it passes [V4,C7]', (t) => {
+ for (const loader of [
+ "function pick(fallback) { return process.env.CASE_MODULE || fallback; }\nawait import(new URL(pick('../src/api.js'), import.meta.url).href);\n",
+ "const helpers = { pick: (fallback) => process.env.CASE_MODULE || fallback };\nawait import(new URL(helpers.pick('../src/api.js'), import.meta.url).href);\n",
+ ]) {
+ const box = graph(t);
+ box.put('src/b.js', 'export const value = 1;\n');
+ // What pick returns is decided at run time, so its literal argument does not bound what the loader reads.
+ box.put('test/loader.test.js', loader);
+ 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, `a helper call's result is unresolved, so the selection falls back to the whole suite: ${loader}`);
+ assert.match(selection.reason, /test\/loader\.test\.js/u);
+ }
+});
+
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');