feat(cli): add pi2 update with a versioned install layout

The standalone (curl installer) channel had no upgrade path of its own: the
documented one was 're-run the installer', which the Neovim plugin cannot do
safely and which re-downloads 35 MB without version arithmetic, provenance or
rollback. ADR 0003 records the design; this is the implementation.

- install.sh now installs one immutable tree per version
  (`<prefix>/versions/<v>/{bin,share,LICENSE}`) behind a single atomically
  swapped `current` symlink, writes `<prefix>/install.json` as the install
  receipt, and migrates a pre-0.1.7 flat layout in place. Keeping `current` plus
  one previous tree gives a one-step rollback for free.
- `pi2 update` (native TypeScript, no `curl | sh` subprocess) resolves the
  release with an ETag-cached GitHub lookup, picks the asset from the
  build-time `PI2_BUILD_TARGET` define instead of re-probing libc, verifies
  SHA256SUMS, verifies SLSA provenance with `gh attestation verify`, runs the
  new binary once, then swaps `current` and rewrites the receipt. Flags:
  --check/--dry-run/--version/--force/--json/--require-attestation/
  --skip-attestation. Downgrades need --force; restarts stay manual.
- the receipt is the only channel detection: npm, Homebrew and the AUR are
  refused with the command that owns their tree, and a flat install is told to
  re-run the installer once. No heuristics on `process.execPath`.
- `pi2 install-service` renders `<prefix>/current/bin/pi2`, so an update no
  longer invalidates the unit.
- `scripts/build-binary.sh` injects `PI2_BUILD_TARGET`; `tarball.ts` is a
  dependency-free ustar/PAX reader with traversal and symlink rejection.

Verified against the real release: install.sh into a scratch prefix, update
--check/--dry-run, a local 0.1.7 mirror upgrade (attestation warn path), then
`pi2 update --version 0.1.6 --force` (real download, real attestation
verified), plus boot-check and the refusal paths. typecheck + 567 daemon tests
+ web typecheck + 537 web tests + smoke are green.
This commit is contained in:
yuez committed 2026-10-29 16:42:57 +08:00
1 parent 29aee26733
commit 8fb535f7f3
20 files changed
+2557 -43

No files matched your search

+25
View File
@@ -70,6 +70,31 @@ only for a package that already exists, so the first publish is manual:
configuration expires.
3. Bump to a **higher** version for the first CI release — npm rejects republishing a version.
## Release assets (the curl channel)
`release.yml` also publishes six `pi2d-<version>-<target>.tar.gz` assets plus `SHA256SUMS` and
SLSA provenance (`actions/attest-build-provenance`), which `pi2 update` consumes. Two things to
know before debugging a missing asset:
- **Backfill an existing tag without re-publishing npm:**
`gh workflow run release.yml -f tag=v0.1.6` — `publish` and `packaging` are gated on
`github.event_name == 'push'`, so a dispatch run only rebuilds and re-attaches assets.
This is the repair path for "the release has no tarballs" (it happened to v0.1.6: the
`darwin-x64` leg sat queued on the retired `macos-13` image for 21 h and `checksums` never ran).
- **Runner labels matter more than the build.** `darwin-x64` needs `macos-15-intel` and
`darwin-arm64` needs `macos-15`; a retired or deprecated label leaves the leg queued forever
and the whole asset job blocked. Verify with
`gh api repos/zgs225/pi2d/actions/runs/<id>/jobs --jq '.jobs[] | "\(.name) \(.status)"'`.
Verify what actually landed, not that the run was green:
```bash
gh release view "v<x.y.z>" --repo zgs225/pi2d --json assets --jq '.assets[].name'
gh attestation verify pi2d-<x.y.z>-linux-x64.tar.gz --repo zgs225/pi2d
PI2_VERSION=<x.y.z> PI2_INSTALL_DIR=/tmp/pi2-check/lib PI2_BIN_DIR=/tmp/pi2-check/bin \
sh scripts/install.sh && sh scripts/boot-check.sh /tmp/pi2-check/bin/pi2 <x.y.z>
```
## Failure playbook
| Symptom | Cause / action |