Commit Graph
3 Commits
Author SHA1 Message Date
yetone 38a90a34ce plugins: a dist add failed by another package, unnamed in Bun's last lines, is done (CHENGJIAHEGOXIS on X)
On v0.1.4210 the reporter (Windows) still couldn't add
@magpie-community/tools-goanyapi from the dist branch:
"bun add ./dist/magpie-community-tools-goanyapi-0.1.1.tgz: exit status 1:
Saved lockfile installed @magpie-community/tools-goanyapi@./dist/... 1
package removed ... Failed to install 1 package". Bun had installed
goanyapi; another package failed, but the line naming it comes before
"Saved lockfile", and the error kept only the last six lines, so
othersFailed found no name and the add failed. The tgz is fine (sha512
matches the index, no dependencies); nothing changes in the plugins repo.

- bunSaid: every Bun error magpie shows (add, update, remove, the dist
  mend) keeps up to 8 failure lines from anywhere in the output before
  its last lines, ANSI and CRs stripped.
- bunFailed reads every way Bun 1.4.4's source (install/*.rs) names a
  failed package: failed to install/link <name>:, refusing to install
  dependency, extracting tarball from/for, downloading tarball <name>@,
  failed to download, Failed to open node_modules folder for, path for
  package.
- othersFailed: a failure naming no package is another's when the add's
  own package is in package.json and installed at the exact version asked
  for (the spec's exact version, or the one installDist read from the
  index; installDist now returns it). Its own package named still fails.
  This covers every plugin kind, provider plugins and tools alike, as all
  go through install().

Run:
- Old code (origin/main 5bd41301b with the new tests): all five new or
  changed tests red, TestUnnamedFailureDoesNotFailADistAdd with the
  reporter's message byte for byte.
- mote: go test -timeout 30m ./internal/plugin/... ok (174s);
  GOOS=windows go vet ./internal/plugin/ and GOOS=linux go vet -tags
  nogui ./internal/plugin/ ok; gofmt -l clean.
- xiaomi-gpu (Windows 11), real Bun 1.4.4, sandbox USERPROFILE/APPDATA/
  XDG_CONFIG_HOME, magpie.exe -tags nogui built from this tree:
  `magpie plugin add @magpie-community/tools-goanyapi` from a clean
  plugins folder installs 0.1.1 from dist with its 37 tools; with
  agency-agents installed and a file of it held open, the add drops
  agency-agents and installs goanyapi. That second shape passes on
  origin/main too (Bun's EBUSY line names agency-agents there).

Not tried: the reporter's exact hidden line, which their message cut
off; no shape I made on Windows hid the name. Publishing tools-goanyapi
to npm, which would skip the dist path, needs the owner.
2026-11-15 11:55:45 +08:00
yetone ab08a9e7c1 plugins: an add from the dist branch drops a leftover too (CHENGJIAHEGOXIS on X)
CHENGJIAHEGOXIS (Windows) still couldn't install GoAnyAPI from Plugins
after v0.1.4205's leftover fix:

  bun add @magpie-community/tools-goanyapi@latest: exit status 1: ...
  error: GET https://registry.npmjs.org/@magpie-community%2ftools-goanyapi - 404
  (and from the community repo's dist branch: bun add
  ./dist/magpie-community-tools-goanyapi-0.1.1.tgz: exit status 1:
  Unexpected: failed copying files from cache to destination for package
  agency-agents
  installed @magpie-community/tools-goanyapi@./dist/...-0.1.1.tgz
  Failed to install 2 packages)

GoAnyAPI isn't on npm (its first version waits for an owner's publish,
as 77 other community packages do), so the add goes to the dist branch.
ec97a4d7b's drop-and-retry ran only after the npm add, whose 404 names no
broken package; installDist's bun add had none. And the dist error was
wrapped with %v, so othersFailed read only the npm try's output and
failed an add whose own package had gone in ("installed ..."). The
"Unexpected:" wording was already matched by bunFailed.

Fix:
- bunAdd does the drop-and-retry itself (dropBroken, then once more), so
  every bun add has it: npm's and the dist tarball's (which keeps the
  package's name, its spec being a path).
- The dist error wraps both tries (%w), and failedOf reads every
  bunRunError in the tree, so othersFailed sees what Bun said from dist.
- depsState.undo loses its gone list: a dropped dependency isn't in
  package.json when undo reads it, so the list never changed anything.
- Fake bun: MAGPIE_FAKE_BUN_NPM404 (Bun 1.4.4's 404, nothing written),
  ./dist/*.tgz adds, MAGPIE_FAKE_BUN_BUSY_SAYS (the reporter's literal
  Bun output).
- docs/subsystems/provider-plugins.md says so.

Tests: TestLeftoverDoesNotFailADistAdd, TestAnotherPluginsFailureDoes
NotFailADistAdd (reporter's bytes), TestBunFailed (+ the literal output,
LF and CRLF).

Run:
- Both new tests red on origin/main's store.go/leftover.go/dist.go
  (the reporter's error, word for word), green with the fix (mote).
- mica-run at this tree: go vet ./internal/plugin/...,
  GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet ./...,
  go build ./..., GOOS=linux go build -tags nogui, GOOS=windows go build:
  ok; go test ./internal/plugin/...: ok (150s).
- win-run go test ./internal/plugin/: only TestPiPackage red (fixture
  spawns `sh`), the same alone at origin/main 6256d9956; filed in #4115.
- mote-run go test -tags nogui -timeout 45m ./... at this tree (base
  6256d9956): 100 packages ok, internal/gateway red on
  TestKeyLimitReservationsStayInTheirWindow account/* only, red alone at
  6256d9956 too: filed #6706.
- gofmt -l: nothing.

Not tried: a real Windows bun with a held agency-agents copy (the
reporter's machine state); npm side needs an owner (no NPM_TOKEN secret,
trusted publishing can't create a package).
2026-11-15 04:36:29 +08:00
yetone ec97a4d7bb plugins: a dependency no plugin needs no longer fails another's install
CHENGJIAHEGOXIS on X (v0.1.4178, Windows) couldn't install GoAnyAPI from
Plugins: "agency-agents" failed with 从缓存复制到目标目录失败, and it was
on no plugin's row, so nothing could remove it.

Cause: every bun add/update/remove installs every dependency in
plugins/package.json again, and a failed `bun add` writes its package
there before exiting 1. agency-agents (a repository with no
package.json) was left by such an add; on Windows a file of its copy in
node_modules is held open, Bun fails "EBUSY: failed copying files from
cache to destination for package agency-agents", and so every later
install failed over a package nothing used.

Fix (internal/plugin/leftover.go, store.go):
- A package Bun says it couldn't install that no plugin is installed as
  (on the list, on or off, an add in flight, pi's agent) is taken out of
  package.json and node_modules and the command runs again: install()
  and runBun, so add, update, check and remove all get it.
- A failed install puts back the dependencies and bun.lock it found.
- An add whose own package went in while another listed plugin's
  failed succeeds; that plugin keeps its dependency.
- Remove and add's clean-ups drop the dependency by hand when
  bun remove fails.
- What is left from before is listed under Installed as "Not used by
  any plugin", each with a Remove (/api/plugins leftovers,
  POST /api/plugins/leftover; pmLeftovers in plugininstalled.js,
  imported when Plugins first draws), in every language.
- plugins.json there and unreadable: nothing is a leftover.
- Core script budget +51 for the one call left in plugins.js (reason in
  core_budget_test.go).

Run:
- mote-run: go vet ./..., GOOS=linux go vet -tags nogui ./...,
  GOOS=windows go vet ./...: ok. go test ./internal/plugin (169s) and
  ./internal/provider (148s): ok.
- mica-run go test -count=1 ./internal/gui with the leftovers drawing
  moved into plugininstalled.js: ok (133s); main since touches none of
  internal/gui's core scripts, internal/plugin or plugins.go.
- win-run go test -run 'Leftover|FailedAdd|AnotherPlugin|RemoveTakes|
  BunFailed' ./internal/plugin on xiaomi-gpu: ok.
- Reproduced the EBUSY with Bun 1.4.2 on xiaomi-gpu (a file in
  node_modules/agency-agents held open, then bun add another package).
- Red on the old store.go: TestLeftoverDoesNotFailAnotherAdd,
  TestFailedAddLeavesNoDependency, TestAnotherPluginsFailureDoesNotFailAdd,
  TestRemoveTakesDependencyOutWhenBunFails.
- GUI: plugin-leftover.test.cjs 42/42 (chromium + webkit, en zh zh-TW
  ja de, 980/420px, with and without a plugin); old plugins.js: 21/21
  chromium red.
- mote-run, rebased on fdf42299e: plugin-leftover + i18n-keys 46/46;
  every other plugin*.test.cjs, old-webkit and i18n-en-no-cjk: 255 ok,
  reds only in old-webkit (#6030, #5919), plugin-move-unserved (#4392),
  plugin-option-placement (#6559) and plugin-page-foreign-error
  (#6117), each red the same on a clean origin/main fdf42299e checkout.

Not run: the full go test ./... and the whole GUI suite (mote over
its cores, mica running another session's full suite; one per machine); a real Windows
install through the magpie app.
2026-11-15 03:07:38 +08:00