2 Commits
Author SHA1 Message Date
yetone 3c516556bb plugin: TestStopLetsARenewalEnd waits for the renewal to start and the stopped host to end, not for 300ms and Restart (#2743)
The test was red on main two ways, each from a timing assumption:

- "the renewal never started" (line 54, 60s): the load call that starts
  the renewal had a fixed 300ms context. When the call is not written to
  the host within those 300ms (a slow get, a busy writer), it is given up
  on before it is sent, the plugin never reaches auth.refresh, and no
  wait helps. Now the call's context is cancelled only once the
  renewal's log shows it started.
- "kept ... not the renewed token" (line 61, CI at 84ad780b6): a
  given-up call keeps its slot until its abort is written to the host
  (callAborting). If Restart runs before that write, the host is busy,
  retire stops it in the background, and Restart returns at once; the
  test then read plugin-auth.json while the renewal was still running.
  The product is right: the background stop still lets the renewal end
  and saves the token. The test now waits on the stopped host's dead
  channel. It also waits until magpie has heard the host's "renewing"
  event, so a host output read late can't count as no renewal.

No product code changes.

Run on mote at base origin/main d2c29abe7 (no internal/plugin change since; rebased onto 640825b09 and the three stop tests rerun there, -race -count=3: ok):
- injected (not committed) a 500ms sleep in callWithTimeout before a
  "load" call is sent, and a 1.5s sleep in pumpCtrl before an abort is
  written. Old test, go test -race -failfast -count=20: red with each, the
  abort delay at line 61 ("after stopping 0s in, kept ... access:old"),
  the send delay at line 54 ("the renewal never started", 60.03s).
  New test, -race -count=20: ok with no injection (83.3s), with the
  abort delay (83.5s) and with the send delay (93.8s).
- broke by hand: stop no longer waiting for a renewal (the
  h.renewing loop off): the new test is red, "after stopping 2.004s in,
  kept ... not the renewed token".
- gofmt -l internal/plugin: nothing; go vet ./internal/plugin, with
  GOOS=linux and GOOS=windows too: ok; go test -tags nogui -race
  -count=1 ./internal/plugin: ok (165.2s).
- the full suite runs after the push, through the suite lock; its reds
  are filed as issues.

Not tried: Windows and Linux runs of this test; the change is in the
test only.
2026-11-06 11:51:38 +08:00
yetone 123594489a plugin: a host stopped mid-renewal saves the new token first, and two hosts never write each other's sign-ins away — a stopped host (quit, plugin update, restart) was killed 2 s after stdin closed even while it renewed a sign-in through auth.refresh, after the vendor had spent the old refresh token, so the account was signed out; and while a host restarts the old one and the new one both rewrote all of plugin-auth.json from what each had read, so one host's save could drop the other's accounts or newer token. host.js now tells magpie how many renewals are under way (event "renewing"), and stop gives a host still renewing after the 2 s up to 15 s in all, until the renewal is saved; with none it stops as fast as before. Every change to plugin-auth.json (setAuth, removeAuth, settle, take, auth.set, a renewal's save, and magpie's SignOut when no host runs) is made under plugin-auth.json.lock (O_EXCL, broken when older than 10 s), reading the file afresh and changing only its own accounts; a renewal's save checks under the lock that the stored sign-in is still the one it renewed, so an older host never writes a stale token over a newer one. TestStopLetsARenewalEnd (a 4 s refresh, the host restarted in the middle: old code kept the spent token) and TestTwoHostsKeepEachOthersSignIns (two hosts saving 40 accounts each at once: old code lost 38 of 80) fail on the old code and pass; TestStopWithoutRenewalIsQuick keeps the quick stop. go vet, builds (darwin, GOOS=linux, GOOS=windows) and go test -tags nogui -count=1 ./... under a temp HOME pass but TestProvidersAnswerWhileListsComeIn and TestClaudeSignedOut, timing tests that pass alone and in their packages rerun. Not tried with real plugin accounts. 2026-10-03 15:47:10 +08:00