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: widen tree-wide source-scan guards to cover tracked .mjs/.cjs files (#7953)

[._.]/ Adam Eivya1c812ff2c9c
diff --git a/server/lib/childProcess.guards.test.js b/server/lib/childProcess.guards.test.js
index 6b58ebff45..1a26c5f69f 100644
--- a/server/lib/childProcess.guards.test.js
+++ b/server/lib/childProcess.guards.test.js
@@ -167,6 +167,9 @@ describe('child_process import guard', () => {
it('scans a non-trivial set of files (guard is not vacuous)', () => {
expect(allFiles.length).toBeGreaterThan(50);
expect(candidates.length).toBeGreaterThan(5);
+ // `server/scripts/` is `.mjs`, and a `.js`-only walk would silently drop it
+ // (#7953) — assert the widened extension list actually reaches it.
+ expect(allFiles.some((rel) => rel.endsWith('.mjs'))).toBe(true);
// Each sibling package must actually be reached. If one is renamed or moved,
// its rule below would iterate nothing and pass green forever.
for (const tree of CALL_SITE_TREES) {
diff --git a/server/lib/testHelper.js b/server/lib/testHelper.js
index 287ed610cd..70cc3510ed 100644
--- a/server/lib/testHelper.js
+++ b/server/lib/testHelper.js
@@ -187,15 +187,23 @@ export function mockTextResponse(body = '', { ok = true, status = 200, contentTy
};
}
+/** Non-test module extensions this tree ships: `.mjs` under `server/scripts/`, `.cjs` nowhere yet but supported. */
+const SOURCE_EXTENSIONS = ['.js', '.mjs', '.cjs'];
+
/**
- * Every non-test `.js` file under `server/`, as server-relative paths.
+ * Every non-test source file under `server/` (`.js`, `.mjs`, `.cjs`), as
+ * server-relative paths.
*
* Shared by the source-scanning guard suites — `spawnCwd.test.js` (every
- * cwd-passing spawn pins PWD, #3193) and `cliChildEnv.test.js` (every AI-CLI
- * spawn composes its env through the shared builder, #3194). Those two guards
- * deliberately overlap, so they must agree on what "a source file" is: a change
- * to the ignore rules here (a new extension, a skipped directory) has to apply
- * to both, or one guard silently stops covering files the other still checks.
+ * cwd-passing spawn pins PWD, #3193), `cliChildEnv.test.js` (every AI-CLI
+ * spawn composes its env through the shared builder, #3194), and
+ * `childProcess.guards.test.js` (every spawn routes through the shared
+ * wrapper, #5678). Those guards deliberately overlap, so they must agree on
+ * what "a source file" is: a change to the ignore rules here (a new
+ * extension, a skipped directory) has to apply to all of them, or one guard
+ * silently stops covering files the others still check. A `.js`-only walk
+ * missed the operator scripts under `server/scripts/`, which are `.mjs`
+ * (#7953).
*
* @param {string} [dir] - directory to walk (defaults to the `server/` root)
* @returns {string[]} paths relative to `server/`, e.g. `services/runner.js`
@@ -221,7 +229,8 @@ export function collectServerSources(dir = SERVER_DIR) {
if (entry.name === 'node_modules' || entry.name.startsWith('.')) return [];
const abs = join(dir, entry.name);
if (entry.isDirectory()) return collectServerSources(abs);
- if (!entry.name.endsWith('.js') || entry.name.endsWith('.test.js')) return [];
+ const ext = SOURCE_EXTENSIONS.find((e) => entry.name.endsWith(e));
+ if (!ext || entry.name.endsWith(`.test${ext}`)) return [];
// POSIX separators always. These relative paths are IDENTIFIERS, not paths
// to open: guard suites compare them against literals like
// 'cos-runner/index.js' and list them in EXEMPT/DELEGATES tables. On
diff --git a/server/process-safety-net.test.js b/server/process-safety-net.test.js
index 096ab6682d..0e553293f1 100644
--- a/server/process-safety-net.test.js
+++ b/server/process-safety-net.test.js
@@ -18,6 +18,12 @@ const read = (rel) => toCode(readFileSync(join(__dirname, rel), 'utf8'));
// entry file that boots on import.
const TOP_LEVEL_CALL = /^[ \t]*setupProcessErrorHandlers\s*\(/m;
+// Unlike the other #7953 source-scan guards, this one names its subjects by
+// path rather than by a `git ls-files` extension glob, so there is no `.js`
+// pathspec to widen: it already covers every long-running process the tree
+// boots, whatever its extension. The tracked `.mjs` scripts under
+// `server/scripts/` are one-shot operator CLIs — none calls `server.listen`
+// or otherwise stays resident — so none belongs in this list.
const WIRING_GUARDS = [
// The main server wires the net from its boot sequence (services/bootstrap.js,
// extracted from index.js in #2839) as a NAMED STEP handed to
diff --git a/server/sockets/asyncHandlerGuard.test.js b/server/sockets/asyncHandlerGuard.test.js
index 74116bd88a..2cc15ef8ae 100644
--- a/server/sockets/asyncHandlerGuard.test.js
+++ b/server/sockets/asyncHandlerGuard.test.js
@@ -113,8 +113,13 @@ export function findUnguardedHandlerAwaits(src) {
.map((chain) => `line ${handler.line} '${handler.event}': ${chain}`));
}
+// `.mjs`/`.cjs` alongside `.js`: nothing under this directory ships those
+// extensions today, but a `.js`-only filter would silently drop one that did
+// (#7953) — the recognizer test below proves the filter itself, not just the
+// current directory contents, actually accepts them.
+const SOCKET_FILE_RE = /\.(?:js|mjs|cjs)$/;
const socketFiles = readdirSync(HERE)
- .filter((f) => f.endsWith('.js') && !f.includes('.test.'))
+ .filter((f) => SOCKET_FILE_RE.test(f) && !f.includes('.test.'))
.sort();
describe('async socket handlers own their rejections (#5661)', () => {
@@ -131,6 +136,15 @@ describe('async socket handlers own their rejections (#5661)', () => {
]));
});
+ // Nothing under this directory ships `.mjs`/`.cjs` today, so the scan above
+ // cannot prove the filter would catch one that did — assert the filter
+ // itself, not just this directory's current contents (#7953).
+ it('would scan a .mjs or .cjs handler file, not just .js', () => {
+ expect(SOCKET_FILE_RE.test('example.mjs')).toBe(true);
+ expect(SOCKET_FILE_RE.test('example.cjs')).toBe(true);
+ expect(SOCKET_FILE_RE.test('example.test.mjs')).toBe(true);
+ });
+
it('has no unguarded await in any async socket handler', () => {
const violations = socketFiles.flatMap((file) => (
findUnguardedHandlerAwaits(readFileSync(join(HERE, file), 'utf8'))
diff --git a/server/timerCallbackConventions.test.js b/server/timerCallbackConventions.test.js
index 53b590fa49..9eebf53c32 100644
--- a/server/timerCallbackConventions.test.js
+++ b/server/timerCallbackConventions.test.js
@@ -114,7 +114,10 @@ export function findUnguardedTimerAwaits(src) {
});
}
-const trackedServerSources = () => execFileSync('git', ['ls-files', '*.js'], {
+// Every module extension the tree actually ships, not just `.js`: the operator
+// scripts under `server/scripts/` are `.mjs`, and a `*.js`-only glob would
+// report the tree clean while one of them held an unguarded timer (#7953).
+const trackedServerSources = () => execFileSync('git', ['ls-files', '*.js', '*.mjs', '*.cjs'], {
cwd: SERVER_ROOT,
encoding: 'utf8',
maxBuffer: 64 * 1024 * 1024,
@@ -127,6 +130,12 @@ describe('async timer callbacks own their rejections (#5668)', () => {
expect(trackedServerSources().length).toBeGreaterThan(200);
});
+ it('scans every module extension the tree ships, not only .js', () => {
+ // `server/scripts/` is `.mjs`, and a `*.js`-only glob would call the tree
+ // clean while a script in that extension held an unguarded timer.
+ expect(trackedServerSources().filter((f) => f.endsWith('.mjs')).length).toBeGreaterThan(0);
+ });
+
it('finds the async timer callbacks it is meant to guard', () => {
// Proves the extractor still recognizes real call sites — without this the
// scan below could go vacuously green after an unrelated refactor.