Skip to content

Every agent's model. One place. Codex on DeepSeek, Claude Code on Kimi, from the menu bar.

1.4 KB
Raw Blame
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":"[email protected]"}`, `no ChatGPT account "[email protected]"`},
		{`{"agent":"claude","user":"[email protected]"}`, `no Claude account "[email protected]"`},
		{`{"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)
		}
	}
}