Files
magpie/internal/gui/warm_now_api_test.go
T
yetone 1801c96bfb warm-up: Warm up now sends one account its warm-up at once (Codex and Claude)
A Windows user on Discord asked for a manual warm-up of a Codex account.
Settings > Warm-up and check-in now ends both the ChatGPT and the Claude
tab with a "Warm up now" row. Its text button sends the account's warm-up
right away. With one account it sends straight off. With several it opens
the app menu ("Warm up which account"), not a select. The row then says
"Warmed up {who} {when}", or "Couldn't warm up {who}: {why}" in red, and
the status line says the same.

What is sent: provider.WarmNow(agent, user) sends the scheduled warm-up's
own request to that one account and to no other. For Codex that is
warmCodexLogin; for Claude it is warmClaudeLogin over the gateway's
warmClaude (Claude Code's run in that account's config directory), set
through WarmClaudeVia. It works whether the warm-ups are on or off. An
account whose sign-in lapsed is refused with the reason. Afterwards the
allowance is read again (StaleAllowance / claudeWarmedNow), as after a
scheduled warm-up. The schedule's file is left to the schedule. The
Codex prompt, identity and base_instructions are unchanged: it is the
same body. The route is POST /api/warm-now, and /api/settings carries
claudeUsers beside codexUsers.

Claude gets the item too. It shares the warm-up engine and the same tab,
and the send is the same warmClaude the schedule uses.

No size budget was raised.

Run:
- WSL (wsl-run), Chromium and WebKit, with the GUI test
  warm-now.test.cjs in en/zh/zh-TW/ja/de at 900px and 440px: 22/22.
  The pressed button stays in place within 1px after two frames.
- WSL, the related files (warm-now, warm-at-own, warm-at-times,
  warm-reset-asleep, settings-groups, settings-search, i18n-keys):
  102/102.
- WSL, the other files that touch these lists (checkin-account,
  checkin-reason, checkin-reason-once, plugin-checkin, segs-press-redraw,
  settings-sections, usage-checkin): 169/170. The red is segs-press-redraw
  "webkit ja 440px: every Settings option..." with "could not bring the
  option into view" after 103s under load. It passed 3/3 alone and is
  filed as #4189.
- mote (macOS) at the final tree: go vet for internal/gui, provider and
  gateway; go test -run 'WarmNow|Budget|Warm' ./internal/gui
  ./internal/provider: ok. An earlier mote run, before the route move,
  ran go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go
  vet ./..., go build ./... and the budget tests: ok.
- Windows (win-run): go test -run 'TestWarmNow|TestCodexWarm|TestClaudeWarm'
  ./internal/provider/ ./internal/gui/: ok.
- WSL: go vet -tags nogui ./... is ok and gofmt -l is empty.
  go test -tags nogui -timeout 45m ./...: 75 packages ok, including
  internal/gui and internal/provider. internal/agent has 4 reds on the WSL
  box (TestInstalledVersion, TestGrokInstalled,
  TestCursorFolderFromTheEditorIsNotTheCLI, TestOmpDetectedWithPiDir). They
  are already filed as #4033 and #3548 (fake binaries hit WSL interop).
  internal/gateway has 1 red, TestUnroutedRequestShownThenAnswered: giveUp
  answers the 504 before it marks the route done. That is not this change,
  and it is filed as #4200.

At the head rebased on origin/main 9474eaf9c:
- mote: gofmt -l is empty. go vet passes for gui, provider and gateway,
  and GOOS=windows go vet passes for gui and provider. go test -run
  'WarmNow|Budget|Warm|I18n' ./internal/gui ./internal/provider: ok.
- WSL: warm-now, i18n-keys and warm-at-own GUI tests: 44/44.

Broken by hand (each was red, then restored and checked with cmp):
- WarmNow swallowing the Codex error: TestWarmNowSendsTheScheduledWarmUp
  went red on the refused request.
- Running Claude in ls[0]'s directory: TestWarmNowClaudeRunsClaudeCode
  went red.
- Dropping the lapsed check: TestWarmNowLapsedAccount went red.
- The menu always sending users[0]: warm-now.test.cjs went red (timed
  out) in both engines.

Not tried:
- A warm-up of a real account. The request-equality test compares
  against the scheduled warm-up's request through a fake vendor.
- Breaking the request-equality check by changing the body itself.
- The GUI suite on macOS, because mote's browsers hang (#4125).
2026-10-29 15:39:31 +08:00

39 lines
1.4 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 ""`},
} {
rec := httptest.NewRecorder()
h.ServeHTTP(rec, httptest.NewRequest("POST", "/api/warm-now", 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)
}
}
}