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

test: cache export lookups in the mock contract scan (#11891)

Adam Eivye3e2952d5628
diff --git a/scripts/lib/mockContractScan.js b/scripts/lib/mockContractScan.js
index 4af2d4cfcc..4d35b5b24c 100644
--- a/scripts/lib/mockContractScan.js
+++ b/scripts/lib/mockContractScan.js
@@ -179,6 +179,8 @@ function literalKeys(raw, masked, open) {
const FACTORY_RE = /\bvi\.mock\(\s*(['"])([^'"]+)\1\s*,\s*(?:async\s*)?\(\s*\)\s*=>\s*\(\s*\{/g;
+const exportCache = new Map();
+
/** `file:line — spec mocks <key>` for each key the real module does not export. */
export function mockDrift(testFile, rawSource, { root, allowed = new Map() }) {
const masked = mask(rawSource);
@@ -193,7 +195,8 @@ export function mockDrift(testFile, rawSource, { root, allowed = new Map() }) {
const open = m.index + m[0].length - 1;
const keys = literalKeys(rawSource, masked, open);
if (!keys) continue;
- const exported = exportNames(target);
+ if (!exportCache.has(target)) exportCache.set(target, exportNames(target));
+ const exported = exportCache.get(target);
for (const key of keys) {
if (key === '__esModule' || exported.has(key) || allowed.has(`${rel}|${m[2]}|${key}`)) continue;
const line = rawSource.slice(0, m.index).split('\n').length;