Files
magpie/internal/gui/warm_now_api_test.go
T
yetone 5bd41301b9 warm-up: All accounts warms every account in use at one press (CoderMaurice on X)
CoderMaurice on X: with several Claude accounts, Warm up now had to be
pressed once per account. With two or more accounts, the Warm up… menu on
the Warm up now row (a Claude Code or Codex provider's editor, the warm-up
section) now starts with All accounts. It sends POST /api/warm-all, and
provider.WarmAll sends Warm up now to every account that is in use (the
one the agent is on, or one turned on beside it) and whose windows aren't
all running already, going by the cached readings the Usage page shares.
It runs three at a time. An account that is turned off or paused, or
already in its windows, is sent nothing. An account whose sign-in lapsed
is sent nothing and is listed as failed, as Warm up now treats it. The
row's line lists the accounts warmed, the ones already in a window, and
each refusal with its reason (in red).
Accounts that are turned off aren't listed. A gateway rest is not read
(the provider package can't see it). An account rested for a used-up
window is still inside that window, so it is skipped as running.

"All accounts" moves from the usage plugin's i18n.js into core i18n.js,
since the core uses it now. It and two new strings are in zh, zh-TW, ja
and de. app.js stays inside its budget: the single-account and
all-accounts results now go through one formatter.

Run at a1968a0b5 (rebased on origin/main aecf27efb), on mica:
- go test -run 'WarmAll|WarmNow|CoreScriptBudget|Budget' ./internal/provider
  ./internal/gui: ok. New: TestWarmAllWarmsEachIdleAccountInUse,
  TestWarmAllOnlyCodexAndClaude, warm-all cases in TestWarmNowAPISaysWhy.
- Broken by hand: with the "running" skip removed from warmAll,
  TestWarmAllWarmsEachIdleAccountInUse FAILs (busy@ and spent@ warmed).
  With the All accounts item removed from the menu, warm-now.test.cjs
  FAILs ("Warm up all warms every account at one press" and the menu
  list assertion).
- GUI, Chromium and WebKit, en/zh/zh-TW/ja/de, 900px and 440px:
  warm-now, i18n-keys, i18n-en-no-cjk, usage-accounts: 54/54 pass. Before
  the rebase, plan-name-fits, provider-prefs-layout and quota-warm also
  passed (54/54 with usage-accounts).
- gofmt -l: clean. go vet, GOOS=linux go vet -tags nogui and
  GOOS=windows go vet of internal/provider and internal/gui: ok.
  go build, GOOS=linux go build -tags nogui, GOOS=windows go build: ok.

Not run: the full go test ./... and the full GUI suite. Both mote and
mica had other sessions' GUI suites running throughout, and this ships
now per the owner's ship-immediately rule. Both will run when a machine
is free. Not tried: a real Warm up all against several real Claude
accounts (the send per account is the unchanged WarmNow).
2026-11-15 11:00:37 +08:00

47 lines
1.8 KiB
Go

package gui
import (
"encoding/json"
"net/http/httptest"
"path/filepath"
"strings"
"testing"
)
// Warm up now's route answers a failure with why, as the row shows it: an
// account that isn't signed in, or an agent with no warm-up, is a 400 with
// the reason, and nothing is sent.
func TestWarmNowAPISaysWhy(t *testing.T) {
home := t.TempDir()
t.Setenv("HOME", home)
t.Setenv("USERPROFILE", home)
t.Setenv("XDG_CONFIG_HOME", filepath.Join(home, ".config"))
t.Setenv("XDG_CACHE_HOME", filepath.Join(home, ".cache"))
t.Setenv("CODEX_HOME", filepath.Join(home, ".codex"))
t.Setenv("CLAUDE_CONFIG_DIR", filepath.Join(home, ".claude"))
t.Setenv("MAGPIE_NO_ACCOUNTS", "1") // no sign-in read, the Keychain's included
h := Handler(nil, nil)
for _, c := range []struct{ body, want string }{
{`{"agent":"codex","user":"nobody@example.com"}`, `no ChatGPT account "nobody@example.com"`},
{`{"agent":"claude","user":"nobody@example.com"}`, `no Claude account "nobody@example.com"`},
{`{"agent":"copilot","user":"octocat"}`, `"copilot" has no warm-up`},
{`{"agent":"codex"}`, `no ChatGPT account ""`},
// Warm up all: no account, or no warm-up
{`{"agent":"claude","all":true}`, `no Claude account to warm up`},
{`{"agent":"codex","all":true}`, `no ChatGPT account to warm up`},
{`{"agent":"copilot","all":true}`, `"copilot" has no warm-up`},
} {
route := "/api/warm-now"
if strings.Contains(c.body, `"all"`) {
route = "/api/warm-all"
}
rec := httptest.NewRecorder()
h.ServeHTTP(rec, httptest.NewRequest("POST", route, strings.NewReader(c.body)))
var out struct{ Error string }
json.Unmarshal(rec.Body.Bytes(), &out)
if rec.Code != 400 || !strings.Contains(out.Error, c.want) {
t.Errorf("%s: %d %s, want 400 saying %s", c.body, rec.Code, rec.Body, c.want)
}
}
}