Repository navigation
fix(cli): add lists files from a received config's registry as received - #7820
Conversation
When a project's hyperframes.json is listed in .hyperframes/received-files.json and names a registry other than the public one, add now lists every file it is about to write in that record before writing any of them. This covers every caller of addToProject: add by name, by tag, several names, and Studio. The decision reads the config the install uses, so a byte-order mark or another spelling of the file on disk is handled the same way. A person's own config, the public registry and a record that cannot be read are left as they are.
add now lists each file in the received-files record just before it writes it, using the write-time decision, so a file kept because the person edited it during the download is never listed. When an install fails, it takes back the entries it listed but never wrote. Changes to the record take .hyperframes/received-files.json.lock, created exclusively. A writer retries for about 2 s, takes over a lock older than about 10 s, and always releases it. A writer that cannot take the lock in time fails with a clear error instead of writing past it.
…eeps what is on disk add now counts an install as received when hyperframes.json exists but cannot be read or parsed, since that config is not proven to be the person's own. When an install fails, it takes back only the entries it listed whose files are not on disk; files that landed stay listed.
jrusso1020
left a comment
There was a problem hiding this comment.
APPROVE. Reviewed at 1eaabba240720ab8a2117f6f4e3c58fd2330c742.
Need: yes, a received config's own registry installed files that counted as the person's own · Size: ok (+430/-10, 8 files, about 70% tests) · Reuse: uses the existing receivedFiles() identity matching, readProjectConfigWithStatus, publishRegistryFile and registryTargetPath · Simpler: already minimal · Structure: fine (checked: the record has one writer, changeReceivedRecord; no split)
Risk: medium — new cross-process lock on a file the desktop app writes too
What I checked
- Where the decision is made.
addToProjectcallsfromReceivedRegistry(projectDir, config.registry), and every install path goes through it: by name, by tag (add <tag>re-enters per item), several names, and Studio (studioServer.ts:888). The decision is made before any file is written.- A config that exists but can't be read or parsed counts as received.
- A BOM is stripped (
readProjectConfigWithStatus). - The config is matched by
dev:inoidentity as well as by name.
- Public-registry test.
isPublicRegistryparses with the sameURLparser thatregistryPathUrl/fetchRegistryHttpsuse to fetch, so both read the registry the same way..., a query, credentials and a lookalike host are all treated as not public. - Order of record and write. Each file is added to the record before it is written (
guardWrite). A lock failure therefore throws before that file lands, so a file is never written without being listed.undo()takes back only entries whose files are not on disk. Files kept as the person's edits havebytes === null, so they are never listed. - Lock. It is
.hyperframes/received-files.json.lock, created with an exclusive create, waited on for about 2 s, taken over once older than about 10 s, and always released. I compared this with the desktop app's writer: the path, the 2 s wait, the 10 s stale rule and the{ files: [...sorted] }format all match.
Evidence
vitest run src/commands/add.test.ts src/utils/privateProjectFile.test.ts src/registry/remote.test.tsat head: 3 files, 101 passed. (The body says 210; I counted the same three files.)- With only the source reverted to the merge base (
add.ts,installer.ts,index.ts,remote.ts,privateProjectFile.ts) and the tests kept: 20 failed. That covers the lock wait, stale takeover, held-lock failure, the received install (dependencies, tag, publish exclusion), BOM, other spelling, unparseable config, failed install, and everyisPublicRegistrycase.
Nits (non-blocking)
- Stale-lock takeover can let two writers in. In
takeRecordLock, two waiters can bothstatthe old lock, and both thenrmSyncit. The secondrmSynccan delete the lock the first waiter has just created. Thefinallyblock has the same problem: a writer whose lock was taken over removes the new owner's lock. Each change holds the lock only for milliseconds, so this needs a 10 s stall to matter. A cheap fix is to remember the lock'sinoandmtimeMswhen you stat it, and remove it only if they still match. - The wait blocks the event loop.
sleepSyncusesAtomics.wait, which blocks the thread for up to 2 s. That is fine for the CLI, butaddToProjectalso runs inside the Studio server, where it stalls every request while it waits. That is acceptable at this hold time; just mention it in a comment. - The two public-registry checks differ. The desktop app's version of this decision also requires every path segment to be plain
[\w.-]+. This one accepts any path under the public prefix. I found no real difference in what the public host serves, but making the two rules identical would keep the CLI and the app from ever disagreeing. - Identity matching gives up on
ino === 0. This is in the existingfileIdentity. On a filesystem that reports no inode numbers, a config listed under another spelling is not matched, so it counts as the person's own. A fail-closed alternative is to read the project root and compare the config's actual on-disk spelling with the record. This was already true on the base, so it can be a follow-up.
Overlap: hf#7792 also changes utils/privateProjectFile.ts, but in a different region (after receivedFiles). I expect a clean merge, but whichever PR lands second should re-run this suite.
— Rames
Edit accuracy: accurate 267 (base branch 267), smooth 100 of thoseThe gate passes. Quarantined, measured but not gated (8)
Unstable (1)
|
…installer does The record's lock and write resolved the project folder with fs.realpathSync, while the containment check resolves targets with the native realpath. The two can spell the same folder differently: a Windows short name or a folder typed in another letter case. The target then looked outside the project and the change was refused. The record now resolves the folder with the installer's realProjectRoot, so the root and target compare in one spelling. The failed-install tests now fail the write by stubbing it, which works on every platform, instead of a read-only folder, which Windows ignores.
jrusso1020
left a comment
There was a problem hiding this comment.
Reviewed at f91ff5b0a96f589345f3d373beee3948d91948e6, including the complete delta from 1eaabba240720ab8a2117f6f4e3c58fd2330c742.
The delta contains one production adjustment: receipt writing now resolves its root through the installer's existing registryRoot/realProjectRoot. The other changes replace platform-dependent read-only-directory failure fixtures with selective publication failures and add a path-spelling regression.
The shared resolver uses the native canonical path, with the existing EISDIR fallback. A root alias resolves to the same physical project as installation; receipt-publication and lock targets still pass the unchanged physical containment checks. This does not permit an outside descendant merely because the root was respelled. The lock contract is unchanged: .hyperframes/received-files.json.lock, exclusive wx, approximately two seconds of retries, stale takeover strictly after ten seconds and release in finally. Compared with the matching app writer's contract.
The failure fixtures still execute real receipt changes and fail the intended content publication: rollback removes never-written entries while retaining entries for files already written. The earlier stale-lock ownership, synchronous-wait and registry-policy/zero-file-ID follow-ups are unchanged. End-user availability still requires publishing the CLI release and updating consumers.
Validation: frozen install/full bun run build passed. Through the shared test gate, bun run --cwd packages/cli test src/commands/add.test.ts src/utils/privateProjectFile.test.ts src/registry/remote.test.ts src/registry/publication.test.ts src/utils/review7820.test.ts --maxWorkers=1: 112 passed (109 committed tests and 3 temporary controls). The temporary controls cover an injected difference between legacy/native root spellings, two aliases updating the same physical receipt, and rejection of outside receipt-folder/leaf writes. Restoring only the previous root resolver makes the spelling control fail; restoring this head gives 3/3 passes.
The new committed case-spelling test uses alternate case only on a case-insensitive filesystem; it falls back to the original spelling on this Linux machine. The injected resolver mismatch is not a native Windows short-name or junction run. Windows engine/CLI CI was still in progress when checked at this head. No live registry install, dev deployment or end-to-end upload/render was performed.
Need: yes · Size: focused compatibility fix · Reuse: installer's canonical root and existing guarded publication · Simpler: one shared root resolver · Structure: fine (checked root resolution, descendant containment, lock and failure fixtures; no split)
Risk: medium — receipt persistence and cross-process locking across platform-specific paths.
Verdict: APPROVE
Reasoning: Receipt locking now uses the same physical root as installation without relaxing the descendant-path checks.
— Rames
What
hyperframes addlists the files it installs as received when the project'shyperframes.jsonis itself a received file and names a registry other than the public one. Writes to the received-files record are now serialized across processes.Why
A received project can name its own registry. Before this change, files that
addinstalled from that registry counted as the person's own. So publish, cloud render and feedback uploads would collect outside-project files those files reference. The record already covers the project's received files. This extends it to what a received config pulls in later.A person's own config, and the public registry, record nothing, so normal use is unchanged.
Related work
Refs #7771 and #7808 (the received-files record and nested records). A matching change in the desktop app records installs that the app runs.
How
commands/add.ts: decides provenance from the config the install actually reads. A byte-order mark is stripped, and the record entry is matched by file identity, so a differently spelled config on a case-insensitive disk is found. A config that exists but can't be read or parsed counts as received.utils/privateProjectFile.ts: changes to the record take.hyperframes/received-files.json.lock, created exclusively. A writer retries for about 2 s and takes over a lock older than about 10 s. It always releases the lock. A writer that can't get the lock in time fails with a clear error instead of writing past it.addToProjectcaller: add by name, by tag, several names, and Studio.One tradeoff: with an unreadable config, files from the public registry are listed as received too. The only effect is that a publish leaves out outside files those catalog blocks reference.
Test plan
Unit tests added/updated
Manual testing performed
Documentation updated (if applicable)
Comments follow CONTRIBUTING.md "Comments": they say why, not what, and a bug fix says what the code must do and how to reproduce the bug
CLI vitest on the touched suites (
add,privateProjectFile,remote): 210 pass. Typecheck, oxlint, oxfmt, the comment ratchet and fallow pass.These new tests fail on
main:A separate review checked that the record's path and format match what the app and the CLI read.
Not run: an end-to-end install against a live non-public registry.