Commit Graph
2 Commits
Author SHA1 Message Date
yetone 75ab21af4d plugin: a test binary takes no Bun from PATH (#6761, #6764)
TestRemoveListedAccountLeavesHiddenNamesake went red in every
whole-package run of internal/provider since 30de93e9e, on CI (ubuntu,
e99307fb8) and on mote, and passed alone.

The cause: 30de93e9e falls back on a Bun from PATH (or ~/.bun/bin) when
the download fails. A test's sandbox has no Bun, and testenv refuses the
download, so TestPluginEmptyKeyKeyAsked now copied the developer's or
CI's own Bun in and started a real plugin host, which nothing ended.
plugin.SignOut goes to the running host when there is one, so the later
test's ForgetLogin signed out in that host's HOME and its own
plugin-auth.json kept zcode#l47q19. Logging plugin.Running() in the test
showed true; the log shows "running plugins on Bun 1.4.2 from
~/.bun/bin/bun" in TestPluginEmptyKeyKeyAsked just before.

Now pathBuns is empty in a test binary testenv isolated
(MAGPIE_TEST_SANDBOX), as before 30de93e9e every test that asks a plugin
without MAGPIE_BUN got no host. TestBunOnPathAfterDownloadFailed sets
pathBuns itself, and BunReleaseForTest already emptied it. A real magpie
never has the marker.

Run on mote:
- before (9bcdcfb7d): go test ./internal/provider -count=1, red 2 of 2
  with "the account removed is still signed in" and running=true;
- after: go vet ./internal/plugin; go test ./internal/provider
  ./internal/plugin -count=1: ok (155s, 173s); gofmt -l clean.

Not run: the full ./... suite, and Windows/Linux; the change is one
early return under a test-only variable.
2026-11-15 22:38:49 +08:00
yetone 30de93e9e9 plugins: a request whose Bun is still downloading fails at once and fails over (#6735)
hixonchan (kyrierekkok123-del on GitHub): with magpie's own Bun missing
and its download stalled, every plugin-served request hung with zero
bytes, nothing in the log, no timeout and no failover, and `magpie
plugin` hung too. The host's lock (hostMu) was held across Bun's
download, which had no bound on the whole, so every caller waited on it
whatever its context said.

Now:
- Bun is downloaded in the background, once at a time per Bun
  (bunready.go). The host waits for it up to 10s from when it began
  (bunReadyWait); then each call ends with BunNotReadyError, "Bun
  runtime not ready: downloading Bun 1.4.2 (12s so far)…" or "… failed:
  <why>", logged, and the gateway goes on to the group's next member.
- A failed download is said at once for a minute, then tried again;
  installs (plugin.Bun) still wait as long as their context lets.
- hostMu is a channel lock that a caller's context can end (LockCtx);
  the gateway's TryLock polling loops use it.
- When the download fails, a Bun on PATH or in ~/.bun/bin is taken if
  magpie would run it itself: at least BunVersion, not set aside, passing
  the try a new release gets. It is copied in as magpie-bun (#1048).
  magpie's checksummed build stays first; the user's own Bun is better
  than no plugins, and it is what the reporter fell back on by hand.
- Each stage is logged: download started, failed after N, downloaded in
  N, the PATH Bun taken or refused and why.
- Every route through the host gets it: fetch, loader options, sign-in,
  the plugin listing (CLI and GUI). `magpie plugin` prints the list and
  the not-ready reason within ~10s.

Self-restart and env (the reporter's point 4): Reexec, RelaunchBinary and
StartBeside pass os.Environ; only the Mac's bundle relaunch (open -n)
starts with LaunchServices' env. Filed as #6757, not changed here. With
this change MAGPIE_BUN isn't needed.

Tests (each red on the old code with a shim for the new test hooks, logs
kept):
- TestHostWhileBunDownloadStalls: old code, "a caller whose context
  ended still waits on the stalled Bun download"; now not-ready at 2s,
  the 100ms caller returns, then the host starts on the download, asked
  once.
- TestHostAfterBunDownloadFailedSaysWhy: old code, a plain 500 error,
  not BunNotReady; now the 500 is said twice with one ask, Bun() retries.
- TestBunOnPathAfterDownloadFailed: old code failed; now 1.4.2 taken,
  1.0.0 refused.
- TestPluginWhoseBunIsNotReadyFailsOver (gateway, real Handler): old
  code, "group/mixed still unanswered after 20s"; now 200 from the next
  member in 0.84s, and the plugin's own model answers 502 "Bun runtime
  not ready" after ~300ms.

Run on mote at 923cc8747 + this commit (rebased since onto d7cda856a,
a GUI-only library change): gofmt -l clean; go vet ./...,
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 -tags nogui -count=1 -timeout 45m ./...: every package ok
(plugin 219s, gateway 1001s) except two untouched by this change:
- internal/usage TestWholeKeptAcrossReset: red on origin/main d7cda856a
  too, 4 of 5 at -count=5 (#6760).
- internal/provider TestRemoveListedAccountLeavesHiddenNamesake: red
  once in the full run, 5 of 5 alone (#6761).
The four new tests pass on Linux (WSL magpie-desktop) and, the two that
run there, on Windows (xiaomi-gpu).

Not tried: a real magpie binary with a really blocked GitHub download
(the gateway test runs the real handler with a stalled release server),
and the Mac relaunch.
2026-11-15 21:26:33 +08:00