readCheckins, the reader every daily check-in shares (WorkBuddy, Trae CN,
MiniMax Code, Qoder and the plugins' own), took a file it couldn't read
or parse as empty. The next check-in then asked the vendor again for
every account and wrote its answers over the file: an account could be
checked in twice in one day, and the entries it couldn't read were lost.
readCheckins now returns an error for a file that is there but can't be
read, or doesn't parse into entries (cut short, zeroed, empty, `[]`,
`null`). A file not there is still empty. On the error:
- checkiner.checkinNow asks nothing and writes nothing. Each account it
would look at is `failed` with the reason (the path and why), so the
loop tries again after 30 minutes and a press (GUI, TUI, `magpie
accounts checkin`) says why. The error is logged once while it stays
the same.
- The readers that only show results (WithCheckins, *Checkins(),
PluginCheckins) go through shownCheckins, which gives what last read
from the file in this process, so a card keeps its last good data.
- adoptLegacyPluginCheckins' own strict copy of the read now uses
readCheckins too.
Docs: providers-accounts.md no longer lists check-in marks among the
caches written over; provider-plugins.md says the plugin file's case.
Test: TestCheckinUnreadableFileLeftAlone writes a cut-short, zeroed,
empty, `[]` and `null` workbuddy-checkin.json, runs the loop and a press
against a fake WorkBuddy, and checks no status or claim request went out,
the file is byte for byte unchanged, and the result says the path; a
folder in place of plugin-checkin.json does the same through a plugin
checkiner. TestCheckinMissingFileIsEmpty and
TestCheckinUnreadableKeepsLastGood cover the other two sides.
Broken by hand (checkinNow taking the error as an empty map again): the
test went red, every case claimed (Asked true), and green once restored.
Run in a worktree at origin/main 62a1df801, sandbox HOME (testenv):
- gofmt -l . : clean
- go vet ./... (darwin), GOOS=linux go vet -tags nogui ./...,
GOOS=windows go vet ./... : all exit 0
- set -o pipefail; go test -timeout 45m ./... : exit 0, 68 packages ok,
none failed (internal/gateway 613s, internal/agent 529s,
internal/provider 262s)
No red seen, so no issue filed.
481 lines
17 KiB
Go
481 lines
17 KiB
Go
package provider
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"os"
|
|
"path/filepath"
|
|
"slices"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/yetone/magpie/internal/plugin"
|
|
"github.com/yetone/magpie/internal/settings"
|
|
"github.com/yetone/magpie/internal/testenv"
|
|
)
|
|
|
|
// pluginCheckinSandbox is the fake plugin with its own check-in, signed in
|
|
// with each key; it says the file each press is written to.
|
|
func pluginCheckinSandbox(t *testing.T, keys ...string) string {
|
|
t.Helper()
|
|
bun := testenv.Bun(t)
|
|
home := claudeHome(t)
|
|
t.Setenv("MAGPIE_BUN", bun)
|
|
presses := filepath.Join(home, "presses")
|
|
t.Setenv("FAKE_CHECKIN", presses)
|
|
t.Cleanup(plugin.Settle)
|
|
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
|
|
defer cancel()
|
|
abs, _ := filepath.Abs("../plugin/testdata/fake/index.js")
|
|
if _, err := plugin.Add(ctx, abs); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, err := plugin.Providers(ctx); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for _, k := range keys {
|
|
if _, err := PluginAPIKey(ctx, "fakeco", 0, nil, k); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
return presses
|
|
}
|
|
|
|
// pressed is the keys the plugin's check-in was pressed for, in order.
|
|
func pressed(t *testing.T, file string) []string {
|
|
t.Helper()
|
|
b, err := os.ReadFile(file)
|
|
if os.IsNotExist(err) {
|
|
return nil
|
|
}
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
return strings.Fields(string(b))
|
|
}
|
|
|
|
// A plugin's own check-in (auth.checkin; Lemon on Discord) runs as magpie's
|
|
// own do: each account once a Beijing day while it is on, a failure asked
|
|
// again after wbCheckinRetry, a captcha left for the user (never retried
|
|
// that day), and what came of each kept, on its card and in Settings.
|
|
func TestPluginCheckinRunsAsTheBuiltinsDo(t *testing.T) {
|
|
keys := []string{"ck-claim", "ck-done", "ck-captcha", "ck-throw", "ck-odd"}
|
|
presses := pluginCheckinSandbox(t, keys...)
|
|
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
|
|
defer cancel()
|
|
|
|
ps := pluginCheckinProviders()
|
|
if len(ps) != 1 || ps[0].ID != "fakeco" || ps[0].Name != "FakeCo" || len(ps[0].accounts) != len(keys) {
|
|
t.Fatalf("the plugins that check in: %+v", ps)
|
|
}
|
|
if !HasPluginCheckin() {
|
|
t.Fatal("HasPluginCheckin is false")
|
|
}
|
|
|
|
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) }}
|
|
|
|
// off (as it is by default): nothing pressed
|
|
if rs := loop.checkinNow(ctx, false); len(rs) != 0 || len(pressed(t, presses)) != 0 {
|
|
t.Fatalf("while off: %+v, pressed %q", rs, pressed(t, presses))
|
|
}
|
|
s := settings.Load()
|
|
s.PluginCheckins = map[string]bool{"fakeco": true}
|
|
if err := settings.Save(s); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
rs := loop.checkinNow(ctx, false)
|
|
if len(rs) != len(keys) {
|
|
t.Fatalf("on: %d answers, want %d: %+v", len(rs), len(keys), rs)
|
|
}
|
|
// by what each answered: one account per key
|
|
got := map[string]WorkBuddyCheckin{}
|
|
for _, r := range rs {
|
|
if r.By != "plugin:fakeco" || r.Vendor != "FakeCo" || !r.Asked || r.Day != "2026-10-06" {
|
|
t.Fatalf("an answer: %+v", r)
|
|
}
|
|
k := r.Outcome
|
|
if k == CheckinFailed {
|
|
k += ":" + r.Msg
|
|
}
|
|
got[k] = r
|
|
}
|
|
if r := got[CheckinClaimed]; r.Credit != 50 || r.Streak != 3 {
|
|
t.Fatalf("ck-claim: %+v (%+v)", r, rs)
|
|
}
|
|
if r := got[CheckinDone]; r.Credit != 50 {
|
|
t.Fatalf("ck-done: %+v (%+v)", r, rs)
|
|
}
|
|
if r := got[CheckinCaptcha]; r.Msg != "slide the puzzle" {
|
|
t.Fatalf("ck-captcha: %+v (%+v)", r, rs)
|
|
}
|
|
failed := 0
|
|
for k := range got {
|
|
if strings.Contains(k, "check-in is down") || strings.Contains(k, "no outcome") {
|
|
failed++
|
|
}
|
|
}
|
|
if failed != 2 {
|
|
t.Fatalf("the failures (ck-throw, ck-odd): %+v", rs)
|
|
}
|
|
if p := pressed(t, presses); len(p) != len(keys) {
|
|
t.Fatalf("pressed %q", p)
|
|
}
|
|
|
|
// a minute on: nothing asked again, each answered as kept
|
|
now = now.Add(time.Minute)
|
|
if rs := loop.checkinNow(ctx, false); len(rs) != len(keys) || len(pressed(t, presses)) != len(keys) {
|
|
t.Fatalf("a minute on: %+v, pressed %q", rs, pressed(t, presses))
|
|
}
|
|
// past wbCheckinRetry: the failures only, not the captcha
|
|
now = now.Add(wbCheckinRetry)
|
|
loop.checkinNow(ctx, false)
|
|
if p := pressed(t, presses)[len(keys):]; strings.Join(slices.Sorted(slices.Values(p)), ",") != "ck-odd,ck-throw" {
|
|
t.Fatalf("past the retry, pressed again %q", p)
|
|
}
|
|
// the next Beijing day: each again
|
|
now = time.Date(2026, 10, 7, 0, 5, 0, 0, beijing)
|
|
loop.checkinNow(ctx, false)
|
|
if p := pressed(t, presses); len(p) != 2*len(keys)+2 {
|
|
t.Fatalf("the next day, pressed %q", p)
|
|
}
|
|
|
|
// kept, for Settings
|
|
pcs := PluginCheckins()
|
|
if len(pcs) != 1 || pcs[0].ID != "fakeco" || !pcs[0].On || len(pcs[0].Checkins) != len(keys) {
|
|
t.Fatalf("PluginCheckins = %+v", pcs)
|
|
}
|
|
// and on each account's card
|
|
var qs []SubscriptionQuota
|
|
for _, a := range ps[0].accounts {
|
|
qs = append(qs, SubscriptionQuota{Provider: PluginID("fakeco"), User: a.User})
|
|
}
|
|
marked := WithCheckins(qs)
|
|
for i, q := range marked {
|
|
if !q.Checkins || q.CheckinBy != "plugin:fakeco" || q.Checkin == nil || q.Checkin.Day != "2026-10-07" {
|
|
t.Fatalf("card %d: %+v %+v", i, q, q.Checkin)
|
|
}
|
|
}
|
|
if qs[0].Checkins {
|
|
t.Fatal("WithCheckins changed the cards it was given")
|
|
}
|
|
// a press now (Check in now, the CLI) asks the failure again at once,
|
|
// whatever the switch; another provider's press asks none of these
|
|
before := len(pressed(t, presses))
|
|
if rs := CheckInPlugins(ctx, "someone-else"); len(rs) != 0 || len(pressed(t, presses)) != before {
|
|
t.Fatalf("another provider's press: %+v", rs)
|
|
}
|
|
}
|
|
|
|
// A plugin that checks in itself takes over from magpie's own check-in
|
|
// through its fetch, so an account isn't checked in twice; and its switch
|
|
// follows the vendor's, which it took over, until set on its own.
|
|
func TestPluginCheckinTakesOverTheVendors(t *testing.T) {
|
|
bun := testenv.Bun(t)
|
|
claudeHome(t)
|
|
t.Setenv("MAGPIE_BUN", bun)
|
|
t.Setenv("FAKE_ID", "qoder")
|
|
t.Cleanup(plugin.Settle)
|
|
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
|
|
defer cancel()
|
|
abs, _ := filepath.Abs("../plugin/testdata/fake/index.js")
|
|
if _, err := plugin.Add(ctx, abs); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, err := plugin.Providers(ctx); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, err := plugin.APIKey(ctx, "qoder", 0, nil, "ck-claim", plugin.NewAccount); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, err := plugin.Providers(ctx); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
// a plugin without auth.checkin: magpie claims Qoder's credits itself
|
|
if n := len(qoderCheckinAccounts()); n != 1 || HasPluginCheckin() {
|
|
t.Fatalf("without the hook: %d Qoder accounts, plugins that check in %v", n, HasPluginCheckin())
|
|
}
|
|
// with it, the plugin does, and magpie's own lists none
|
|
t.Setenv("FAKE_CHECKIN", filepath.Join(t.TempDir(), "presses"))
|
|
plugin.Restart()
|
|
if _, err := plugin.Providers(ctx); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if n := len(qoderCheckinAccounts()); n != 0 || !HasPluginCheckin() {
|
|
t.Fatalf("with the hook: %d Qoder accounts, plugins that check in %v", n, HasPluginCheckin())
|
|
}
|
|
for _, c := range []struct {
|
|
s settings.Settings
|
|
id string
|
|
want bool
|
|
}{
|
|
{settings.Settings{QoderCheckin: true}, "qoder", true},
|
|
{settings.Settings{QoderCheckin: true}, QoderCNID, true},
|
|
{settings.Settings{QoderCheckin: true, PluginCheckins: map[string]bool{"qoder": false}}, "qoder", false},
|
|
{settings.Settings{WorkBuddyCheckin: true}, "workbuddy", true},
|
|
{settings.Settings{TraeCheckin: true}, TraeCNID, true},
|
|
{settings.Settings{MiniMaxCheckin: true}, MiniMaxCodeGlobalID, true},
|
|
{settings.Settings{QoderCheckin: true}, "fakeco", false},
|
|
{settings.Settings{PluginCheckins: map[string]bool{"fakeco": true}}, "fakeco", true},
|
|
} {
|
|
if got := PluginCheckinOn(c.s, c.id); got != c.want {
|
|
t.Errorf("PluginCheckinOn(%+v, %s) = %v, want %v", c.s, c.id, got, c.want)
|
|
}
|
|
}
|
|
}
|
|
|
|
// 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 := shownCheckins(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 := shownCheckins(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 := shownCheckins(path)
|
|
if _, ok := st["fakeco|fakeco"]; !ok || len(st) != 1 {
|
|
t.Fatalf("carried as %+v", st)
|
|
}
|
|
}
|