tests: the root package's plugin tests run the bun on PATH once before their one-minute context, so a bun that has never run here doesn't time them out (ggbdpq, #1306)

TestAccountsOfAPlugin and the plugin login tests (fakeCoHome) point
MAGPIE_BUN at the bun found on PATH and do all their plugin work inside
a one-minute context. 7ddea2c2 kept macOS's first-exec check of the
copied magpie-bun out of that minute, but not the PATH bun's own: when
bun was just installed or upgraded, its check landed inside the minute
and the test failed with "starting plugins: context deadline exceeded".

Both now take their bun from pathBun, which looks it up as before and
runs `bun --version` once before the context opens. This is patch 1 from
ggbdpq's comment on #1306, with the warm-up in one helper beside
fakeCoHome instead of copied into both tests. Patch 2 (quota_served's
stand-ins) is left out: it only saves wall-clock time, and that test has
no deadline.

What was run (macOS arm64, bun 1.4.2):
- Red, old code: a wrapper bun first on PATH whose first exec sleeps
  61s (marker-gated, then execs the real bun). TestAccountsOfAPlugin:
  FAIL at 62.0s, "accounts_plugin_cli_test.go:38: starting plugins:
  context deadline exceeded". TestPluginLoginTakesTheLapseOff: FAIL at
  62.0s, "plugin_login_cli_test.go:46: starting plugins: context
  deadline exceeded".
- Green, this change, the same cold wrapper with a fresh marker:
  TestAccountsOfAPlugin PASS (65.2s), TestPluginLoginTakesTheLapseOff
  PASS (63.4s); the 61s is spent before the context opens.
- go test -tags nogui -count=1 . under a temp HOME with GOMODCACHE,
  GOCACHE and GOPATH pinned: ok (22.8s); with a warm bun the warm-up
  adds nothing noticeable.
- gofmt -l on both files: clean. go vet -tags nogui . for darwin,
  GOOS=linux and GOOS=windows: clean.

Not covered: the same shape (LookPath("bun") as MAGPIE_BUN, then a
one-minute context) is in internal/provider (pluginsignin_paste_test,
plugin_fetch_lapse_test, signin_removed_test) and internal/plugin
(plugin_test). Not run on a genuinely cold bun on a loaded machine; the
sleep stands in for the check.
This commit is contained in:
ggbdpq authored and yetone committed 2026-10-10 10:12:59 +08:00
1 parent e611fc65d6
commit 65dcc57369
2 files changed
+17 -9

No files matched your search

+1 -5
View File
@@ -3,7 +3,6 @@ package main
import (
"context"
"encoding/json"
"os/exec"
"path/filepath"
"strings"
"testing"
@@ -16,10 +15,7 @@ import (
// magpie accounts lists, switches and forgets a plugin's accounts by its
// provider's id, as a built-in subscription's.
func TestAccountsOfAPlugin(t *testing.T) {
bun, err := exec.LookPath("bun")
if err != nil {
t.Skip("no bun on PATH")
}
bun := pathBun(t)
home := t.TempDir()
t.Setenv("HOME", home)
t.Setenv("USERPROFILE", home)
+16 -4
View File
@@ -101,10 +101,7 @@ func TestPluginLoginReadsUsageAfresh(t *testing.T) {
// plugin (FakeCo) added, as TestAccountsOfAPlugin sets one up.
func fakeCoHome(t *testing.T) context.Context {
t.Helper()
bun, err := exec.LookPath("bun")
if err != nil {
t.Skip("no bun on PATH")
}
bun := pathBun(t)
home := t.TempDir()
t.Setenv("HOME", home)
t.Setenv("USERPROFILE", home)
@@ -125,6 +122,21 @@ func fakeCoHome(t *testing.T) context.Context {
return ctx
}
// pathBun is the bun on PATH, run once before the caller opens its
// one-minute context. A bun just installed or upgraded hasn't run on this
// machine yet, and macOS checks a program before its first exec, which can
// take tens of seconds on a busy machine: that check must not eat the
// minute the plugin calls have (ggbdpq, #1306; 7ddea2c2 for the copied bun).
func pathBun(t *testing.T) string {
t.Helper()
bun, err := exec.LookPath("bun")
if err != nil {
t.Skip("no bun on PATH")
}
exec.Command(bun, "--version").Run()
return bun
}
// noBrowser has the sign-in pages magpie opens go nowhere. It swaps the
// opener rather than putting a do-nothing open first on PATH: a script
// written now is a program macOS checks on its first run, which took 25 to