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(admission): a concatenated string title is not CPU options [C7,V4]

Corey Olsondae7e16a0a60
diff --git a/src/module-imports.js b/src/module-imports.js
index 98b50e0c..23b658c8 100644
--- a/src/module-imports.js
+++ b/src/module-imports.js
@@ -432,9 +432,25 @@ function firstCpuOption(source, bindings, quoted, argument) {
}
// A complete string/template is a title; every unresolved expression may instead be options.
if (bindings.strings.some(value => value.start === from && value.end === to)) return false;
+ if (stringConcatenation(bindings, from, to)) return false;
return cpuOption(source, bindings.code, quoted, [from, to]);
}
+/** A string literal joined only by top-level + always evaluates to a string, so it is a title, never options. */
+function stringConcatenation(bindings, from, to) {
+ const lead = bindings.strings.find(value => value.start === from && value.end < to);
+ if (!lead || !/^\s*\+/u.test(bindings.code.slice(lead.end, to))) return false;
+ let depth = 0;
+ for (let index = lead.end; index < to; index++) {
+ const char = bindings.code[index];
+ if ('([{'.includes(char)) depth++;
+ else if (')]}'.includes(char)) depth--;
+ // A conditional, logical or sequence operator could still yield a non-string value.
+ else if (depth === 0 && '?|&,'.includes(char)) return false;
+ }
+ return depth === 0;
+}
+
/** Return registration exports for bounded static module-graph propagation, not execution. */
export function cpuRegistrationExportsIn(sources, moduleExports = () => new Set(), literalCache = new Map()) {
return sources.map((source, index) => cpuBindings(source, name => moduleExports(index, name), false, literalCache).exports);
diff --git a/test/cpu-callable-options.test.js b/test/cpu-callable-options.test.js
index 5e1c873b..cd7c9ebe 100644
--- a/test/cpu-callable-options.test.js
+++ b/test/cpu-callable-options.test.js
@@ -51,3 +51,12 @@ test('a proven string title and callable callback do not become CPU options [C7]
assert.equal(cpuLoadOptionsIn([source])[0], false);
}
});
+
+test('a string-concatenated title is a title, while a conditional first argument stays conservative [C7,V4]', () => {
+ // The landing-shards fixture names its case 'fixture file ' + name; that can only be a string.
+ assert.equal(cpuLoadOptionsIn(["import test from 'node:test'; const name = 'a'; test('fixture file ' + name, async () => {});"])[0], false);
+ assert.equal(cpuLoadOptionsIn(["import test from 'node:test'; test('case ' + name + ' at ' + (Date.now() % 7), () => {});"])[0], false);
+ assert.equal(cpuLoadOptionsIn(["import test from 'node:test'; test('x' + flag ? options : 'y', () => {});"])[0], true,
+ 'a top-level conditional could still pass an options object');
+ assert.equal(cpuLoadOptionsIn(["import test from 'node:test'; test({ cpuLoad: true }, async () => {});"])[0], true);
+});