Commit Graph
3 Commits
Author SHA1 Message Date
yetone bde11c7780 plugin, cli tests: stay off the network, so a host start never waits 30s on the real models.dev (#1922)
What: internal/plugin's and internal/cli's TestMain now call
testenv.Offline, as gateway's and provider's already do, and each package
has TestStaysOffTheNetwork. TestPluginListSaysMiddleware runs on
testenv.Bun via MAGPIE_BUN like its siblings, instead of downloading
Bun 1.4.2 from GitHub on every run (the guard turned that up).

Why: every plugin test's sandbox is a new home with no models.dev
catalog, so startOn fetched the real https://models.dev/api.json, with a
30s cap, on each host start until one succeeded. When models.dev didn't
answer the macOS runner, a test that starts two hosts (Add, then Restart
or a list changed elsewhere) spent 30s + 30s; the second start reached
its init call with the test's one-minute ctx already gone: "starting
plugins: context deadline exceeded" at 60s, TestPluginsChangedElsewhere
at 90s. Ubuntu's runner got models.dev's answer in time.

What was run:
- Injected the delay on the old code: a DialContext that holds every
  non-loopback dial. TestFallenBackListKeepsTheLastOne/throws=,=1,=own
  60.1-60.4s, TestUnloadedPluginKeepsProviders 60.32s,
  TestPluginsChangedElsewhere 90.36s, each "starting plugins: context
  deadline exceeded" - CI's signature. With Offline on top of the same
  slow dial: all pass in 0.4-1.0s.
- TestStaysOffTheNetwork fails on the old TestMain ("models.dev answered
  200 OK"), passes with the change.
- 8 parallel -race processes x -count=6 of the three tests on the old
  code: all passed (models.dev answering here), so the delay, not load,
  is the cause.
- go test -tags nogui ./internal/plugin/... ./internal/cli/... pass;
  go vet (darwin, linux, windows), gofmt -l clean.

Not tried: on a macOS CI runner itself (the push's run is the check).
The product path is unchanged: a magpie whose models.dev fetch hangs
still waits up to 30s on each host start until one succeeds.
2026-10-13 13:02:58 +08:00
wei 920d96af55 tests: provider, plugin, gateway, codexcat, gui and tui tests pass in any order and on any -count (#1146)
Squashed from wei's #1146, onto main. Each test now starts from state of
its own instead of what an earlier test (or an earlier -count run) left:

- plugin: changed() counts the OnChange hooks still running; Told waits
  for them, and Settle ends with Told and UseCached(nil), so a change one
  test made isn't told in the next and the next test's plugin list isn't
  read as changed. Only tests call Settle/Told; in production changed()
  only counts. New TestSettleWaitsForTheHooksItTold and
  TestSettleForgetsTheFoldersPlugins.
- provider: isolate forgets Copilot's state, the plans' quota cards and
  balances; the warm-up, Cursor sign-in, hold and moved-plugin tests wait
  for what they started.
- gateway: fresh() forgets refused seals, and TestRouting,
  TestSmartRouting and TestQuotaRestsUntilItsReset start from
  forgetRouting; codexSignedIn and TestForeignReasoningIsLeftOut start
  from fresh.
- codexcat: XDG_CONFIG_HOME under the test's home. tui: costAt reset.
  gui: the fake Cursor account no longer outlives its test. cli: Settle.

Left out as already on main: the cli_identity keepIdentities switch
(9c3772311 keeps the asks in a sandbox via testenv's marker) and the
omarchy reset (main's TestCurrent already resets cached/seen/asked).

Run (darwin, loaded machine):
- On main 043e0cfc7, -count=3: TestRouting, TestSmartRouting,
  TestQuotaRestsUntilItsReset, TestForeignReasoningIsLeftOut,
  TestStandaloneNativeFallback fail; codexcat and tui fail; provider
  -shuffle=1791359851244745000 fails TestCopilotAuto and
  TestCopilotSignAndModels, and -count=2 -shuffle=1791856220860256000
  -run 'Copilot|TestPlanQuotas|TestCachedCardsAskNobody' fails
  TestPlanQuotas and TestCachedCardsAskNobody. With this change, that
  provider run (-shuffle=on, -count=2), the same gateway tests,
  ./internal/codexcat, ./internal/tui and the Settle/Hold/warm-up tests
  in plugin and provider pass -count=3.
- Breaking Settle by hand: without Told(),
  TestSettleWaitsForTheHooksItTold fails; without UseCached(nil),
  TestSettleForgetsTheFoldersPlugins fails.
- gofmt -l; go vet ./... on darwin, GOOS=linux -tags nogui, GOOS=windows.
Not run: the whole ./... suite at once (the machine's load times it out)
and Windows/Linux test runs.
2026-10-13 09:52:14 +08:00
yetone 23e764d0e0 cli: magpie's commands move from the root into internal/cli; the root keeps only main.go
The root held 89 .go files (30 commands, 59 tests). They move as they are
to internal/cli (package cli), with git mv so history follows them. The
only code change is main() becoming cli.Main(version): the root's new
main.go keeps `var version` in package main, so -ldflags "-X
main.version=…" in the Makefile, the Dockerfile and magpie-releases, and
every workflow, work unchanged. go-winres's rsrc_windows_*.syso still land
next to package main in the root.

Tests that read testdata by a root-relative path now go up one level
(../plugin/testdata/fake, ../sessions/testdata). Five subsystem doc links
point at internal/cli/.

Run:
- go build ./..., gofmt -l, go vet on darwin, linux and windows (nogui)
- builds with tags production, dev, "production nogui"; windows
  -H windowsgui; linux CGO_ENABLED=0
- make release-cli TARGETS="darwin/arm64 linux/amd64 windows/amd64
  android/arm64" VERSION=9.9.9-tidy: all four built, binary prints
  "magpie 9.9.9-tidy"
- docker build --build-arg VERSION=7.7.7-tidy: container prints
  "magpie 7.7.7-tidy"
- go test ./internal/cli (default and nogui): 152 tests, the same count
  as the root on main
- go test ./...: all packages pass (agent, gateway, library, provider
  timed out at 10m under other sessions' load and passed rerun alone
  with -timeout 40m; none of them changed)
- the built binary in a sandbox HOME: version, help, ls, providers,
  claude, and an unknown command's error
2026-10-12 20:40:22 +08:00