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: cover the rebuild decision and close the CI-invisible accounting gap

Adam Eivye6a2d1a59d92
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 97ad98378a..2490f7f4d0 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -24,7 +24,7 @@
- **The `ignore-scripts` supply-chain guard was silently inactive for every workspace install, including CI.** The repo-root `.npmrc` has pinned `ignore-scripts=true` for a while, but npm resolves the project `.npmrc` from the *local prefix* and never walks up the directory tree — so it never applied to `cd client && npm install`, `cd server && npm install`, or `npm ci --prefix server` / `--prefix client`, which is exactly what CI runs and what the documented per-workspace test workflow uses. In those paths every dependency kept an install-time code-execution slot: the same slot the August 2026 keyv/cacheable (Shai-Hulud) worm used, via a `preinstall` hook, to harvest credentials before any application code ran. `client/`, `server/`, `autofixer/`, and `browser/` now each carry their own `.npmrc`, so the guard holds in every workspace install path — whether entered by `cd`ing in or via `--prefix`.
- Closing the hole made the trusted-rebuild allowlist load-bearing for the first time, and it had drifted across its four copies (the root `setup` script, `scripts/ensure-deps.js`, `update.sh`, `update.ps1`): the `esbuild` entries were dead — vite 8 dropped that dependency — while `onnxruntime-node` and `protobufjs` were missing entirely, so CI ran install hooks that the local setup skipped. All four now read one allowlist from `scripts/trusted-rebuilds.js`, and CI rebuilds it explicitly after installing server dependencies so `node-pty`'s native binding is still present for the smoke-boot. `scripts/trusted-rebuilds.test.js` fails if any workspace `.npmrc` loses the setting, or if a dependency shows up with an install hook nobody has decided about — the second case being how a missing native build otherwise surfaces much later as a confusing runtime crash.
+ Closing the hole made the trusted-rebuild allowlist load-bearing for the first time, and it had drifted across its five copies (the root `setup` script, `scripts/ensure-deps.js`, `update.sh`, `update.ps1`, `setup.ps1`): the `esbuild` entries were dead — vite 8 dropped that dependency — while `onnxruntime-node` and `protobufjs` were missing entirely, so CI ran install hooks that the local setup skipped. All four now read one allowlist from `scripts/trusted-rebuilds.js`, and CI rebuilds it explicitly after installing server dependencies so `node-pty`'s native binding is still present for the smoke-boot. `scripts/trusted-rebuilds.test.js` fails if any workspace `.npmrc` loses the setting, or if a dependency shows up with an install hook nobody has decided about — the second case being how a missing native build otherwise surfaces much later as a confusing runtime crash.
- **Release notes told fresh-clone users to run `npm install`, which cannot produce a working install.** The fallback release-notes template in `.github/workflows/release.yml` printed a `git clone` + `npm install` + `pm2 start` sequence, but a bare root `npm install` skips the client, server, and Autofixer workspaces, never initializes the bundled submodules, and does no data/database provisioning. It now points at `npm run install:all`, matching the README.
diff --git a/.npmrc b/.npmrc
index f44b6f2364..adaf6de7a3 100644
--- a/.npmrc
+++ b/.npmrc
@@ -10,7 +10,7 @@
#
# Packages with legitimate install scripts are rebuilt explicitly from the
# allowlist in scripts/trusted-rebuilds.js (shared by `npm run setup`,
-# scripts/ensure-deps.js, update.sh/update.ps1 and CI). Currently only the
+# scripts/ensure-deps.js, setup.ps1, update.sh/update.ps1 and CI). Currently only the
# server needs any: node-pty (native PTY addon), sharp (insurance — ships
# prebuilt bindings today), and onnxruntime-node / protobufjs (best-effort).
ignore-scripts=true
diff --git a/client/biome.jsonc b/client/biome.jsonc
index 479473eacb..f0bf4ee30d 100644
--- a/client/biome.jsonc
+++ b/client/biome.jsonc
@@ -53,10 +53,20 @@
// nobody acts on, i.e. noise that hides real errors. Biome defaults many rules to
// 'warn', so every rule below sets 'error' explicitly.
//
- // `preset: "none"` + an explicit list keeps this a faithful port of the ESLint
- // rule set (js.configs.recommended + 8 @eslint-react rules + react-hooks). Biome's
- // own `recommended` preset is much broader; adopting it is a separate policy
+ // `preset: "none"` + an explicit list ports the ESLint rule set
+ // (js.configs.recommended + 8 @eslint-react rules + react-hooks). Biome's own
+ // `recommended` preset is much broader; adopting it is a separate policy
// decision, not part of this migration.
+ //
+ // KNOWN PARITY GAPS — this is a near-port, not a total one. Measured, not assumed:
+ // * `no-cond-assign` and `no-empty` have only *broader* Biome analogues
+ // (`noAssignInExpressions` ~400 hits, `noEmptyBlockStatements` ~705 hits on
+ // today's src — mostly `while ((m = re.exec(s)))` and `() => {}` mocks), so
+ // enabling them as-is would be a lint-policy change, not a port. Left off.
+ // * No Biome equivalent exists for `no-invalid-regexp`, `no-useless-assignment`,
+ // `no-unexpected-multiline`, `no-delete-var`, or `no-empty-static-block`.
+ // Most are parse-level or moot in ESM.
+ // Do not upgrade this comment to a claim of full parity without re-measuring.
"rules": {
"preset": "none",
"complexity": {
@@ -131,6 +141,11 @@
// eslint: require-yield
"useYield": "error"
},
+ "style": {
+ // eslint: preserve-caught-error — re-throwing without `{ cause }` loses the
+ // original error. 0 hits on today's src, so enforcing it is free.
+ "useErrorCause": "error"
+ },
"security": {
// @eslint-react/dom-no-unsafe-target-blank
"noBlankTarget": "error",
@@ -146,6 +161,9 @@
"noClassAssign": "error",
// eslint: no-compare-neg-zero
"noCompareNegZero": "error",
+ // eslint: no-constant-binary-expression — 0 hits on today's src, so
+ // enforcing it is free and closes one of the recommended-set gaps above.
+ "noConstantBinaryExpressions": "error",
// eslint: no-control-regex
"noControlCharactersInRegex": "error",
// eslint: no-debugger
diff --git a/client/package.json b/client/package.json
index 3317eec203..ed94344278 100644
--- a/client/package.json
+++ b/client/package.json
@@ -7,7 +7,7 @@
"dev": "vite --host 0.0.0.0 --port 5554",
"build": "vite build",
"build:analyze": "ANALYZE=true vite build",
- "lint": "biome lint src",
+ "lint": "biome lint --error-on-warnings src",
"preview": "vite preview",
"test": "vitest run",
"test:ci": "vitest run --bail=1 --reporter=default --reporter=github-actions",
diff --git a/docs/DEPS.md b/docs/DEPS.md
index ba882ad135..9affa28bfe 100644
--- a/docs/DEPS.md
+++ b/docs/DEPS.md
@@ -57,7 +57,7 @@ Before removing a Tier 3 candidate, run a transitive-dep check (`npm ls <pkg>`).
| `three` | 1 | KEEP | 3D | |
| **Client devDeps** | | | | |
| `@biomejs/biome` | 1 | KEEP | linting | Replaced the whole eslint stack 2026-08-04; native binary, 0 regular deps + 8 platform optionals (1 installed) |
-| `eslint` | — | REMOVED | linting | 2026-08-04 → `@biomejs/biome`. Pulled 53 exclusive packages incl. the `file-entry-cache → flat-cache → keyv` chain |
+| `eslint` | — | REMOVED | linting | 2026-08-04 → `@biomejs/biome`. 53 packages were reachable only via `eslint` itself (incl. the `file-entry-cache → flat-cache → keyv` chain); 110 net once the plugin subtrees and orphaned `typescript` go too |
| `@eslint/js` | — | REMOVED | linting | Removed with `eslint` |
| `@eslint-react/eslint-plugin` | — | REMOVED | linting | Removed with `eslint`; its 8 enabled rules map to Biome rules + one GritQL plugin |
| `eslint-plugin-react-hooks` | — | REMOVED | linting | Removed with `eslint`; `rules-of-hooks` → Biome `useHookAtTopLevel` |
@@ -141,4 +141,4 @@ These exist purely to force-bump transitive deps; revisit if `npm audit` flags n
`ignore-scripts=true` is pinned in **every** workspace's own `.npmrc` (root, `client/`, `server/`, `autofixer/`, `browser/`) — not just the repo root. The list is not maintained by hand: `discoverWorkspaces()` in `scripts/trusted-rebuilds.js` globs every top-level directory carrying a `package.json`, and the test asserts each discovered one has the setting — so a workspace added later is caught rather than silently unguarded. npm resolves the project `.npmrc` from the *local prefix* and never walks up the directory tree, so a root-only setting does not cover `cd client && npm install` or `npm ci --prefix server` (what CI runs). Deleting any workspace `.npmrc` silently re-grants every dependency in that workspace an install-time code-execution slot — the vector the Shai-Hulud worm used.
-Packages that legitimately need an install script are named explicitly in the allowlist in `scripts/trusted-rebuilds.js`, the single source consumed by `npm run setup`, `scripts/ensure-deps.js`, `update.sh` / `update.ps1`, and CI. `scripts/trusted-rebuilds.test.js` fails if a workspace `.npmrc` loses the setting, or if a dependency appears with an install hook that nobody has explicitly decided about.
+Packages that legitimately need an install script are named explicitly in the allowlist in `scripts/trusted-rebuilds.js`, the single source consumed by `npm run setup`, `scripts/ensure-deps.js`, `setup.ps1`, `update.sh` / `update.ps1`, and CI. `scripts/trusted-rebuilds.test.js` fails if a workspace `.npmrc` loses the setting, or if a dependency appears with an install hook that nobody has explicitly decided about.
diff --git a/scripts/trusted-rebuilds.js b/scripts/trusted-rebuilds.js
index 10b03df594..4843b067d6 100644
--- a/scripts/trusted-rebuilds.js
+++ b/scripts/trusted-rebuilds.js
@@ -9,8 +9,10 @@
* Those are rebuilt explicitly here — an allowlist, so adding a dependency
* never silently grants it an install-time code-execution slot.
*
- * Consumed by scripts/ensure-deps.js, the root `setup` script, and CI. Keep the
- * list here only — a second copy in a workflow file is how it drifts.
+ * Consumed by scripts/ensure-deps.js, the root `setup` script, setup.ps1,
+ * update.sh, update.ps1, and CI. Keep the list here only — a second copy is how it
+ * drifts, which is exactly how setup.ps1 ended up rebuilding a package that no
+ * longer exists while missing two that do.
*
* Usage as a CLI (what CI and `npm run setup` call):
* node scripts/trusted-rebuilds.js server
@@ -81,14 +83,20 @@ export const TRUSTED_REBUILDS = {
/**
* Rebuild the trusted packages for one workspace.
* Returns true when every fatal group succeeded.
+ *
+ * `spawn` is injectable so the fatal/non-fatal decision is testable without
+ * actually invoking npm. That decision is the whole point of the module — if it
+ * inverts, a failed node-pty build exits 0 and the missing binding resurfaces as
+ * a confusing MODULE_NOT_FOUND at smoke-boot — so it needs real coverage rather
+ * than only a shape assertion on TRUSTED_REBUILDS.
*/
-export function rebuildTrusted(dir, label) {
+export function rebuildTrusted(dir, label, { spawn = execFileSync } = {}) {
const groups = TRUSTED_REBUILDS[label];
if (!groups) return true;
let ok = true;
for (const { pkgs, fatal } of groups) {
try {
- execFileSync(NPM, ['rebuild', ...pkgs], { cwd: dir, stdio: 'inherit', windowsHide: true });
+ spawn(NPM, ['rebuild', ...pkgs], { cwd: dir, stdio: 'inherit', windowsHide: true });
} catch (err) {
console.error(`⚠️ npm rebuild ${pkgs.join(' ')} failed for ${label}: ${err.message ?? err}`);
if (fatal) ok = false;
@@ -97,15 +105,19 @@ export function rebuildTrusted(dir, label) {
return ok;
}
-// CLI entry: `node scripts/trusted-rebuilds.js <label> [dir]`
-function main() {
- const label = process.argv[2];
+/**
+ * CLI body, returning an exit code instead of calling process.exit, so every
+ * branch (usage, unknown label, rebuild-free workspace, rebuild failure) is
+ * assertable. `node scripts/trusted-rebuilds.js <label> [dir]`
+ */
+export function runCli(argv, { spawn = execFileSync } = {}) {
+ const [label, dirOverride] = argv;
if (!label) {
// List the real workspaces, not just the keys of TRUSTED_REBUILDS — the CLI
// accepts any workspace (a rebuild-free one is a documented no-op), so
// advertising only `server` misrepresents what is valid.
console.error(`❌ usage: node scripts/trusted-rebuilds.js <${discoverWorkspaces().join('|')}>`);
- process.exit(1);
+ return 1;
}
// Validate the label against the real workspace list BEFORE the "nothing to do"
// check below. Otherwise a typo (`sever`) falls through to a green "✅ no trusted
@@ -115,14 +127,14 @@ function main() {
const workspaces = discoverWorkspaces();
if (!workspaces.includes(label)) {
console.error(`❌ unknown workspace '${label}'. Known workspaces: ${workspaces.join(', ')}`);
- process.exit(1);
+ return 1;
}
if (!TRUSTED_REBUILDS[label]) {
console.log(`✅ no trusted rebuilds needed for ${label}`);
- process.exit(0);
+ return 0;
}
console.log(`🔨 Rebuilding trusted install-script packages for ${label}`);
- process.exit(rebuildTrusted(process.argv[3] ?? workspaceDir(label), label) ? 0 : 1);
+ return rebuildTrusted(dirOverride ?? workspaceDir(label), label, { spawn }) ? 0 : 1;
}
// Matches the entry-guard idiom in scripts/run-ci-lint.js — `resolve()` on both
@@ -130,4 +142,4 @@ function main() {
const isMain = process.argv[1]
&& resolve(process.argv[1]) === resolve(fileURLToPath(import.meta.url));
-if (isMain) main();
+if (isMain) process.exit(runCli(process.argv.slice(2)));
diff --git a/scripts/trusted-rebuilds.test.js b/scripts/trusted-rebuilds.test.js
index d522669283..2e6348d434 100644
--- a/scripts/trusted-rebuilds.test.js
+++ b/scripts/trusted-rebuilds.test.js
@@ -2,7 +2,7 @@ import { describe, it, expect } from 'vitest';
import { readFileSync, existsSync, readdirSync } from 'fs';
import { join } from 'path';
-import { TRUSTED_REBUILDS, discoverWorkspaces, workspaceDir } from './trusted-rebuilds.js';
+import { TRUSTED_REBUILDS, discoverWorkspaces, workspaceDir, rebuildTrusted, runCli } from './trusted-rebuilds.js';
// Discovered, not hand-listed: a hardcoded roster here would silently miss a
// workspace added later, leaving it with no `ignore-scripts` guard while this
@@ -11,6 +11,32 @@ const WORKSPACES = discoverWorkspaces();
const LIFECYCLE_HOOKS = ['preinstall', 'install', 'postinstall'];
+/**
+ * Packages a workspace declares an install hook for, read from the committed
+ * lockfile. This is the CI-safe path: `scripts/**` is globbed only by the SERVER
+ * vitest runner, and the server CI job installs only server deps — so for
+ * client/autofixer/browser there is no node_modules and a node_modules-only scan
+ * silently skipped, meaning the accounting assertion below never ran for them in
+ * CI. A dependency there gaining a postinstall (a Dependabot bump, or a
+ * compromised release) would have sailed through green. The lockfile is committed,
+ * so this works with zero installs.
+ */
+function lockfileInstallScriptPackages(label) {
+ const lock = join(workspaceDir(label), 'package-lock.json');
+ if (!existsSync(lock)) return null;
+ let parsed;
+ try {
+ parsed = JSON.parse(readFileSync(lock, 'utf8'));
+ } catch {
+ return null;
+ }
+ return new Set(
+ Object.entries(parsed?.packages ?? {})
+ .filter(([, meta]) => meta?.hasInstallScript === true)
+ .map(([path]) => path.replace(/.*node_modules\//, ''))
+ );
+}
+
/**
* Packages in a workspace's installed tree that declare a lifecycle install hook.
* Returns null when the workspace has no node_modules (e.g. the client tree in
@@ -112,7 +138,18 @@ describe('trusted rebuild allowlist', () => {
// postinstall and nobody decides about it, it is silently left unbuilt — which
// surfaces much later as a confusing runtime crash on a missing native binding.
// Fail here instead, when the dependency lands, and force the decision.
- const DELIBERATELY_UNBUILT = {};
+ // `fsevents` carries `hasInstallScript: true` in the lockfiles, but that is stale
+ // registry metadata: the installed 2.3.3 ships `fsevents.node` prebuilt and
+ // declares no hook and no binding.gyp (verified in all three trees that have it).
+ // It is also darwin-only and optional, so it is absent entirely on CI. Nothing to
+ // rebuild — recorded here so the lockfile-derived check stays honest rather than
+ // being loosened.
+ const FSEVENTS_STALE_FLAG = ['fsevents'];
+ const DELIBERATELY_UNBUILT = {
+ root: FSEVENTS_STALE_FLAG,
+ client: FSEVENTS_STALE_FLAG,
+ server: FSEVENTS_STALE_FLAG
+ };
it('detects install hooks at all, so the accounting assertion is not vacuous', () => {
// `unaccounted === []` also passes when the scan finds nothing, so a scan that
@@ -131,6 +168,30 @@ describe('trusted rebuild allowlist', () => {
expect(hooked.size).toBeGreaterThanOrEqual(3);
});
+ // The lockfile-driven twin of the test below. This one runs in EVERY CI job for
+ // EVERY workspace, installed or not, which is what closes the silent-skip hole.
+ it.each(WORKSPACES)('%s: every lockfile-declared install hook is accounted for', (label) => {
+ const declared = lockfileInstallScriptPackages(label);
+ if (declared === null) return; // no lockfile (browser/ has no dependencies)
+ const allowed = new Set([
+ ...(TRUSTED_REBUILDS[label] ?? []).flatMap((group) => group.pkgs),
+ ...(DELIBERATELY_UNBUILT[label] ?? [])
+ ]);
+ const unaccounted = [...declared].filter((name) => !allowed.has(name));
+ expect(
+ unaccounted,
+ `${label}: package-lock.json marks these with hasInstallScript, but they are not in the allowlist in scripts/trusted-rebuilds.js. ignore-scripts=true blocks their build, so either add them (if the build is needed) or list them under DELIBERATELY_UNBUILT with the reason: ${unaccounted.join(', ')}`
+ ).toEqual([]);
+ });
+
+ it('reads install-script flags from the lockfile, so the check is not vacuous', () => {
+ // Same vacuity trap as below: an empty result passes. The server lock is known
+ // to flag node-pty, so a broken read fails loudly instead of looking clean.
+ const declared = lockfileInstallScriptPackages('server');
+ expect(declared).not.toBeNull();
+ expect(declared.has('node-pty'), 'server lockfile should mark node-pty hasInstallScript').toBe(true);
+ });
+
it.each(WORKSPACES)('%s: every installed package with an install hook is accounted for', (label) => {
const hooked = packagesWithInstallHooks(label);
if (hooked === null) return; // node_modules absent in this job
@@ -145,3 +206,67 @@ describe('trusted rebuild allowlist', () => {
).toEqual([]);
});
});
+
+// The fatal/non-fatal decision is the module's entire purpose: if it inverts or is
+// dropped, a failed node-pty build exits 0, `npm run setup` and the CI rebuild step
+// both report success, and the missing binding resurfaces much later as a confusing
+// MODULE_NOT_FOUND at smoke-boot. Assert the decision directly with an injected
+// spawner rather than only asserting the shape of TRUSTED_REBUILDS.
+describe('rebuildTrusted failure semantics', () => {
+ const failFor = (needle) => (_bin, args) => {
+ if (args.some((arg) => arg === needle)) throw new Error(`boom: ${needle}`);
+ };
+
+ it('spawns one npm rebuild per group, with the group\'s packages', () => {
+ const calls = [];
+ rebuildTrusted('/tmp', 'server', { spawn: (_bin, args) => calls.push(args) });
+ expect(calls).toEqual(TRUSTED_REBUILDS.server.map((group) => ['rebuild', ...group.pkgs]));
+ });
+
+ it('fails when a fatal group fails', () => {
+ expect(rebuildTrusted('/tmp', 'server', { spawn: failFor('node-pty') })).toBe(false);
+ });
+
+ it('still succeeds when only a non-fatal group fails', () => {
+ expect(rebuildTrusted('/tmp', 'server', { spawn: failFor('onnxruntime-node') })).toBe(true);
+ });
+
+ it('attempts every group even after one fails', () => {
+ const calls = [];
+ rebuildTrusted('/tmp', 'server', {
+ spawn: (_bin, args) => { calls.push(args); if (args.includes('node-pty')) throw new Error('boom'); }
+ });
+ expect(calls.length).toBe(TRUSTED_REBUILDS.server.length);
+ });
+
+ it('is a no-op for a workspace with no trusted rebuilds', () => {
+ const calls = [];
+ expect(rebuildTrusted('/tmp', 'client', { spawn: (...a) => calls.push(a) })).toBe(true);
+ expect(calls).toEqual([]);
+ });
+});
+
+describe('runCli exit codes', () => {
+ const noop = () => {};
+
+ it('exits 1 with usage when no label is given', () => {
+ expect(runCli([], { spawn: noop })).toBe(1);
+ });
+
+ it('exits 1 on an unknown label instead of reporting a green no-op', () => {
+ // The regression this guards: `sever` previously printed "✅ no trusted rebuilds
+ // needed" and exited 0, leaving node-pty unbuilt behind a passing CI step.
+ expect(runCli(['sever'], { spawn: noop })).toBe(1);
+ });
+
+ it('exits 0 for a real workspace that needs no rebuilds', () => {
+ expect(runCli(['browser'], { spawn: noop })).toBe(0);
+ });
+
+ it('exits 0 when every rebuild succeeds and 1 when a fatal one fails', () => {
+ expect(runCli(['server', '/tmp'], { spawn: noop })).toBe(0);
+ expect(runCli(['server', '/tmp'], {
+ spawn: (_bin, args) => { if (args.includes('node-pty')) throw new Error('boom'); }
+ })).toBe(1);
+ });
+});