plugin: a check-in outcome magpie doesn't know names what the plugin said
A plugin check-in that answered an outcome not in the list, with a message, became failed with the plugin's message alone, so "the daily credits were refreshed" read as magpie's own failure reason. The reason now names the answer first: the plugin answered "yes": <message>. With no message it stays "the plugin answered no outcome" or the answer. Split out of skygunner's fix/usage-absent-used branch (#3650), which carried it beside the usage fix. Run: go test ./internal/provider -run TestPluginCheckinRunsAsTheBuiltinsDo ok. Broken by hand: host.js's old line makes it red (Msg was the message alone). Not tried: a real plugin answering an unknown outcome. Co-authored-by: skygunner <skygunner@users.noreply.github.com>
This commit is contained in:
@@ -50,7 +50,7 @@ A plugin whose vendor counts no cache tokens says so with `usage.magpie_cache_un
|
||||
|
||||
A plugin can press its vendor's daily check-in (签到) itself: its `auth` hook gains `checkin(getAuth, provider)`, beside `usage`. The host lists the provider with `checkin: true` (`plugin.Provider.Checkin`) and answers `checkin({provider, account})` (`plugin.AccountCheckin`) by refreshing the account as `usage` does and calling the hook with the account's auth.
|
||||
|
||||
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. An `inactive` or `ineligible` result with a `message` shows it beside the fixed label ("No check-in event now · <message>") on the card, where it wraps rather than ends in "…", in Settings' check-in line and in `magpie accounts checkin`; the TUI's narrow cell says `c` says why, and `c`'s flash carries it (plugins#304). Without a message the label reads alone.
|
||||
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; for an outcome not in the list the reason names what the plugin answered, before its own message (`the plugin answered "yes": …`), so a plugin's wording isn't read as magpie's. `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. An `inactive` or `ineligible` result with a `message` shows it beside the fixed label ("No check-in event now · <message>") on the card, where it wraps rather than ends in "…", in Settings' check-in line and in `magpie accounts checkin`; the TUI's narrow cell says `c` says why, and `c`'s flash carries it (plugins#304). Without a message the label reads alone.
|
||||
|
||||
[`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. A `done`, `inactive` or `ineligible` answered before noon Beijing (`checkinSureHour`) for an account magpie hasn't seen claim that Beijing day is provisional (`provisional`, #3326): a vendor whose day turns at UTC midnight (08:00 Beijing) or later still answers yesterday's "already" at 00:00, and magpie took it for today's and never asked again. The loop asks it again 30 minutes after the answer, until a claim or an answer from noon on, so at most 24 more asks a day and none once magpie claims; a press (`soon`) asks it again at once, whatever the hour, since the vendor's answer is what the press is for. A claim stamps `Claimed`, carried over while later answers that day say done, so a done after magpie's own claim is settled. Such a record is sent with `again: true` (`shown`, never kept), and the card, Settings, TUI and CLI say the vendor said already checked in and magpie asks again later, not "Checked in today", and the card keeps *Check in now*. A vendor whose day turns after noon Beijing (a US day) is not covered. The Qoder and Qoder CN plugins are the exception, as magpie's own Qoder check-in is (`recheck`, `pluginRechecks`, #2696): a campaign can open mid-day (Qoder CN's ran 10:00 to 09:59 the next day), so the loop asks again 30 minutes after the last answer whatever it was, and *Check in now* asks at once, and their card keeps *Check in now* for an `inactive` result. Every other plugin keeps the day's result. 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; until then no plugin account is checked in, and each says why (`readCheckins`, as for every vendor's check-in file). 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}`). The press says what it came to, a count per kind (`checkinPressSaid`, #3326): claimed now with the credits, already checked in today, not available yet (`inactive`, `ineligible`, or an `again` answer), to check in in the vendor's own app, failed; a result is claimed now only when it carries `asked` (`Asked`, sent but never kept), so an account claimed earlier today counts as already. `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`.
|
||||
|
||||
|
||||
@@ -2478,7 +2478,8 @@ async function checkinOf(provider, account) {
|
||||
const num = (v) => (typeof v === "number" && isFinite(v) ? Math.max(0, v) : 0)
|
||||
const message = typeof r.message === "string" ? r.message : ""
|
||||
if (!checkinOutcomes.includes(r.outcome)) {
|
||||
return { outcome: "failed", credit: 0, streak: 0, message: message || `the plugin answered no outcome (${JSON.stringify(r.outcome ?? null)})` }
|
||||
const said = r.outcome === undefined || r.outcome === null ? "no outcome" : JSON.stringify(r.outcome)
|
||||
return { outcome: "failed", credit: 0, streak: 0, message: message ? `the plugin answered ${said}: ${message}` : `the plugin answered ${said}` }
|
||||
}
|
||||
return { outcome: r.outcome, credit: num(r.credit), streak: Math.round(num(r.streak)), message }
|
||||
}
|
||||
|
||||
+1
-1
@@ -268,7 +268,7 @@ export const FakePlugin = async ({ client }) => ({
|
||||
case "ck-throw":
|
||||
throw new Error("FakeCo's check-in is down")
|
||||
case "ck-odd":
|
||||
return { outcome: "yes" }
|
||||
return { outcome: "yes", message: "the daily credits were refreshed" }
|
||||
}
|
||||
return { outcome: "inactive" }
|
||||
},
|
||||
|
||||
@@ -113,13 +113,18 @@ func TestPluginCheckinRunsAsTheBuiltinsDo(t *testing.T) {
|
||||
}
|
||||
failed := 0
|
||||
for k := range got {
|
||||
if strings.Contains(k, "check-in is down") || strings.Contains(k, "no outcome") {
|
||||
if strings.Contains(k, "check-in is down") || strings.Contains(k, "the plugin answered") {
|
||||
failed++
|
||||
}
|
||||
}
|
||||
if failed != 2 {
|
||||
t.Fatalf("the failures (ck-throw, ck-odd): %+v", rs)
|
||||
}
|
||||
// an outcome magpie doesn't know keeps the plugin's message, marked as
|
||||
// the plugin's own word, so "failed" can't read as contradicting it (#3650)
|
||||
if _, ok := got[CheckinFailed+`:the plugin answered "yes": the daily credits were refreshed`]; !ok {
|
||||
t.Fatalf("ck-odd's message: %+v", rs)
|
||||
}
|
||||
if p := pressed(t, presses); len(p) != len(keys) {
|
||||
t.Fatalf("pressed %q", p)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user