Files
magpie/internal/provider/checkin_off_test.go
T
yetone b7ceb53fe4 provider: WorkBuddy's built-in is retired; its plugin serves it
workbuddy and workbuddy-ai join retiredBuiltins, as Zed did in c0605abc2
and Qoder in 43cc3171d. @magpie-community/opencode-workbuddy-auth serves
both, moved or not.

Removed (built-in only):
- provider: workbuddy_models.go (the model list); in workbuddy.go the
  sign-in, token renewal, usage/credits reading, request signing and the
  site's model fetch; the WorkBuddy cases in account.go (Accounts),
  logins_on.go, logins.go (list/switch/forget), login_usage.go,
  subscription_usage.go and signin.go; WorkBuddyBaseForTest, now unused.
- The built-in tests: workbuddy_test, workbuddy_signin_test,
  workbuddy_accounts_test, workbuddy_ai_test, workbuddy_body_test,
  workbuddy_enterprise_test, workbuddy_free_test, workbuddy_names_test,
  workbuddy_spare_free_test, workbuddy_refused_test (provider), and
  gateway/workbuddy_refused_test.

Kept, and why:
- migrate_workbuddy.go (the mover) with what it reads: wbSite, wbCreds,
  wbOwn/wbAuthPath (the desktop's file, sent as a marker), wbLogins,
  wbTokens (back drops a renewed pair).
- workbuddy_checkin.go: the daily check-in now walks the plugin's
  accounts only and sends through the plugin's fetch (a.via); wbCallVia,
  wbNum and the site's api() serve it, and plugin_usage's host.
- WBRestricted/WBRestrictedHint: the gateway reads the plugin's 11140 by
  them. textOnly: applied to the plugin's lists.
- draw_workbuddy and search_workbuddy in the gateway: they serve the
  plugin's provider. The PLUGIN-SERVED notice in workbuddy.go.
- The WorkBuddy agent target (internal/agent) is untouched.

Tests changed in meaning:
- TestFetchNewAccount, TestFetchNewRetriedSoon and
  TestFetchingNewOnceStarted used WorkBuddy as the built-in signed in;
  they use Codex now (codexSignedIn, codexListedAt), same assertions.
- TestFetchPlanWithoutList uses local models; TestWorkBuddyFetchModels,
  TestWorkBuddyAIGLMIsTextOnly and TestOwnStoreSignInAgainDropsTheReading
  (WorkBuddy case) are gone with the code.
- Check-in: TestWorkBuddyCheckinSignedIn is gone; the fixture's account
  is a plugin account signing through via; PluginUnderItsOwnID became
  TestWorkBuddyCheckinPluginAccounts (plugin accounts listed, a built-in
  login left out). TestCheckinAccountsListed reads a moved plugin.
- TestWorkBuddyMover seeds the desktop's logins.json row: retired, the
  built-in no longer writes it, and an existing user's row is what moves
  (red without the row).
- Gateway: the WorkBuddy draw and search tests run through the fake
  plugin (besideFake), without the built-in's header checks;
  TestWorkBuddySearchesForItsModels folded into
  TestWorkBuddyPluginSearches (refusal and search-off checks kept);
  TestLoopEndsWorkBuddysReply is the plugin route only;
  TestWorkBuddyRestrictedRestsHours lost its built-in translation case.

Run:
- gofmt -l internal: empty
- go vet -tags nogui ./...; GOOS=linux and GOOS=windows the same: clean
- go test -tags nogui -count=1 -timeout 45m -run 'WorkBuddy|workbuddy|Checkin|CheckIn|FetchNew|FetchingNew|FetchPlan|Migrat|migrat|Mover|Moved|Retired|Retire|SignIn|Plugin|Draw|Search|Loop|Redact|Restricted|Images|TextOnly|Qoder|BuiltinsSay|AsksOwn|Loopback' ./internal/provider ./internal/gateway ./internal/cli ./internal/gui ./internal/qoder
  first run: gateway, cli, gui ok; provider red on TestWorkBuddyMover
  (above); after the fix provider ok (99s).
- Not run: whole packages, the full suite, the GUI node suite.
2026-10-17 23:11:00 +08:00

82 lines
2.4 KiB
Go

package provider
import (
"context"
"testing"
"time"
"github.com/yetone/magpie/internal/settings"
)
// leaveOut saves keys as the accounts left out of their daily check-in.
func leaveOut(t *testing.T, keys ...string) {
t.Helper()
s := settings.Load()
s.CheckinOff = keys
if err := settings.Save(s); err != nil {
t.Fatal(err)
}
}
// An account the user left out of the daily check-in (#1902, magicLaLa:
// 根据每个账号设置是否开启自动签到) is asked nothing, by the loop or a
// press of Check in now, while its vendor's check-in is on; turned back
// on, it is checked in at once.
func TestCheckinAccountLeftOut(t *testing.T) {
signIn(t)
f := &fakeWBCheckin{active: true}
srv := f.serve(t)
now := time.Date(2026, 10, 13, 3, 0, 0, 0, time.UTC)
c := wbCheckinFixture(t, srv, &now)
ctx := context.Background()
leaveOut(t, "workbuddy|u1")
for _, soon := range []bool{false, true} {
if rs := c.checkinNow(ctx, soon); len(rs) != 0 {
t.Fatalf("left out, soon %v: %+v", soon, rs)
}
}
if s, cl := f.counts(); s != 0 || cl != 0 {
t.Fatalf("left out, yet asked: status %d, claims %d", s, cl)
}
// another account's entry leaves this one in
leaveOut(t, "workbuddy|u2")
rs := c.checkinNow(ctx, false)
if len(rs) != 1 || rs[0].Outcome != CheckinClaimed || !rs[0].Asked {
t.Fatalf("back on: %+v", rs)
}
}
// Settings lists each account a check-in reaches with its own switch, and
// the account's Usage card says it is left out.
func TestCheckinAccountsListed(t *testing.T) {
movedPlugin(t, "workbuddy", map[string]map[string]any{
"workbuddy": {"type": "oauth", "access": "wb-access", "refresh": "r", "expires": 0, "accountId": "旅行者", "uid": "u1"},
})
var mine []CheckinAccount
for _, a := range CheckinAccounts() {
if a.Key == "workbuddy|u1" {
mine = append(mine, a)
}
}
if len(mine) != 1 || mine[0].By != "" || mine[0].User != "旅行者" || !mine[0].On {
t.Fatalf("listed: %+v", CheckinAccounts())
}
qs := WithCheckins([]SubscriptionQuota{{Provider: "workbuddy", User: "旅行者"}})
if !qs[0].Checkins || qs[0].CheckinOff {
t.Fatalf("card, on: %+v", qs[0])
}
leaveOut(t, "workbuddy|u1")
for _, a := range CheckinAccounts() {
if a.Key == "workbuddy|u1" && a.On {
t.Fatalf("left out, listed on: %+v", a)
}
}
qs = WithCheckins([]SubscriptionQuota{{Provider: "workbuddy", User: "旅行者"}})
if !qs[0].Checkins || !qs[0].CheckinOff {
t.Fatalf("card, left out: %+v", qs[0])
}
}