Files
magpie/internal
nrenvo 7b151cf549 provider tests: the stale copy's prompt return is asserted by a held refresh, not a 40ms bound (#1586)
TestSubscriptionUsageServesStale said "a stale copy comes back at once while it
refreshes" by timing the call: a 50ms ctx and a 40ms bound on time.Since(start).
On a loaded machine the bound is what fails -- the report has "waited
311.332917ms for a stale copy" -- so the test said nothing either way about the
guarantee it guards. Which step of the call took those 311ms I did not
establish; the assertion no longer needs to know, because nothing is timed.

The refresh is now held at the vendor instead: CopilotUserURL points at an
httptest server whose handler blocks until released, so the refresh cannot
finish. The copy is asserted to come back while SubscriptionUsageReading still
reports a refresh in flight, which is the guarantee itself rather than a proxy
for it, and <-reached proves a refresh really went out, so the test cannot pass
by never starting one.

The test also resets c.asked, the one field of the cache it primes that it had
left alone. It is not set when this test runs -- AskUsage is the only setter and
quota_asked_test.go's own restart clears it -- so this is not the reported
failure's cause; it completes what the test already does to c.data, c.at and
c.pending, so the test does not depend on another file's cleanup.

What was run:
  gofmt -l internal/provider/subscription_usage_test.go   (no output)
  go test -tags nogui -count=1 -run TestSubscriptionUsageServesStale ./internal/provider
  go test -race -count=20 -run TestSubscriptionUsageServesStale ./internal/provider
  go test -tags nogui -count=1 ./internal/provider        (whole package)
  go vet ./... ; GOOS=linux go vet -tags nogui ./... ; GOOS=windows go vet ./...
  go build ; GOOS=linux go build -tags nogui ; GOOS=windows go build
  go test -tags nogui ./... (53 of 54 packages ok; internal/gateway reds only in
    the parallel run, which this change cannot reach -- it does not compile this
    file -- and which is filed already as #1543/#1544)

Without the change: with SubscriptionUsage's "if !have && pending != nil" broken
to "if have && pending != nil" -- a copy that has data waiting for the pending
refresh -- the new test fails with

  subscription_usage_test.go:97: got [], want only claude: a copy that waited
  for the held refresh comes back with nothing
  --- FAIL: TestSubscriptionUsageServesStale (12.51s)

Reviewed and landed from nrenvo/magpie fix/1586-stale-copy-test (b5bda612),
posted on #1586 because PRs are collaborators-only. Run at the cherry-pick on
origin/main 398f8469b, temp HOME, caches pinned, load average ~120-135:
  go test -tags nogui -race -count=50 -run 'TestSubscriptionUsageServesStale$' ./internal/provider   ok
  go test -tags nogui -race -count=20 -cpu 1,2 -run TestSubscriptionUsage ./internal/provider        ok
  go test -tags nogui -count=1 ./internal/provider                                                   ok 149.7s
  go vet, GOOS=linux and GOOS=windows go vet -tags nogui ./internal/provider; gofmt -l               clean
Broken by hand in SubscriptionUsage, two ways, each red:
  "if !have && pending != nil" -> "if pending != nil" (a stale read waits for
    the refresh, up to ctx): FAIL at :96, got [] (11.6s)
  an unbounded <-pending for every read: FAIL at :96, got the Copilot card read
    after the held refresh gave up (21s)
2026-10-11 21:22:18 +08:00
..
settings: keep awake can keep the display on too (#975, Hu9956: magpie's keep-awake held the system up, but the screen still went black and locked, and their agents record the screen to check their work, which a locked screen stops) — Settings › General's "Keep awake while agents work" row now has three segments, Off / On / Screen on too, saved as keepAwake and the new keepAwakeDisplay (default off, so On and every existing settings.json behave as before). awake.Keep takes a Level (Off, System, Display) in place of a bool; a level changed while held releases and takes the hold anew. On a Mac the display level runs caffeinate -i -d -w <pid> (pmset -g assertions on a caffeinate of the same flags shows PreventUserIdleDisplaySleep beside PreventUserIdleSystemSleep); on Windows SetThreadExecutionState gets ES_DISPLAY_REQUIRED too; on Linux logind's idle inhibitor (systemd-inhibit --what=idle:sleep, unchanged) is all there is, and whether the screen stays on is up to the desktop. keepAwakeDisplay is this computer's own (KeepOwn) and goes in prefsKeep, so another setting's save keeps it. The row's line says the display stays on when it's chosen; it keeps its English in data-en, so a language change re-translates it. zh/ja/de strings added. No TUI or CLI has keep-awake, so none changed. TestKeepDisplay (taken once, taken anew with the display, not again at the same level, back to System, released at Off), TestCaffeinateArgs, TestExecutionState (GOOS=windows test build) and TestKeepAwakeKeptAndOwn cover it; go test ./internal/awake ./internal/settings ./internal/gui ./internal/gateway pass, -race -count=5 on awake. keep-awake.test.cjs now runs en/zh/ja/de at 900px and 440px in Chromium and WebKit (display posts keepAwake+keepAwakeDisplay true, the line changes, another setting's save keeps it, segments fit the row, On and Off clear it, no click moves the page): 32/32 twice; gui-ja, gui-de, i18n-keys and click-scroll pass. go vet (darwin, windows, linux), darwin, linux (nogui) and windows builds pass. Not tried with an agent recording the screen; the reporter is asked to confirm.
2026-10-06 15:33:28 +08:00
…
upstream: the vendors' own status pages say when their API is down (#971, emo172: an Anthropic or OpenAI outage looked like a sign-in or quota problem) — a provider that calls Anthropic's, OpenAI's or Moonshot's API (by its base URL's host: api.anthropic.com, which the Claude subscription calls too; api.openai.com and chatgpt.com, Codex's; api.moonshot.cn/.ai) carries "API outage" (red), "API degraded" or "API maintenance" beside its name on its Providers row and its Usage card while the vendor's page says so; its title names the parts and the open incidents, and a click opens the incident (or the page), not the row. internal/upstream reads each page's Statuspage-style summary.json (status.claude.com; status.openai.com, incident.io's; status.moonshot.cn), checked by hand on 2026-10-06, and only the API's own parts (Claude API and Claude Code, not claude.ai; Chat Completions, Responses, Codex, Codex CLI, not "Codex in ChatGPT Desktop", which was degraded that day); an incident naming no parts (OpenAI's) counts only while those parts are affected. Pages are read only when the Providers or Usage page asks (GET /api/upstream), at most once in five minutes, never on a request's way; a page that fails, isn't JSON or no longer lists the API's parts is unknown and marks nothing. A relay serving the same models is never marked. DeepSeek's page (Flashduty) has nothing readable and is only known for its link; OpenRouter, xAI, Mistral and z.ai have no page read. The gateway's failure messages, TUI, CLI and tray aren't changed. zh/ja/de added. upstream_test (fake pages from the real summaries: API down, claude.ai down isn't the API, Claude Code degraded, OpenAI's app isn't the API, 503/HTML/changed page unknown, read once in Fresh and Of never waits, hosts; -race -count=5) and gui's TestUpstreamRoute pass; upstream-status (Anthropic down: its provider and the Claude subscription marked, relay/OpenAI/unread Moonshot not, click opens the incident not the row, all well marks nothing; 900 and 440px, the badge whole, the name giving way) passes in Chromium and WebKit, en and zh, and fails 8/8 without the app.js change. i18n-keys, gui-ja, gui-de, click-scroll, account-return, account-models, usage-keys-fold, deprecated-subscriptions and add-sheet pass; go vet, go test ./internal/gui/, linux/windows/nogui builds pass.
2026-10-06 12:36:05 +08:00
…