Skip to content

fix(registry): pick another version when the locked one left the registry, and refuse links - #380

Merged
Exeloo merged 5 commits into
mainfrom
fix/registry-safety
Nov 29, 2026
Merged

Exeloo merged 5 commits into
mainfrom
fix/registry-safety

Conversation

@Exeloo

@Exeloo Exeloo commented Nov 29, 2026 •

Copy link
Copy Markdown
Member

What does this PR do?

Closes NanoForge-dev/Editor#254
Refs NanoForge-dev/Editor#248

Two fixes in @nanoforge-dev/registry (libs/registry):

  • A locked version missing from the registry breaks every package operation Editor#254, a locked version that left the registry: every package operation failed with a TypeError on versions.find(...)!. The lock is now kept only when the registry still has that version; otherwise the newest version that fits is taken. A missing entry throws a RegistryError (NOT_FOUND) naming the package and version.
  • Links in the project (A symlink in nf_modules lets Restore packages delete files outside the project Editor#248, lib side): restore, install, update and uninstall no longer follow links out of the project. Before any change they refuse, with a RegistryError (INVALID), a symbolic link or junction as nf_modules, one of its scopes or entries, nanoforge.packages.json, nanoforge.packages.lock.json or tsconfig.json.
    • assertNoLinks / assertNotLink (modules-folder.ts) run at the start of restore(), in _apply before any write or removal, and in the read helpers of the list, the lock and tsconfig.json.
    • writeAtomically creates its temporary file exclusively (wx), and the rollback of the list and the lock writes them atomically too.
  • Docs: docs/docs/commands/install.mdx says nf install refuses these links.

The editor's own checks (NanoForge-dev/Editor fix/registry-trust-gate (NanoForge-dev/Editor#386)) are what settle NanoForge-dev/Editor#248, because the editor still ships registry 3.0.1. This PR is the lib side of it.

How do you test this PR?

Test (libs/registry/test/registry.spec.ts) Before After
"keeps working when a locked version left the registry, and names a missing one" TypeError: Cannot read properties of undefined (reading 'sha256') passes
linked scope on restore, linked nf_modules on restore, linked scope on install, linked package folder (4 tests) promise resolved instead of rejecting refused with INVALID
"refuses a linked tsconfig.json, list or lock, and reads or writes none of them" promise resolved instead of rejecting refused, nothing outside read or written

First run: 5 failed, 10 passed before the fix. Registry lib on the final code: 58 passed, 0 skipped. The links are made as junctions so the folder tests also run on Windows CI without symlink rights; the linked tsconfig.json case needs a file symlink (not checked on a Windows runner).

Commands run from the worktree: pnpm repo:build, pnpm repo:lint, pnpm repo:test:unit, pnpm build, pnpm lint, pnpm test:unit (345 passed): all pass. After the last docs commit (0ea19b2): pnpm lint, pnpm repo:lint.

Merge danger

Follow-up issues

Quality gate

Lane Result HEAD covered
Docs Updated: docs/docs/commands/install.mdx (250a11b, 0ea19b2) 0ea19b2
Correctness Pass ("mergeable") da10d78
Performance Not recorded -
Accessibility N/A: no UI, only new error messages -
Security Round 1 re-review: minors (reads through a link, wx, the rollback write), fixed in f78acb3 250a11b
Style Pass (covered by the correctness reviewer) da10d78

Last round f78acb3 and 0ea19b2: producer red→green, not re-reviewed.

…stry

A locked version the registry no longer has made every package
operation fail with a TypeError on `versions.find(...)!`. The lock is
now kept only when the registry still has that version, otherwise the
newest version that fits is taken, and a missing entry throws a
RegistryError naming the package and version.

Closes NanoForge-dev/Editor#254
A linked nf_modules, scope or package folder made restore remove, and
install write, files outside the project: a cloned project could link
nf_modules/@evil to the user's home and have restore empty it. Restore
and every install, update and uninstall now lstat nf_modules, its
scopes and their entries first, and refuse with a RegistryError
(INVALID) when one is a link or junction.

Refs NanoForge-dev/Editor#248
…ugh it

Install and restore wrote the paths of the packages with a plain
writeFile, which follows a linked tsconfig.json out of the project. It
is now written like the list and the lock: a temporary file renamed
over it, which replaces the link. The unreachable NOT_FOUND guard on a
missing registry entry gets a note, and the install docs say nf_modules
links are refused.

Refs NanoForge-dev/Editor#248
The list, the lock and tsconfig.json were read through a symbolic
link, which copies JSON from outside the project into it. They are now
refused like the links in nf_modules. writeAtomically creates its
temporary file exclusively (wx), and the rollback of the list and the
lock writes them atomically too, never through a link.

Refs NanoForge-dev/Editor#248
@github-actions github-actions Bot added documentation Improvements or additions to documentation lib:registry Related to the @nanoforge-dev/registry library labels Nov 29, 2026
@Exeloo
Exeloo merged commit e636a0b into main Nov 29, 2026
9 of 11 checks passed
@Exeloo
Exeloo deleted the fix/registry-safety branch November 29, 2026 11:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation lib:registry Related to the @nanoforge-dev/registry library

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A locked version missing from the registry breaks every package operation

1 participant