Skip to content

fix(app): stage the CLI closure without anchoring on the checkout's absolute path (UUID-safe) - #1473

Merged
iamtoruk merged 3 commits into
getagentseal:mainfrom
ozymandiashh:fix/1466-stage-cli-uuid-path
Sep 18, 2026
Merged

iamtoruk merged 3 commits into
getagentseal:mainfrom
ozymandiashh:fix/1466-stage-cli-uuid-path

Conversation

@ozymandiashh

Copy link
Copy Markdown
Collaborator

Fixes #1466.

app/scripts/stage-cli.mjs resolved the CLI's production dependency closure by matching each npm ls --parseable line against the checkout's absolute <root>/node_modules/ prefix. npm 12 redacts UUID-shaped path segments to *** in that output, so on any checkout under a UUID directory (CI runners, scratch worktrees) the match found nothing and packaging aborted with the misleading "is the root npm installed?".

The fix

The top-level package name is now read by position: after the N-th /node_modules occurrence in the line, where N is counted off the real (unredacted) root path. The redaction renames segments but cannot move an occurrence, so redacted shapes resolve exactly like plain ones. The extraction lives in a new pure module app/scripts/stage-cli-packages.mjs with a .d.mts declaration, following the existing windows-installer-paths.mjs/.d.mts precedent, unit-tested under the app vitest gate (scripts/**/*.test.ts).

Kept from the old behaviour and pinned by tests:

  • a nested transitive path (.../node_modules/react-dom/node_modules/scheduler) still maps to its top-level ancestor (react-dom), which is what the stage copies;
  • a checkout that itself lives inside a node_modules directory resolves one segment deeper (a naive first-occurrence parser would read the checkout's directory name off every line);
  • Windows separators normalize on both the lines and the root path.

Two adjacent hardenings in the same script: a missing npm_execpath now fails with its own message instead of degrading into the empty-closure one (the try/catch that exists so a non-zero npm ls exit still yields its stdout was also swallowing it), and a truncated line ending in a bare @scope is refused rather than copied as the whole scope directory.

Proof

  • Genuine npm 12 output, reproduced: checkout at /tmp/1a2b3c4d-1111-2222-3333-444455556666/probe-29473 — [email protected] ls --omit=dev --all --parseable prints /private/tmp/***/probe-29473/node_modules/lodash. Fed that literal output to old vs new: the absolute-prefix match finds 0 packages, the position-based extractor finds lodash.
  • End-to-end: npm --prefix app run stage-cli on this repo (non-UUID path): builds the CLI, stages 160 production packages, and the Electron launch smoke (models --help + a full serve ready frame) passes.
  • Unit: app/scripts/stage-cli-packages.test.ts, 6 tests — the literal redacted npm-12 shape, the nested-checkout shape, transitive→ancestor mapping, Windows separators, root-line/blank/bare-scope skipping. Runs under cd app && npm test (scripts/**/*.test.ts in app/vitest.config.ts), same gate as verify-windows-installer.test.ts.
  • tsc --noEmit -p app/tsconfig.json clean.

…heckout's absolute path

npm 12 redacts UUID-shaped path segments to *** in npm ls --parseable
output, so the absolute <root>/node_modules/ prefix match staged an
empty closure on any checkout under a UUID directory (CI runners,
scratch worktrees) and packaging aborted with the misleading
'is the root npm installed?' (getagentseal#1466).

The top-level package name is now read by position - after the N-th
/node_modules occurrence, where N is counted off the real root path the
redaction cannot move - extracted into a pure, unit-tested module
following the windows-installer-paths .mjs/.d.mts precedent. Nested
transitive paths still map to their top-level ancestor, a checkout that
itself lives inside a node_modules directory resolves one segment
deeper, Windows separators normalize on both sides, and a bare
truncated scope is refused rather than copied whole.

Also stop swallowing a missing npm_execpath into the empty-closure
message: it now fails with its own instruction.

Verified against genuine npm 12.0.2 output from a UUID-path checkout
(new logic resolves the package, the old prefix match finds none), by
the new fixture suite, and by a full end-to-end npm run stage-cli
(160 packages staged, Electron launch smoke green).
@ozymandiashh
ozymandiashh force-pushed the fix/1466-stage-cli-uuid-path branch from 098c0b4 to 4ca4ee7 Compare September 18, 2026 11:43
…pm version

The two hand-rolled scanners do what split('/node_modules/') already does.
npm 11.19.0 redacts UUID segments too, so the npm 12 attribution was wrong.
@iamtoruk
iamtoruk merged commit 0f5a334 into getagentseal:main Sep 18, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Desktop packaging aborts when the checkout path contains a UUID segment

2 participants