provider: a plugin's daily check-in reaches every sign-in, also two that share a display name (plugins#254)

AutoClaw's plugin can hold several sign-ins under one default display name,
which AutoClaw doesn't let the user change. plugin_checkin.go keyed each
account's check-in on "<provider>|<AccountID>", the display name, so
checkinNow's per-key dedupe asked only the first sign-in of each name, by
the loop and by Check in now alike; the others stayed 今日未签 for good,
and Settings showed one row, and one Off switch, per name.

Each sign-in is now keyed on the key plugin-auth.json keeps it under
(pluginCheckinKey: "autoclaw|autoclaw", "autoclaw|autoclaw#x1y2z3").
Two sign-ins never share it; a refresh writes the same key, and signing
in to an account already signed in goes back to its key (host.js
settle). The display name is shown only. Cards, Settings rows,
CheckinOff and Check in now all read the same key, so app.js is
unchanged. An account without an AccountID already had this key.

Upgrade (adoptLegacyPluginCheckins, run when the plugin's accounts are
listed): an entry kept as "<provider>|<display name>" goes
- in plugin-checkin.json, to the first sign-in in use of that name (the
  one the old key's check-in asked) and only to it, and the old entry
  is dropped: it isn't asked again today, and its namesakes, never asked,
  are;
- in settings.CheckinOff, to every sign-in of that name: the user turned
  that name off and none of its sign-ins was checked in since, so the
  upgrade switches none on (settings.EditCheckinOff edits that field
  alone from what the file holds).
A plugin-checkin.json that can't be read or parsed is left as it is and
carried over once it reads; writes go through writePrivate
(temp-and-rename). Known gap: a sign-in made the same day after another
was signed out can take the freed key and that day's result.

The fake plugin's check-in now records a signed-in account as
name@fake/uid so two of one name tell apart in the presses.

Tests:
- TestPluginCheckinTellsSignInsOfOneNameApart: four sign-ins, A/u1, A/u2,
  B/u3, B/u4 (the reporter's case). All four pressed once, none again
  that day, four entries kept, four Settings rows, every card marked;
  with A/u2 off, Check in now the next day presses the other three.
- TestPluginCheckinCarriesOverDisplayNameEntries: a plugin-checkin.json
  with fakeco|A@fake and fakeco|B@fake claimed today plus another
  plugin's entry, and CheckinOff ["workbuddy|123", "fakeco|B@fake"].
  A's check-in goes to its first sign-in only, the old entries go, the
  other plugin's stays, both B sign-ins are off and workbuddy|123 is
  kept; the loop then presses only A's namesake, and a second look
  presses nothing.
- TestPluginCheckinCarriesNothingOverAnUnreadableFile.

Broken by hand, each red:
1. key back on the display name: TellsApart pressed only A@fake/u1 and
   B@fake/u3; CarriesOver kept the old entries.
2. adoption not called: CarriesOver ("A's check-in went to ... ok false").
3. record to every heir: CarriesOver ("carried to both") and Unreadable.
4. Off to the first heir only: CarriesOver (CheckinOff lacks one B).
5. old entry kept: CarriesOver and Unreadable.
6. parse error ignored: Unreadable.

Run at 0f044e944 (origin/main) plus this change, macOS arm64, sandbox
HOMEs from testenv, shared GOCACHE:
- go test -race -count=20 -run TestPluginCheckin ./internal/provider: ok
- gofmt -l on the changed files: prints nothing
- go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows
  go vet ./...: clean
- go build, GOOS=linux go build -tags nogui, GOOS=windows go build: ok
- go test -timeout 45m ./...: exit 0, 68 packages ok, no FAIL
- after a comment-only rewrap: go test ./internal/provider
  ./internal/settings: ok
No GUI suite: internal/gui/assets is unchanged.
Not tried with real AutoClaw accounts or a real plugin-checkin.json from
the reporter.
This commit is contained in:
yetone
2026-10-21 07:04:19 +08:00
parent fb371eaa1b
commit 62a1df8010
5 changed files with 453 additions and 14 deletions
+2 -2
View File
@@ -44,7 +44,7 @@ A plugin can press its vendor's daily check-in (签到) itself: its `auth` hook
The hook returns `{outcome, credit?, streak?, message?}`. `outcome` is one of `claimed` (checked in now), `done` (already in today), `ineligible`, `inactive` (no check-in event now), `captcha` or `failed`. A throw, or an outcome not in that list, is `failed` with the reason. `captcha` means the vendor wants a captcha: magpie never solves one, and says "check in in its own app" instead. A plugin must not solve captchas either.
[`plugin_checkin.go`](../../internal/provider/plugin_checkin.go) runs these through the same `checkiner` as the built-in check-ins ([`checkin.go`](../../internal/provider/checkin.go)): each signed-in, in-use account once a Beijing day, the first look 2 minutes after start and then every 30 minutes, a `failed` asked again after 30 minutes, every other outcome settled for the day. Results are kept in `plugin-checkin.json` by `provider|account`; a failure is recorded as failed and never resets an account, a key or a previous day's result. Each account's Usage card has the check-in row (`checkinBy: "plugin:<provider>"`), and Settings → Usage has a Plugins tab with a Daily check-in switch per provider (`settings.PluginCheckins`, `POST /api/settings/plugin-checkin {provider, on}`; *Check in now* is `POST /api/usage/plugin-checkin {provider}`). `magpie accounts checkin` and `c` on the TUI's Usage page include them. Every check-in, built-in or a plugin's, also skips an account listed in `settings.CheckinOff` by its file key (#1902): `checkinNow` asks nothing for it, by the loop or a press, `CheckinAccounts()` lists each account with its own `on` for Settings (`checkinAccounts`, a row each under the vendor's switch when it has two or more, `POST /api/settings/checkin-account {key, on}`), and its card carries `checkinOff`.
[`plugin_checkin.go`](../../internal/provider/plugin_checkin.go) runs these through the same `checkiner` as the built-in check-ins ([`checkin.go`](../../internal/provider/checkin.go)): each signed-in, in-use account once a Beijing day, the first look 2 minutes after start and then every 30 minutes, a `failed` asked again after 30 minutes, every other outcome settled for the day. Results are kept in `plugin-checkin.json` by `provider|<sign-in key>` (`pluginCheckinKey`: the key `plugin-auth.json` keeps the sign-in under, `autoclaw` or `autoclaw#x1y2z3`), never by the display name: two sign-ins can share a name (AutoClaw's default can't be changed), and keyed by it only the first of them was ever checked in, by the loop or *Check in now* (plugins#254). The sign-in key holds over a refresh and over signing in to the same account again (`settle` in `host.js` puts it back under its key); a sign-in made after one was signed out the same day may take the freed key, and with it that day's result. An entry kept by `provider|<display name>` before then is carried over once the plugin's accounts are listed (`adoptLegacyPluginCheckins`): a check-in goes to the first sign-in in use of that name, the one the old key asked, and only to it, so its namesakes are asked and none twice; an `Off` in `settings.CheckinOff` goes to every sign-in of that name, since none of them was checked in while it was off. A `plugin-checkin.json` that can't be read or parsed is left as it is and carried over once it reads. A failure is recorded as failed and never resets an account, a key or a previous day's result. Each account's Usage card has the check-in row (`checkinBy: "plugin:<provider>"`), and Settings → Usage has a Plugins tab with a Daily check-in switch per provider (`settings.PluginCheckins`, `POST /api/settings/plugin-checkin {provider, on}`; *Check in now* is `POST /api/usage/plugin-checkin {provider}`). `magpie accounts checkin` and `c` on the TUI's Usage page include them. Every check-in, built-in or a plugin's, also skips an account listed in `settings.CheckinOff` by its file key (#1902): `checkinNow` asks nothing for it, by the loop or a press, `CheckinAccounts()` lists each account with its own `on` for Settings (`checkinAccounts`, a row each under the vendor's switch when it has two or more, `POST /api/settings/checkin-account {key, on}`), and its card carries `checkinOff`.
The switch is off by default. For a provider whose vendor magpie checked in through the plugin's fetch before (WorkBuddy, Trae CN, MiniMax Code, Qoder), it follows that vendor's existing switch until set on its own, and magpie's own check-in leaves that provider's accounts to the plugin (`pluginChecksIn`), so an account is never checked in twice.
@@ -192,7 +192,7 @@ Gateway parity tests in [`plugin_parity_test.go`](../../internal/gateway/plugin_
[`plugin_decide_test.go`](../../internal/gateway/plugin_decide_test.go) runs the fake plugin (`FAKE_DECIDE`) with a decision API: its marked and `jev-*` models are classifiers and not offered to agents, chat to one is refused, a group saves one as classifier, not beside a chat model, and a group of decision models alone, and each classifier's question reaches the fake vendor at `/v1/systemone` through the plugin's fetch. With `FAKE_DECIDE=models` the marks without `decide` change nothing.
[`plugin_checkin_test.go`](../../internal/provider/plugin_checkin_test.go) runs the fake plugin's `auth.checkin` (`FAKE_CHECKIN`) through the schedule: off, each outcome, no second press the same day, failures only after the retry window, the next day, cards and Settings, and the vendor check-in stepping aside. `plugin-checkin.test.cjs` covers the card row and the Settings tab.
[`plugin_checkin_test.go`](../../internal/provider/plugin_checkin_test.go) runs the fake plugin's `auth.checkin` (`FAKE_CHECKIN`) through the schedule: off, each outcome, no second press the same day, failures only after the retry window, the next day, cards and Settings, and the vendor check-in stepping aside; `TestPluginCheckinTellsSignInsOfOneNameApart` signs in four accounts under two names, two of each (plugins#254), and checks each is checked in, kept, carded and switched off on its own, and `TestPluginCheckinCarriesOverDisplayNameEntries` upgrades a file and an `Off` kept by display name. `plugin-checkin.test.cjs` covers the card row and the Settings tab.
[`plugin_options_test.go`](../../internal/plugin/plugin_options_test.go) loads `testdata/options` in a real host: which declared options are kept and how they are capped, the user's value over the default at start, and a change read by the plugin after `SetProviderOptions` without a restart. [`plugin_option_api_test.go`](../../internal/gui/plugin_option_api_test.go) covers the endpoint, a bad key, and a Settings save keeping the values. `plugin-options.test.cjs` covers the editor in Chromium and WebKit, 1100 and 420 wide, in every language.
+3 -2
View File
@@ -217,7 +217,8 @@ export const FakePlugin = async ({ client }) => ({
}
},
// $FAKE_CHECKIN: the plugin presses the daily check-in itself, each
// press written as a line of the account's key to that file, and the
// press written as a line of the account's key to that file (a signed-in
// account's name/uid, so two of one name tell apart), and the
// answer said by the key: ck-claim gives 50 on a 3-day streak, ck-done
// is in already, ck-captcha is asked a captcha, ck-throw can't reach
// the vendor, ck-odd answers no outcome magpie knows
@@ -226,7 +227,7 @@ export const FakePlugin = async ({ client }) => ({
checkin: async (getAuth) => {
const a = await getAuth()
const fs = await import("node:fs")
fs.appendFileSync(process.env.FAKE_CHECKIN, (a.key ?? a.accountId ?? "") + "\n")
fs.appendFileSync(process.env.FAKE_CHECKIN, (a.key ?? (a.uid ? a.accountId + "/" + a.uid : a.accountId) ?? "") + "\n")
switch (a.key) {
case "ck-claim":
return { outcome: "claimed", credit: 50, streak: 3 }
+172 -9
View File
@@ -9,11 +9,16 @@ package provider
// from magpie's own check-in through its fetch (WorkBuddy, Trae CN,
// MiniMax Code, Qoder), so an account is never checked in twice.
//
// What came of it is kept in plugin-checkin.json by provider and account.
// What came of it is kept in plugin-checkin.json by provider and sign-in
// (pluginCheckinKey).
import (
"context"
"encoding/json"
"log"
"os"
"path/filepath"
"slices"
"sort"
"sync"
"time"
@@ -33,9 +38,31 @@ var pluginCheckinMu sync.Mutex
type pluginCheckinAcct struct {
User string
On bool
key string // provider|account
card string
do func(context.Context) WorkBuddyCheckin
key string // pluginCheckinKey
// legacy is the account's entry before plugins#254,
// pluginCheckinLegacyKey
legacy string
card string
do func(context.Context) WorkBuddyCheckin
}
// pluginCheckinKey is a plugin sign-in's entry in plugin-checkin.json and
// settings.CheckinOff: the provider and the key plugin-auth.json keeps the
// sign-in under ("autoclaw", "autoclaw#x1y2z3"). Two sign-ins never share
// it, and it holds while the sign-in does: a refresh writes the same key,
// and signing in to an account already signed in goes back to its key
// (host.js settle). Its display name (AccountID) is not the account: two
// AutoClaw sign-ins share a default name the user can't change, and keyed
// on it only the first of them was ever checked in (plugins#254).
func pluginCheckinKey(id, login string) string { return id + "|" + login }
// pluginCheckinLegacyKey is what pluginCheckinKey was before plugins#254:
// the provider and the account's display name, else its sign-in key.
func pluginCheckinLegacyKey(id string, a plugin.Account) string {
if a.AccountID != "" {
return id + "|" + a.AccountID
}
return pluginCheckinKey(id, a.Key)
}
// pluginCheckinProvider is a plugin's provider that checks in, and its
@@ -57,12 +84,8 @@ var pluginCheckinProviders = func() []pluginCheckinProvider {
card := PluginID(pp.ID)
for _, l := range pluginLogins(pp) {
acct := l.acct.Key
who := l.acct.AccountID
if who == "" {
who = acct
}
id := pp.ID
p.accounts = append(p.accounts, pluginCheckinAcct{User: l.User, On: l.On, key: id + "|" + who, card: card,
p.accounts = append(p.accounts, pluginCheckinAcct{User: l.User, On: l.On, key: pluginCheckinKey(id, acct), legacy: pluginCheckinLegacyKey(id, l.acct), card: card,
do: func(ctx context.Context) WorkBuddyCheckin {
c, err := plugin.AccountCheckin(ctx, id, acct)
if err != nil {
@@ -75,9 +98,149 @@ var pluginCheckinProviders = func() []pluginCheckinProvider {
out = append(out, p)
}
}
adoptLegacyPluginCheckins(out)
return out
}
// pluginCheckinAdopted are the legacy entries (pluginCheckinLegacyKey),
// by the check-in file they were looked for in, that
// adoptLegacyPluginCheckins has carried over or found nothing kept under,
// so it reads the files once for each; under pluginCheckinMu.
var pluginCheckinAdopted = map[[2]string]bool{}
// adoptLegacyPluginCheckins carries what was kept under each account's
// entry before plugins#254 (its provider and display name) over to its
// entry now (its sign-in), so an upgrade neither checks an account in
// twice in a day nor loses the user's own Off. Kept under a name two
// sign-ins share, it is:
//
// - a check-in, in plugin-checkin.json: the first of them in use, in
// the order the check-in lists them, the one the old key's check-in
// asked (it skipped the rest), and only that one: the others were
// never asked, so they are asked now. The entry goes once carried.
// - an account left out, in settings.CheckinOff: each of them. The user
// switched that name off, and none of its sign-ins was checked in
// since; one switched on only by the upgrade would be checked in
// against the user's choice.
//
// A file that can't be read or parsed is left for later as it is, and the
// entries are carried again once it reads.
func adoptLegacyPluginCheckins(ps []pluginCheckinProvider) {
pluginCheckinMu.Lock()
defer pluginCheckinMu.Unlock()
path := pluginCheckinPath()
// an entry a sign-in keeps now is never taken for an old one
now := map[string]bool{}
for _, p := range ps {
for _, a := range p.accounts {
now[a.key] = true
}
}
// each legacy entry's heirs, those in use first: the old check-in
// skipped an account not in use before it took the key
heirs := map[string][]string{}
var order []string
for _, inUse := range []bool{true, false} {
for _, p := range ps {
for _, a := range p.accounts {
if a.On != inUse || a.legacy == "" || now[a.legacy] || pluginCheckinAdopted[[2]string{path, a.legacy}] {
continue
}
if _, ok := heirs[a.legacy]; !ok {
order = append(order, a.legacy)
}
heirs[a.legacy] = append(heirs[a.legacy], a.key)
}
}
}
if len(order) == 0 {
return
}
checkins := adoptLegacyCheckinFile(path, order, heirs)
off := adoptLegacyCheckinOff(heirs)
if checkins && off {
for _, l := range order {
pluginCheckinAdopted[[2]string{path, l}] = true
}
}
}
// adoptLegacyCheckinFile gives each legacy entry of the check-in file at
// path to its first heir that has none of its own, and drops it; it says
// whether the file is as it should be now.
func adoptLegacyCheckinFile(path string, order []string, heirs map[string][]string) bool {
b, err := os.ReadFile(path)
if os.IsNotExist(err) {
return true
}
if err != nil {
log.Printf("plugin check-in: %v", err)
return false
}
st := map[string]WorkBuddyCheckin{}
if err := json.Unmarshal(b, &st); err != nil {
log.Printf("plugin check-in: %s: %v", path, err)
return false
}
changed := false
for _, l := range order {
r, ok := st[l]
if !ok {
continue
}
if _, has := st[heirs[l][0]]; !has {
st[heirs[l][0]] = r
}
delete(st, l)
changed = true
}
if !changed {
return true
}
out, err := json.MarshalIndent(st, "", " ")
if err == nil {
err = writePrivate(path, append(out, '\n'))
}
if err != nil {
log.Printf("plugin check-in: %v", err)
return false
}
return true
}
// adoptLegacyCheckinOff puts every heir of a legacy entry in
// settings.CheckinOff in its place; it says whether the settings are as
// they should be now.
func adoptLegacyCheckinOff(heirs map[string][]string) bool {
s, err := settings.LoadChecked()
if err != nil {
return false
}
if !slices.ContainsFunc(s.CheckinOff, func(k string) bool { _, ok := heirs[k]; return ok }) {
return true
}
err = settings.EditCheckinOff(func(off []string) []string {
var out []string
for _, k := range off {
ks, ok := heirs[k]
if !ok {
ks = []string{k}
}
for _, k := range ks {
if !slices.Contains(out, k) {
out = append(out, k)
}
}
}
return out
})
if err != nil {
log.Printf("plugin check-in: %v", err)
return false
}
return true
}
// pluginChecksIn says whether pp's plugin presses the check-in itself:
// magpie's own check-in through its fetch leaves its accounts to it.
func pluginChecksIn(pp plugin.Provider) bool { return pp.Checkin }
+254
View File
@@ -2,6 +2,7 @@ package provider
import (
"context"
"encoding/json"
"os"
"path/filepath"
"slices"
@@ -224,3 +225,256 @@ func TestPluginCheckinTakesOverTheVendors(t *testing.T) {
}
}
}
// pluginCheckinTeams is the fake plugin with its own check-in, signed in
// through its browser sign-in as each team (name/uid): the reporter's case
// in plugins#254 is two AutoClaw display names with two sign-ins each,
// told apart only by their uid. It says the file each press is written to,
// as name@fake/uid, and each team's sign-in key.
func pluginCheckinTeams(t *testing.T, teams ...string) (string, map[string]string) {
t.Helper()
presses := pluginCheckinSandbox(t)
for _, team := range teams {
st, err := StartPluginSignIn("fakeco", 1, map[string]string{"where": "work", "team": team})
if err != nil {
t.Fatal(err)
}
if err := SubmitSignInCallback(st.ID, "good"); err != nil {
t.Fatal(err)
}
}
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()
if _, err := plugin.Providers(ctx); err != nil {
t.Fatal(err)
}
keys := map[string]string{} // name@fake/uid → its sign-in's key
for k, a := range plugin.Auths("fakeco") {
id, _ := a["accountId"].(string)
uid, _ := a["uid"].(string)
keys[id+"/"+uid] = k
}
if len(keys) != len(teams) {
t.Fatalf("signed in as %v, want %d sign-ins", keys, len(teams))
}
return presses, keys
}
// pluginCheckinOn turns fakeco's daily check-in on.
func pluginCheckinOn(t *testing.T) {
t.Helper()
s := settings.Load()
s.PluginCheckins = map[string]bool{"fakeco": true}
if err := settings.Save(s); err != nil {
t.Fatal(err)
}
}
// pluginCards are a card for each of p's accounts, as the Usage page has.
func pluginCards(p pluginCheckinProvider) []SubscriptionQuota {
var qs []SubscriptionQuota
for _, a := range p.accounts {
qs = append(qs, SubscriptionQuota{Provider: PluginID(p.ID), User: a.User})
}
return qs
}
// Two sign-ins of one plugin that share a display name are two accounts
// to check in (plugins#254: four AutoClaw sign-ins under two default
// names, which AutoClaw doesn't let the user change, and only the first of
// each name was ever checked in, by the loop or Check in now). Each is
// checked in once a day, kept, carded and switched off on its own.
func TestPluginCheckinTellsSignInsOfOneNameApart(t *testing.T) {
presses, keys := pluginCheckinTeams(t, "A/u1", "A/u2", "B/u3", "B/u4")
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()
pluginCheckinOn(t)
ps := pluginCheckinProviders()
if len(ps) != 1 || len(ps[0].accounts) != 4 {
t.Fatalf("the plugins that check in: %+v", ps)
}
now := time.Date(2026, 10, 6, 10, 0, 0, 0, beijing)
loop := pluginCheckiner{now: func() time.Time { return now }, only: func(id string) bool { return PluginCheckinOn(settings.Load(), id) }}
all := "A@fake/u1,A@fake/u2,B@fake/u3,B@fake/u4"
sorted := func(p []string) string { return strings.Join(slices.Sorted(slices.Values(p)), ",") }
if rs := loop.checkinNow(ctx, false); len(rs) != 4 || sorted(pressed(t, presses)) != all {
t.Fatalf("the loop: %+v, pressed %q", rs, pressed(t, presses))
}
// kept for each: nothing asked again that day
now = now.Add(time.Minute)
if rs := loop.checkinNow(ctx, false); len(rs) != 4 || len(pressed(t, presses)) != 4 {
t.Fatalf("a minute on: %+v, pressed %q", rs, pressed(t, presses))
}
st := readCheckins(pluginCheckinPath())
for who, k := range keys {
if r, ok := st[pluginCheckinKey("fakeco", k)]; !ok || r.Day != "2026-10-06" || r.Outcome != CheckinInactive {
t.Errorf("%s (%s) kept as %+v, ok %v; file %+v", who, k, r, ok, st)
}
}
if len(st) != 4 {
t.Errorf("plugin-checkin.json holds %d entries, want 4: %+v", len(st), st)
}
// Settings lists each, and each card says today's
if pcs := PluginCheckins(); len(pcs) != 1 || len(pcs[0].Checkins) != 4 {
t.Fatalf("PluginCheckins = %+v", pcs)
}
for i, q := range WithCheckins(pluginCards(ps[0])) {
if !q.Checkins || q.Checkin == nil || q.Checkin.Day != "2026-10-06" {
t.Fatalf("card %d (%s): %+v", i, q.User, q.Checkin)
}
}
// each its own row in Settings, and one switched off is left out
var rows []string
for _, a := range CheckinAccounts() {
if a.By == "plugin:fakeco" {
rows = append(rows, a.Key)
}
}
if len(rows) != 4 {
t.Fatalf("Settings' rows: %q", rows)
}
s := settings.Load()
s.CheckinOff = []string{pluginCheckinKey("fakeco", keys["A@fake/u2"])}
if err := settings.Save(s); err != nil {
t.Fatal(err)
}
// Check in now, the next day: each but the one switched off
now = time.Date(2026, 10, 7, 9, 0, 0, 0, beijing)
press := pluginCheckiner{now: func() time.Time { return now }, only: func(id string) bool { return id == "fakeco" }}
press.checkinNow(ctx, true)
if p := sorted(pressed(t, presses)[4:]); p != "A@fake/u1,B@fake/u3,B@fake/u4" {
t.Fatalf("Check in now with A@fake/u2 off pressed %q", p)
}
for _, q := range WithCheckins(pluginCards(ps[0])) {
if q.CheckinOff != (q.User == userOf(ps[0], keys["A@fake/u2"])) {
t.Fatalf("card %s: off %v", q.User, q.CheckinOff)
}
}
}
// userOf is the name the account signed in under key is shown by.
func userOf(p pluginCheckinProvider, key string) string {
for _, a := range p.accounts {
if a.key == pluginCheckinKey(p.ID, key) {
return a.User
}
}
return ""
}
// An upgrade from a plugin-checkin.json kept by display name (before
// plugins#254) checks no account in twice and keeps the user's own Off: a
// name checked in today is carried to the one sign-in the old key asked,
// the first in use, so only its namesake is asked; a name switched off
// stays off for each sign-in of it; another vendor's Off is left alone.
func TestPluginCheckinCarriesOverDisplayNameEntries(t *testing.T) {
presses, keys := pluginCheckinTeams(t, "A/u1", "A/u2", "B/u3", "B/u4")
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()
now := time.Date(2026, 10, 6, 10, 0, 0, 0, beijing)
legacy := map[string]WorkBuddyCheckin{
"fakeco|A@fake": {Day: "2026-10-06", At: now.Add(-time.Hour), Outcome: CheckinClaimed, Credit: 400},
"fakeco|B@fake": {Day: "2026-10-06", At: now.Add(-time.Hour), Outcome: CheckinClaimed, Credit: 400},
// another plugin's, whose accounts aren't signed in: left as kept
"other|C": {Day: "2026-10-05", At: now.Add(-25 * time.Hour), Outcome: CheckinDone},
}
b, _ := json.Marshal(legacy)
if err := os.WriteFile(pluginCheckinPath(), b, 0o600); err != nil {
t.Fatal(err)
}
s := settings.Load()
s.PluginCheckins = map[string]bool{"fakeco": true}
s.CheckinOff = []string{"workbuddy|123", "fakeco|B@fake"}
if err := settings.Save(s); err != nil {
t.Fatal(err)
}
ps := pluginCheckinProviders()
if len(ps) != 1 || len(ps[0].accounts) != 4 {
t.Fatalf("the plugins that check in: %+v", ps)
}
// the sign-in of A the old key asked: the first of A's in use
var heir, namesake string
for _, a := range ps[0].accounts {
if a.legacy == "fakeco|A@fake" && a.On {
if heir == "" {
heir = a.key
} else if namesake == "" {
namesake = a.key
}
}
}
if heir == "" || namesake == "" {
t.Fatalf("A's sign-ins: %+v", ps[0].accounts)
}
st := readCheckins(pluginCheckinPath())
if r, ok := st[heir]; !ok || r.Outcome != CheckinClaimed || r.Credit != 400 || r.Day != "2026-10-06" {
t.Fatalf("A's check-in went to %s as %+v (ok %v): %+v", heir, r, ok, st)
}
if _, ok := st[namesake]; ok {
t.Fatalf("A's check-in was carried to both its sign-ins: %+v", st)
}
if _, ok := st["fakeco|A@fake"]; ok {
t.Fatalf("A's old entry was kept: %+v", st)
}
if _, ok := st["other|C"]; !ok {
t.Fatalf("another plugin's entry went: %+v", st)
}
off := settings.Load().CheckinOff
want := []string{"workbuddy|123", pluginCheckinKey("fakeco", keys["B@fake/u3"]), pluginCheckinKey("fakeco", keys["B@fake/u4"])}
if !slices.Equal(slices.Sorted(slices.Values(off)), slices.Sorted(slices.Values(want))) {
t.Fatalf("CheckinOff = %q, want %q", off, want)
}
// the loop asks only A's namesake: the heir is in, B's are off
loop := pluginCheckiner{now: func() time.Time { return now }, only: func(id string) bool { return PluginCheckinOn(settings.Load(), id) }}
loop.checkinNow(ctx, false)
var who string
for w, k := range keys {
if pluginCheckinKey("fakeco", k) == namesake {
who = w
}
}
if p := pressed(t, presses); len(p) != 1 || p[0] != who {
t.Fatalf("after the upgrade pressed %q, want only %s", p, who)
}
// and nothing is carried again, or asked again, on the next look
pluginCheckinProviders()
loop.checkinNow(ctx, false)
if p := pressed(t, presses); len(p) != 1 {
t.Fatalf("a second look pressed %q", p)
}
for _, a := range CheckinAccounts() {
if a.By == "plugin:fakeco" && a.On == strings.HasPrefix(a.User, "B@fake") {
t.Fatalf("Settings' row %+v: B's should be off, A's on", a)
}
}
}
// A plugin-checkin.json that doesn't parse is unknown: nothing is carried
// over or written over, and it is carried once it reads.
func TestPluginCheckinCarriesNothingOverAnUnreadableFile(t *testing.T) {
path := filepath.Join(claudeHome(t), "plugin-checkin.json")
order, heirs := []string{"fakeco|A"}, map[string][]string{"fakeco|A": {"fakeco|fakeco", "fakeco|fakeco#x1"}}
bad := []byte(`{"fakeco|A": {"day": "2026-10-06",`)
if err := os.WriteFile(path, bad, 0o600); err != nil {
t.Fatal(err)
}
if adoptLegacyCheckinFile(path, order, heirs) {
t.Fatal("a file that doesn't parse was taken as carried over")
}
if b, _ := os.ReadFile(path); string(b) != string(bad) {
t.Fatalf("the file was written over: %s", b)
}
if err := os.WriteFile(path, []byte(`{"fakeco|A": {"day": "2026-10-06", "outcome": "claimed"}}`), 0o600); err != nil {
t.Fatal(err)
}
if !adoptLegacyCheckinFile(path, order, heirs) {
t.Fatal("not carried once the file reads")
}
st := readCheckins(path)
if _, ok := st["fakeco|fakeco"]; !ok || len(st) != 1 {
t.Fatalf("carried as %+v", st)
}
}
+22 -1
View File
@@ -221,7 +221,10 @@ type Settings struct {
// CheckinOff are the accounts left out of their vendor's daily
// check-in while it is on (#1902), each by its entry in the vendor's
// check-in file: "<site or provider>|<account id>" ("workbuddy|<uid>",
// "trae-cn|<uid>", a plugin's "<provider>|<account>").
// "trae-cn|<uid>", a plugin's "<provider>|<sign-in key>", e.g.
// "autoclaw|autoclaw#x1y2z3"; before plugins#254 a plugin's was
// "<provider>|<display name>", which provider.adoptLegacyPluginCheckins
// carries over).
CheckinOff []string `json:"checkinOff,omitempty"`
// MemberModel has a reply's model name the routing group's member
// that answered, as magpie's provider/model id (workbuddy/glm-5.3-flash),
@@ -1222,6 +1225,24 @@ func SetGatewayConversations(on bool) error {
return save(s, true)
}
// EditCheckinOff changes CheckinOff alone, as edit returns it from what the
// file holds now, so a save elsewhere from an older snapshot isn't undone.
// A settings file that can't be read is left as it is, with the error.
func EditCheckinOff(edit func([]string) []string) error {
fileMu.Lock()
defer fileMu.Unlock()
s, err := loadChecked()
if err != nil {
return err
}
off := edit(slices.Clone(s.CheckinOff))
if len(off) == 0 {
off = nil
}
s.CheckinOff = off
return save(s, false)
}
// SetRedactModel turns the local masking model on or off, on its own, as
// Settings → Privacy does once the model is downloaded.
func SetRedactModel(on bool) error {