Files
magpie/internal/gui/checkin_account_api_test.go
T
yetone ab1006bb80 gui: each WorkBuddy, Trae CN, MiniMax, Qoder or plugin account's daily check-in can be turned off on its own (#1902, magicLaLa)
settings.CheckinOff lists the accounts left out, by their entry in the
vendor's check-in file ("workbuddy|<uid>", "trae-cn|<uid>", a plugin's
"<provider>|<account>"). checkinNow skips them, both in the loop and on
Check in now. provider.CheckinAccounts() lists every account a check-in
reaches; /api/settings carries it as checkinAccounts, and
POST /api/settings/checkin-account {key,on} turns one off or on. A full
/api/settings save keeps the list. Settings shows an Off/On switch per
account under each vendor's Daily check-in row when it has 2 or more
accounts; the Usage card says "Auto check-in is off for this account" and
offers no Check in now for it. en, zh, zh-TW, ja, de.

Run (on 63a361b5f's tree, then targeted again on 7565d93c8):
- go test -tags nogui ./internal/provider -run 'TestCheckinAccount|TestWorkBuddyCheckin|TestTraeCheckin|TestPluginCheckin|TestQoderCheckin|TestMiniMax.*Checkin' : ok
- go test ./internal/gui -run 'TestCheckinAccountSetting|TestSettingsSaveKeeps' : ok
- broken by hand: skipping off accounts (false && off[a.key]), listing On,
  the card flag, the /api/settings carry and the dedup each turned the
  new tests red
- GUI (playwright, Chromium + WebKit, 1100 and 420, en/zh/zh-TW/ja/de):
  checkin-account 40/40, plugin-checkin, usage-checkin, i18n-keys,
  warm-at-own, warm-at-times all pass; app.js broken by hand made
  checkin-account fail 20/20 in Chromium
Then on 8e6354714 (fresh origin/main):
- gofmt -l clean; go vet darwin, GOOS=linux -tags nogui, GOOS=windows for
  provider, gui and settings ok
- go test -tags nogui ./internal/provider ok (260s); ./internal/settings ok
- GUI checkin-account, plugin-checkin, usage-checkin, i18n-keys 91/91
- go test ./internal/gui: everything passed except two timing tests, both
  at load average ~180 from other sessions:
  - TestMainWindowCorners was killed at its 40s deadline. Filed as #1936.
    It passes alone on origin/main 81f587d7b and on this change (13s).
  - TestSetAnswersWhileDevinAndProvidersHang hit 14s against its 10s bound
    (#1375). Alone it passes (1.1s).
  Neither test goes near check-in or settings.CheckinOff. The whole of
  ./internal/gui passed (506s) on the tree before the rebase.
2026-10-13 14:40:11 +08:00

67 lines
2.2 KiB
Go

package gui
import (
"net/http"
"net/http/httptest"
"path/filepath"
"slices"
"strings"
"testing"
"github.com/yetone/magpie/internal/agentenv"
"github.com/yetone/magpie/internal/settings"
)
// One account's daily check-in is turned off and on by itself (#1902,
// magicLaLa: 根据每个账号设置是否开启自动签到): off adds it to
// settings.CheckinOff once, on takes it out, another account's entry and
// the vendor's switch are left as they were, and a save of the Settings
// page, which doesn't send it, keeps it.
func TestCheckinAccountSetting(t *testing.T) {
h := t.TempDir()
t.Setenv("HOME", h)
t.Setenv("USERPROFILE", h)
t.Setenv("XDG_CONFIG_HOME", filepath.Join(h, ".config"))
t.Setenv("XDG_CACHE_HOME", filepath.Join(h, ".cache"))
t.Setenv("APPDATA", filepath.Join(h, "AppData", "Roaming"))
t.Setenv("LOCALAPPDATA", filepath.Join(h, "AppData", "Local"))
for _, v := range agentenv.Vars {
t.Setenv(v, "")
}
s := settings.Load()
s.WorkBuddyCheckin, s.CheckinOff = true, []string{"workbuddy|u2"}
if err := settings.Save(s); err != nil {
t.Fatal(err)
}
handler := Handler(nil, nil)
post := func(path, body string) {
t.Helper()
rec := httptest.NewRecorder()
handler.ServeHTTP(rec, httptest.NewRequest("POST", path, strings.NewReader(body)))
if rec.Code != http.StatusOK {
t.Fatalf("%s %s: %d %s", path, body, rec.Code, rec.Body)
}
}
off := func(want ...string) {
t.Helper()
got := settings.Load()
if !slices.Equal(got.CheckinOff, want) || !got.WorkBuddyCheckin {
t.Fatalf("checkinOff %q (want %q), workbuddyCheckin %v", got.CheckinOff, want, got.WorkBuddyCheckin)
}
}
post("/api/settings/checkin-account", `{"key":"workbuddy|u1","on":false}`)
off("workbuddy|u2", "workbuddy|u1")
post("/api/settings/checkin-account", `{"key":"workbuddy|u1","on":false}`)
off("workbuddy|u2", "workbuddy|u1")
post("/api/settings", `{"theme":"dark","workbuddyCheckin":true}`)
off("workbuddy|u2", "workbuddy|u1")
post("/api/settings/checkin-account", `{"key":"workbuddy|u1","on":true}`)
off("workbuddy|u2")
rec := httptest.NewRecorder()
handler.ServeHTTP(rec, httptest.NewRequest("POST", "/api/settings/checkin-account", strings.NewReader(`{"on":false}`)))
if rec.Code == http.StatusOK {
t.Fatal("no account, yet saved")
}
}