Commit Graph
2 Commits
Author SHA1 Message Date
yetone 96d1b93b23 plugin: a dist add is judged by the copy Bun leaves, tried again over a broken one
CHENGJIAHEGOXIS on X (Windows, Bun 1.4.4, after v0.1.4229) still couldn't
install @magpie-community/tools-goanyapi from the dist branch: "Unexpected:
failed copying files from cache to destination for package
@magpie-community/tools-goanyapi ... installed ... Failed to install 1
package". 38a90a34c only let a failure over *another* package pass; this one
names GoAnyAPI itself, so the add was refused, and nothing magpie did made
the next try different.

What Bun 1.4.4 does (reproduced, sandbox HOME, its source read in
src/install/PackageInstall.rs):
- A local tarball is installed from its install-cache entry
  <cache>/@T@sha512-<32 hex>@@@1, trusted whole once there. An entry
  missing a file gives a copy missing it, "1 package installed", exit 0
  (macOS on mote and Windows on xiaomi-gpu). Before this, magpie recorded
  that plugin as installed with no index.mjs.
- A copy it can't make still prints "installed", writes the dependency and
  exits 1: a file of the old copy held open without delete sharing on
  Windows gives the reporter's lines with EBUSY; a read-only folder on
  macOS gives EACCES. The reporter's "Unexpected" is a Win32 code Bun has
  no errno for; which one wasn't reproduced (antivirus, a cloud
  placeholder or a transient hold are the candidates).

Now addDist checks node_modules/<name> against the tarball installDist
verified, file by file (.bun-tag and other extras ignored). A copy that
differs is taken out together with Bun's cache entry and its scope link,
and after 2s (distAgainAfter) the add is tried once more. A whole copy is
the package in. One still not whole is errDistPartial, which install never
hands to othersFailed, so the dependency is put back and the plugin isn't
listed. The npm add has no tarball in hand and isn't judged this way.

The fake bun now copies a dist tarball through a modelled cache entry
(.held / MAGPIE_FAKE_BUN_HELD for a copy it can't make, MAGPIE_FAKE_BUN_LOSE
for a file that never arrives); both sandboxes pass BUN_INSTALL_CACHE_DIR.

Run:
- New tests red on the old dist.go/store.go (mote): TestDistAddOverABroken-
  CacheEntry (no index.js), TestDistAddOverAHeldCopy (the reporter's
  error), TestDistAddNeverRecordsAPartialCopy (exit 0 one returned nil).
- go test ./internal/plugin/... on mote at the pushed head (rebased on
  8bf9cb99d): ok 155s. gofmt -l clean; GOOS=windows go vet and GOOS=linux
  go vet -tags nogui of internal/plugin: ok.
- win-run go test ./internal/plugin/ (before the rebase): the new tests
  pass; TestStaleMissingIsUnknownWhileDistUnread (#5351, passes alone) and
  TestPiPackage (#4115, red alone on base dd89f1255 too) red.
- Real Bun 1.4.4, real goanyapi 0.1.1 tarball served as the dist branch,
  through AddExact (throwaway test, not committed): clean add, a cache
  entry with index.mjs taken out, and on Windows a file of the old copy
  held open for 3s (EBUSY, then the second try after the pause) each
  installed, and the plugin loaded under bun (its hooks return 37/50
  tools). A hold of 20s: add fails with Bun's EBUSY lines, GoAnyAPI not in
  package.json and not listed.
- All 105 dist packages' latest tarballs added with real Bun 1.4.4 on mote:
  every copy equals its tarball byte for byte (only .bun-tag besides), so
  the check refuses none of them.

Not tried: the reporter's own machine or its "Unexpected" code; the check
on npm adds (#6736).
2026-11-15 13:41:12 +08:00
1d8134605a plugin: a plugin pinned to a version, or turned off, keeps both throu… (#1076)
* plugin: a mover installs the version its user pinned, not @latest

plugin.Add installs the spec it is given and appends @latest to a bare
package name, so installPlugin — the mover's installer, for
keepMovedCurrent, Move and HandOver — handing it a bare name quietly
replaced <pkg>@1.2.3 with <pkg>@latest in plugins.json. The pin was the
user's choice, and it was destroyed behind their back every time the
mover's min was raised.

installPlugin now hands Add the entry's own spec when the user has one.
A pin older than the move needs is left pinned and reported by the check
that was already there below it ("%s %s is installed; moving needs %s
or newer"), whose remedy is to unpin it; a pin that satisfies min still
returns early and is not reinstalled. A user with no entry for the
package keeps the bare name, which is a first install and there is no
pin to keep. A plugin the user turned off is still refused before any of
this, as it was.

TestInstallPluginKeepsTheUsersPin pins fake@0.1.5 with the move needing
0.2.0 and writes the version plugin.Version reads into the plugins folder
it is read from. It asks Add for fake@0.1.5 — against installPlugin as it
handed over the bare name it fails with "asked Add for [fake], want the
pinned fake@0.1.5" — and gets "needs 0.2.0 or newer" back rather than a
silent install of @latest. It also checks that a plugin the user turned
off is refused and not asked for at all. addPlugin is a var beside
pluginProviders and removePlugin so the test can read the spec handed
over without the Bun that Add runs.

Rebased on main as of 1b8cb53e. Note that main's installPlugin has since
learned to route an unpinned npm entry through plugin.Upgrade (for bun's
minimumReleaseAge, 4b56c867); this branch keeps the user's own spec for
an entry that exists, which is what a pin needs, and leaves the bare
name — the Upgrade route — to a first install.

Verified: go test ./internal/provider (2.9s, TestReleasePlugin and
TestMovedSignInAsBuiltIn skip: no bun on PATH); go vet on windows/amd64,
darwin/arm64 and linux/amd64 (-tags nogui) for both packages; gofmt -l
on an LF-normalized copy of the tree. No live plugin was installed and no
npm registry was reached.

* plugin: a plugin the user turned off stays off through every install path

add rebuilds an existing entry as Entry{Spec: spec} and keeps only its
options, so Off was lost: a plugin the user turned off came back on with
the next Add, Update, Update all or Upgrade, each of which goes through
add for an npm package. add now keeps Off too, as it keeps Options.

The fake bun the git plugin's test has the test binary stand in with
learned an npm spec (node_modules/<name> at the version the spec names,
with a file to load), so the tests really wrote plugins.json through add.
TestAddKeepsAnOffPluginOff, TestUpdateKeepsAnOffPluginOff and
TestUpgradeKeepsAnOffPluginOff each fail without the change — "after
Upgrade: [{Spec:... Off:false}], want the plugin still off" — and pass
with it. bunCommand is stubbed rather than $MAGPIE_BUN set, as the git
plugin's test does it: the env a test sets reaches the package's other
tests only through what they read, and $MAGPIE_BUN set here made
TestLoadConcurrentWithSavesAndEdits' Add run this binary too.

docs/subsystems/provider-plugins.md says which path does what: Update and
Update all install npm's newest and unpin a pin (ba0e2a8a), while
keepMovedCurrent installs the spec the user already chose.

Verified: go test ./internal/plugin (1.9s for the new tests; the full
package passes, with TestLoadConcurrentWithSavesAndEdits flaky on
Windows on main too — its rename of plugins.json loses to "Access is
denied" now and then, seen on a clean main checkout) and
./internal/provider (2.9s, TestReleasePlugin and TestMovedSignInAsBuiltIn
skip: no bun on PATH); go vet on windows/amd64, darwin/arm64 and
linux/amd64 (-tags nogui) for both packages; gofmt -l on an
LF-normalized copy of the tree.

* provider: a move leaves a pin, and an unpinned plugin still goes to npm's newest

installPlugin handed Add the entry's own spec, so an unpinned plugin
(pkg@latest) below a mover's min went to bun's @latest instead of
plugin.Upgrade. Under a bunfig minimumReleaseAge that silently installs an
older version and the move stays stuck: the sweanng424 fix (4b56c8672)
undone. Now:
- a pinned npm version below min is not reinstalled; the move says it is
  pinned and which version it needs (the pin is the user's own choice);
- an unpinned npm entry goes through Upgrade, as on main;
- a git entry is reinstalled from its own spec, not swapped for npm's.

The docs paragraph now says the same.

Run: go test -tags nogui -run TestInstallPlugin ./internal/provider (green);
with the Upgrade branch disabled it goes red on the unpinned case, and with
the Pinned check removed it goes red on the pinned case.

---------

Co-authored-by: TryWorld <TryWorld2026@users.noreply.github.com>
Co-authored-by: yetone <yetoneful@gmail.com>
2026-10-13 09:47:51 +08:00