Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: match Python import_module calls with whitespace before the paren (#12300)

[._.]/ Adam Eivy33db843381d4
diff --git a/scripts/lib/testMemo.js b/scripts/lib/testMemo.js
index 7bc274a7b0..5126fac9a8 100644
--- a/scripts/lib/testMemo.js
+++ b/scripts/lib/testMemo.js
@@ -801,7 +801,8 @@ export function extractFileFacts(src, { fileRel, cwdRel }) {
// `require(PACKAGE_CONSTANT)`: a module-level string is a specifier like a literal one.
if (value.k === 'str') { facts.edges.push({ spec: value.v, kind }); continue; }
// `require(join(<unknown dir>, 'ecosystem.config.cjs'))`: the directory is a parameter or an
- // install root, the basename is fixed, so every tracked file of that name is an input.
+ // install root, the basename is fixed, so every tracked file of that name is an input
+ // (tests only load in-repo files, so keying by tracked basename covers the real target).
const scoped = kind === 'require' ? joinedBasename(arg.index) : null;
if (scoped !== null) { facts.scopedNames.push(scoped); continue; }
facts.unresolvedEdges.push(`${token.v}() with a non-literal specifier`);
@@ -1047,7 +1048,7 @@ export function createTestMemoAnalyzer({ fs, workspaceRel, env = {}, platform =
const names = m ? (m[1] !== undefined ? [m[1]] : m[2].split(',')).map((part) => part.trim()).filter(Boolean) : [];
// `importlib.import_module('x')` is a sibling import; a non-literal name may reach any module.
if (!/^\s*#/.test(line)) {
- for (const call of line.matchAll(/\bimport_module\(\s*(?:(['"])([\w.]+)\1(?=\s*[,)])|)/g)) {
+ for (const call of line.matchAll(/\bimport_module\s*\(\s*(?:(['"])([\w.]+)\1(?=\s*[,)])|)/g)) {
if (call[2] !== undefined) names.push(call[2]);
else resolved.unresolvedInputs.push(`python import_module with a non-literal name in ${target}`);
}
diff --git a/scripts/lib/testMemo.test.js b/scripts/lib/testMemo.test.js
index 5427950411..c3b00539da 100644
--- a/scripts/lib/testMemo.test.js
+++ b/scripts/lib/testMemo.test.js
@@ -282,6 +282,10 @@ describe('python sidecars, external tools and machine-local state', () => {
expect(key({ ...files, 'scripts/tool.py': 'import importlib\nmod = importlib.import_module(name)\n' })).toMatchObject({ memoizable: false, reason: expect.stringContaining('import_module') });
// A literal prefix of a computed name is not the whole argument.
expect(key({ ...files, 'scripts/tool.py': "import importlib\nmod = importlib.import_module('_pins' + suffix)\n" })).toMatchObject({ memoizable: false, reason: expect.stringContaining('import_module') });
+ // Whitespace between the name and '(' is valid Python and must not bypass either path.
+ const spaced = { ...files, 'scripts/tool.py': "import importlib\nmod = importlib.import_module ('_pins')\n" };
+ expect(key({ ...spaced, 'scripts/_pins.py': 'PINS = 2\n' }).key).not.toBe(key(spaced).key);
+ expect(key({ ...files, 'scripts/tool.py': 'import importlib\nmod = importlib.import_module (name)\n' })).toMatchObject({ memoizable: false, reason: expect.stringContaining('import_module') });
});
it('fails closed when the test or repository tooling reads the install data tree or the home directory, and ignores a product module doing so', () => {