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(gate): distinguish callbacks from invoked option factories [C7]

Corey Olsona5ea928fa9b4
diff --git a/src/module-imports.js b/src/module-imports.js
index b0088495..7dc6346a 100644
--- a/src/module-imports.js
+++ b/src/module-imports.js
@@ -216,9 +216,13 @@ function opaqueOptions(source, code, from, to) {
/** Recognize callback syntax only; an opaque function-producing expression can instead be options. */
function callbackSource(source) {
- const value = pastGap(source, 0);
- return /^(?:async\s+)?function\b/u.test(value)
- || /^(?:async\s+)?(?:[A-Za-z_$][\w$]*|\([^]*?\))\s*=>/u.test(value);
+ let code = lex(source).code.trim();
+ code = code.replace(/^async\s+/u, '');
+ if (/^function\b/u.test(code)) return code.endsWith('}');
+ if (/^[A-Za-z_$][\w$]*\s*=>/u.test(code)) return true;
+ if (!code.startsWith('(')) return false;
+ const parameters = sourceParts(code, 1, ')');
+ return Boolean(parameters && code.slice(parameters.end + 1).trimStart().startsWith('=>'));
}
/** Unknown test option expressions are declarations under the conservative placement contract. */
diff --git a/test/cpu-load-tests.test.js b/test/cpu-load-tests.test.js
index c9ce2911..2a430ba5 100644
--- a/test/cpu-load-tests.test.js
+++ b/test/cpu-load-tests.test.js
@@ -113,6 +113,7 @@ for (const [kind, declaration, binding] of [
['computed property', '{ [["cpu", "Load"].join("")]: true }', 'test'],
['spread property', '{ ...Object.fromEntries([[ ["cpu", "Load"].join(""), true ]]) }', 'test'],
['opaque options and an imported alias', 'Object.fromEntries([[ ["cpu", "Load"].join(""), true ]])', 'register'],
+ ['invoked option factory', '(() => Object.fromEntries([[ ["cpu", "Load"].join(""), true ]]))()', 'test'],
]) test(`unreadable ${kind} options conservatively use a registered runner [C7]`, async () => {
const box = cpuLoadFixture(e2e, { declaration, binding });
const remote = await box.runGate();