checkin: the Qoder plugins' check-in is asked again within the day, as the built-in's was (#2696)
The native Qoder and Qoder CN plugin check-in (pluginCheckinProvider) built
its checkiner without recheck, while the built-in qoderCheckiner set it.
So an inactive or done result was kept for the whole Beijing day, and a
press of "Check in now" was answered from that record too. Qoder CN's
campaign runs 10:00 to 09:59 the next day (mufanmu), so an early read
describes yesterday's campaign and said nothing about today's.
What changed:
- provider: pluginRechecks(id) is true for "qoder" and "qoder-cn" only,
and sets recheck on their checkiner. A press asks at once. The loop asks
again after wbCheckinEvery (30m) for inactive and done. Every other
plugin stays settled for the day.
- GUI (checkinRow): a Qoder account (built-in or plugin) whose check-in
found no campaign today keeps "Check in now". A press reports "Check-in
status refreshed" instead of "Checked in", since it may still find
none. The unused "Checked in" key is replaced in all four languages.
- docs/subsystems/provider-plugins.md names the exception and the tests.
Taken from LoKi's (lokic7123-star) patch on the issue: the recheck on the
Qoder plugin ids, the Check in now button for an inactive Qoder card, and
the neutral press status. Their GUI test was adapted into
qoder-checkin-recheck.test.cjs.
Left out, as the earlier review asked: the blanket 30-minute message, the
UTC timestamps and the client-computed next check. Also left out: the
"Already checked in today" wording and the "· credit" display. That is
not this bug, and the TUI and CLI would need the same change.
Run:
- Red on the old code:
- All 8 subtests of TestPluginCheckinQoderRechecksCampaigns
({qoder,qoder-cn} x {inactive,done} x {loop,press}) fail without
the fix.
- Forcing recheck on for every plugin turns
TestPluginCheckinOthersSettledForTheDay red.
- qoder-checkin-recheck.test.cjs is red on the origin/main assets (no
.ci-now on the card).
- At 91bb01e65 (base 9572a3576):
- Full suite: set -o pipefail; go test -timeout 45m ./... |
tee. EXIT=0, 68 packages ok, run alone on the machine.
- qoder-checkin-recheck.test.cjs passes 20/20: chromium and webkit,
en/zh/zh-TW/ja/de, 900 and 440px.
- 76 GUI files reachable from the change were run: check-in files,
gui-*, i18n-keys and tray-usages. Reds:
- login-import, chromium en/zh: red on main too (#1307).
- quota-reads webkit de 360: red on main too (#2150, commented
with its c.toFixed page error).
- usage-checkin webkit en/zh, Qoder tab: red on main too (#2549).
- update-wait chromium en and usage-alert webkit en: red only
under load, pass alone (#3275).
- At this tree, rebased on 87d703c5c (b91bcf260, library only, came
after). The 8 new main commits since
9572a3576 bring app.js, i18n.js and provider plugin changes; none of
them touches check-in code.
- gofmt -l: clean.
- go vet ./...: clean on darwin, linux (-tags nogui) and windows.
- go test ./internal/provider/ ./internal/gui/ ./internal/plugin/
./internal/cli/: all ok. internal/gui includes TestCoreScriptBudget.
- GUI, both engines: qoder-checkin-recheck, i18n-keys,
plugin-checkin, checkin-account, account-models and
plugin-keyless-signin pass 119/119.
Not tried:
- No real Qoder or Qoder CN account, and no campaign that opens
mid-day.
- The full GUI suite: another session's full GUI run held the machine,
so 76 files were run instead.
- Linux and Windows at runtime.
Reported by mufanmu and LoKi; patch by LoKi.
Co-authored-by: LoKi <317300729+lokic7123-star@users.noreply.github.com>
This commit is contained in:
@@ -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|<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}`). `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. 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}`). `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.
|
||||
|
||||
@@ -196,7 +196,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; `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_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. `TestPluginCheckinQoderRechecksCampaigns` holds the Qoder plugins' recheck, by the loop and a press, after `inactive` and `done`, and `TestPluginCheckinOthersSettledForTheDay` every other plugin's day; `qoder-checkin-recheck.test.cjs` covers the card's press. `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.
|
||||
|
||||
|
||||
@@ -17697,8 +17697,10 @@ function checkinRow(q, first, subs) {
|
||||
}
|
||||
};
|
||||
row.append(auto);
|
||||
// pressed now: shown while an account isn't in today and could be
|
||||
const due = subs.filter((x) => x.checkins && !x.checkinOff && (x.checkinBy || "") === by && !(x.checkin?.day === today && x.checkin.outcome !== "failed"));
|
||||
// pressed now: shown while an account isn't in today and could be; a
|
||||
// Qoder campaign can open later in the day, so its inactive too (#2696)
|
||||
const later = /^(plugin:)?qoder(-cn)?$/.test(by);
|
||||
const due = subs.filter((x) => x.checkins && !x.checkinOff && (x.checkinBy || "") === by && !(x.checkin?.day === today && x.checkin.outcome !== "failed" && !(later && x.checkin.outcome === "inactive")));
|
||||
if (due.length) {
|
||||
const now = el("button", "text ci-now", t("Check in now"));
|
||||
now.type = "button";
|
||||
@@ -17710,7 +17712,7 @@ function checkinRow(q, first, subs) {
|
||||
try {
|
||||
const rs = await api("usage/" + vendor.api, vendor.plugin ? { provider: vendor.plugin } : {});
|
||||
const bad = (rs || []).filter((x) => x.outcome === "failed").length;
|
||||
status(bad ? t("Check-in failed for {n} account(s)", { n: bad }) : t("Checked in"), bad ? "err" : "ok");
|
||||
status(bad ? t("Check-in failed for {n} account(s)", { n: bad }) : t("Check-in status refreshed"), bad ? "err" : "ok");
|
||||
} catch (err) {
|
||||
status(err.message, "err");
|
||||
}
|
||||
|
||||
@@ -1134,7 +1134,7 @@ const I18N = {
|
||||
"Claims each signed-in Qoder account's daily credits once a day": "每天替每个已登录的 Qoder 账号领取一次每日积分",
|
||||
"As claiming the daily credits in Qoder does": "和在 Qoder 里领取每日积分一样",
|
||||
"Check-in failed for {n} account(s)": "{n} 个账号签到失败",
|
||||
"Checked in": "已签到",
|
||||
"Check-in status refreshed": "签到状态已刷新",
|
||||
"Emails, phone numbers, ID and bank card numbers too": "邮箱、手机号、身份证号和银行卡号也一并脱敏",
|
||||
"Social Security numbers": "美国社会安全号",
|
||||
"US SSNs, in the ranges that are given out": "美国 SSN,只认实际会发放的号段",
|
||||
@@ -5003,7 +5003,7 @@ const I18N = {
|
||||
"Claims each signed-in Qoder account's daily credits once a day": "每天替每個已登入的 Qoder 帳號領取一次每日積分",
|
||||
"As claiming the daily credits in Qoder does": "和在 Qoder 裡領取每日積分一樣",
|
||||
"Check-in failed for {n} account(s)": "{n} 個帳號簽到失敗",
|
||||
"Checked in": "已簽到",
|
||||
"Check-in status refreshed": "簽到狀態已重新整理",
|
||||
"Emails, phone numbers, ID and bank card numbers too": "郵箱、手機號、身份證號和銀行卡號也一併脫敏",
|
||||
"Social Security numbers": "美國社會安全碼",
|
||||
"US SSNs, in the ranges that are given out": "美國 SSN,只認實際會發放的號段",
|
||||
@@ -8842,7 +8842,7 @@ const I18N = {
|
||||
"Claims each signed-in Qoder account's daily credits once a day": "サインイン済みの各 Qoder アカウントの毎日のクレジットを 1 日 1 回受け取ります",
|
||||
"As claiming the daily credits in Qoder does": "Qoder で毎日のクレジットを受け取るのと同じです",
|
||||
"Check-in failed for {n} account(s)": "{n} 件のアカウントでチェックインに失敗しました",
|
||||
"Checked in": "チェックイン済み",
|
||||
"Check-in status refreshed": "チェックイン状態を更新しました",
|
||||
"Emails, phone numbers, ID and bank card numbers too": "メールアドレス、電話番号、ID 番号、銀行カード番号もマスクします",
|
||||
"Social Security numbers": "社会保障番号",
|
||||
"US SSNs, in the ranges that are given out": "米国の SSN。実際に発行される範囲のものだけ",
|
||||
@@ -12711,7 +12711,7 @@ const I18N = {
|
||||
"Claims each signed-in Qoder account's daily credits once a day": "Holt einmal täglich die täglichen Credits jedes angemeldeten Qoder-Kontos ab",
|
||||
"As claiming the daily credits in Qoder does": "Wie das Abholen der täglichen Credits in Qoder",
|
||||
"Check-in failed for {n} account(s)": "Check-in für {n} Konto/Konten fehlgeschlagen",
|
||||
"Checked in": "Eingecheckt",
|
||||
"Check-in status refreshed": "Check-in-Status aktualisiert",
|
||||
"Emails, phone numbers, ID and bank card numbers too": "Auch E-Mail-Adressen, Telefonnummern, Ausweis- und Bankkartennummern",
|
||||
"Social Security numbers": "Sozialversicherungsnummern",
|
||||
"US SSNs, in the ranges that are given out": "US-SSNs, nur in den Bereichen, die vergeben werden",
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
// Run with Node's test runner and Playwright on the module path; see README.md.
|
||||
// #2696 (LoKi, mufanmu): a Qoder campaign can open later in the Beijing day,
|
||||
// so magpie asks Qoder's check-in again, the built-in's and the Qoder and
|
||||
// Qoder CN plugins', on a press. A Qoder account whose check-in found no
|
||||
// campaign (inactive) today keeps Check in now on its card, built-in
|
||||
// (checkinBy "qoder") and plugin ("plugin:qoder-cn") alike, and the press
|
||||
// says the check-in was refreshed rather than "Checked in", since it may
|
||||
// still find none. Another vendor's inactive, a plugin's included, is
|
||||
// settled for the day and has no press. After LoKi's patch on the issue.
|
||||
// English, Simplified and Traditional Chinese, Japanese and German, the
|
||||
// window and the panel's 440px; the API is faked here.
|
||||
const assert = require("node:assert/strict");
|
||||
const fs = require("node:fs/promises");
|
||||
const path = require("node:path");
|
||||
const { test } = require("node:test");
|
||||
const { chromium, webkit } = require("playwright");
|
||||
const { watchSettingsReads, settingsDrawn, reach } = require("./reader.cjs");
|
||||
|
||||
const assets = path.resolve(__dirname, "../assets");
|
||||
const today = new Date(Date.now() + 8 * 3600e3).toISOString().slice(0, 10);
|
||||
const card = (provider, name, user, by) => ({
|
||||
provider, name, plan: "Pro", user, windows: [{ name: "Credits", used: 1 }],
|
||||
checkins: true, checkinBy: by, checkin: { user, by, day: today, outcome: "inactive" },
|
||||
});
|
||||
const quotas = () => [
|
||||
card("qoder", "Qoder", "arno", "qoder"),
|
||||
card("plugin:qoder-cn", "Qoder CN", "lei", "plugin:qoder-cn"),
|
||||
card("plugin:fakeco", "FakeCo", "ann", "plugin:fakeco"),
|
||||
card("workbuddy", "WorkBuddy", "lucy", ""),
|
||||
];
|
||||
|
||||
function serve(lang, asked) {
|
||||
const settings = { theme: "light", lang, quotaLeft: false, currency: "usd", qoderCheckin: true, workbuddyCheckin: true, pluginCheckins: { "qoder-cn": true, fakeco: true } };
|
||||
return async (route) => {
|
||||
const url = new URL(route.request().url());
|
||||
const json = (data) => route.fulfill({ json: data });
|
||||
if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:true};` });
|
||||
if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
|
||||
if (url.pathname === "/api/state") return json({ agents: [], profiles: [], settings });
|
||||
if (url.pathname === "/api/settings") return json(settings);
|
||||
if (url.pathname === "/api/usage/qoder-checkin" || url.pathname === "/api/usage/plugin-checkin") {
|
||||
asked.push([url.pathname, route.request().postDataJSON()]);
|
||||
return json([{ outcome: "inactive" }]);
|
||||
}
|
||||
if (url.pathname === "/api/providers") return json({ providers: [], presets: [], excluded: [], gateway: { running: true, window: true } });
|
||||
if (url.pathname === "/api/usage/quotas") return json(quotas());
|
||||
if (url.pathname === "/api/groups") return json({ groups: [], models: [] });
|
||||
if (url.pathname === "/api/plugins") return json({ plugins: [] });
|
||||
if (url.pathname.startsWith("/api/")) return json({});
|
||||
const file = path.join(assets, url.pathname === "/" ? "index.html" : url.pathname);
|
||||
const contentType = { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".png": "image/png" }[path.extname(file)];
|
||||
try { await route.fulfill({ body: await fs.readFile(file), contentType }); } catch { await route.fulfill({ status: 404, body: "" }); }
|
||||
};
|
||||
}
|
||||
|
||||
const refreshed = { en: "Check-in status refreshed", zh: "签到状态已刷新", "zh-TW": "簽到狀態已重新整理", ja: "チェックイン状態を更新しました", de: "Check-in-Status aktualisiert" };
|
||||
|
||||
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
||||
for (const lang of ["en", "zh", "zh-TW", "ja", "de"]) {
|
||||
for (const width of [900, 440]) {
|
||||
test(`${engine} ${lang} ${width}px: an inactive Qoder check-in can be pressed again`, async (t) => {
|
||||
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
||||
t.after(() => browser.close());
|
||||
const page = await (await browser.newContext({ viewport: { width, height: 900 }, reducedMotion: "reduce" })).newPage();
|
||||
page.setDefaultTimeout(5000);
|
||||
const errors = [], asked = [];
|
||||
page.on("pageerror", (e) => errors.push(e.message));
|
||||
await page.route("**/*", serve(lang, asked));
|
||||
await watchSettingsReads(page);
|
||||
await page.goto("http://magpie.test/?view=usage");
|
||||
await settingsDrawn(page);
|
||||
const of = (name) => page.locator(".subscription-card", { hasText: name });
|
||||
// each card by its account: "Qoder" is in Qoder CN's name too
|
||||
for (const user of ["arno", "lei", "ann", "lucy"]) await of(user).locator(".wb-checkin").first().waitFor();
|
||||
assert.equal(await of("ann").locator(".ci-now").count(), 0, "another plugin's inactive is settled for the day");
|
||||
assert.equal(await of("lucy").locator(".ci-now").count(), 0, "another vendor's inactive is settled for the day");
|
||||
|
||||
for (const [user, want] of [
|
||||
["arno", ["/api/usage/qoder-checkin", {}]],
|
||||
["lei", ["/api/usage/plugin-checkin", { provider: "qoder-cn" }]],
|
||||
]) {
|
||||
const now = of(user).locator(".ci-now");
|
||||
assert.equal(await now.count(), 1, user + "'s inactive Qoder check-in has Check in now");
|
||||
asked.length = 0;
|
||||
await page.evaluate(() => { document.querySelector("#status").textContent = ""; });
|
||||
await reach(page, now);
|
||||
await now.click();
|
||||
await page.waitForFunction((want) => document.querySelector("#status")?.textContent === want, refreshed[lang]);
|
||||
assert.deepEqual(asked, [want]);
|
||||
}
|
||||
assert.ok(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth), "no sideways scroll");
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -258,8 +258,16 @@ func PluginCheckinOn(s settings.Settings, id string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// pluginRechecks says whether a plugin provider's check-in is asked again
|
||||
// within the Beijing day, as magpie's own Qoder check-in is (recheck):
|
||||
// a campaign can open mid-day (Qoder CN's ran 10:00 to 09:59 the next
|
||||
// day), so a done or inactive read before then said nothing about the
|
||||
// day's own and was kept all day, a press too (#2696). Every other
|
||||
// plugin is settled for the day.
|
||||
func pluginRechecks(id string) bool { return id == "qoder" || id == QoderCNID }
|
||||
|
||||
func (p pluginCheckinProvider) checkiner(now func() time.Time) checkiner {
|
||||
return checkiner{path: pluginCheckinPath(), now: now, mu: &pluginCheckinMu, by: pluginCheckinBy(p.ID), label: p.ID, accounts: func() []checkinAcct {
|
||||
return checkiner{path: pluginCheckinPath(), now: now, mu: &pluginCheckinMu, by: pluginCheckinBy(p.ID), label: p.ID, recheck: pluginRechecks(p.ID), accounts: func() []checkinAcct {
|
||||
var out []checkinAcct
|
||||
for _, a := range p.accounts {
|
||||
out = append(out, checkinAcct{User: a.User, On: a.On, key: a.key, provider: a.card, do: a.do})
|
||||
|
||||
@@ -478,3 +478,87 @@ func TestPluginCheckinCarriesNothingOverAnUnreadableFile(t *testing.T) {
|
||||
t.Fatalf("carried as %+v", st)
|
||||
}
|
||||
}
|
||||
|
||||
// pluginCheckinCounter is a plugin provider with one account whose
|
||||
// check-in answers what *outcome holds and counts the asks in *calls.
|
||||
func pluginCheckinCounter(id string, outcome *string, calls *int) pluginCheckinProvider {
|
||||
return pluginCheckinProvider{ID: id, accounts: []pluginCheckinAcct{{User: "ann", On: true, key: id + "|ann", card: id, do: func(context.Context) WorkBuddyCheckin {
|
||||
*calls++
|
||||
return WorkBuddyCheckin{Outcome: *outcome}
|
||||
}}}}
|
||||
}
|
||||
|
||||
// #2696 (LoKi, mufanmu): the Qoder plugins' check-in is rechecked as
|
||||
// magpie's own Qoder check-in is. A campaign can open mid-day, so a done or
|
||||
// inactive read before it was kept for the whole Beijing day, even on a
|
||||
// press. Now the loop asks again 30 minutes after the last answer, not
|
||||
// before, and a press asks at once.
|
||||
func TestPluginCheckinQoderRechecksCampaigns(t *testing.T) {
|
||||
for _, id := range []string{"qoder", QoderCNID} {
|
||||
for _, first := range []string{CheckinInactive, CheckinDone} {
|
||||
// each: wait this long, press or not, then the outcome shown
|
||||
// and the asks so far
|
||||
type step struct {
|
||||
wait time.Duration
|
||||
press bool
|
||||
want string
|
||||
wantCalls int
|
||||
}
|
||||
for name, steps := range map[string][]step{
|
||||
"loop": {
|
||||
{0, false, first, 1},
|
||||
{29 * time.Minute, false, first, 1},
|
||||
{time.Minute, false, CheckinClaimed, 2},
|
||||
{29 * time.Minute, false, CheckinClaimed, 2},
|
||||
{time.Minute, false, CheckinClaimed, 3}, // a claim is rechecked too
|
||||
},
|
||||
"press": {
|
||||
{0, false, first, 1},
|
||||
{10 * time.Minute, true, CheckinClaimed, 2},
|
||||
{0, false, CheckinClaimed, 2}, // the loop keeps what the press read
|
||||
{0, true, CheckinClaimed, 3},
|
||||
},
|
||||
} {
|
||||
t.Run(id+"/"+first+"/"+name, func(t *testing.T) {
|
||||
claudeHome(t)
|
||||
now := time.Date(2026, 10, 18, 1, 0, 0, 0, time.UTC) // 09:00 Beijing
|
||||
outcome, calls := first, 0
|
||||
p := pluginCheckinCounter(id, &outcome, &calls)
|
||||
for i, s := range steps {
|
||||
now = now.Add(s.wait)
|
||||
got := p.checkiner(func() time.Time { return now }).checkinNow(context.Background(), s.press)
|
||||
if len(got) != 1 || got[0].Outcome != s.want || calls != s.wantCalls {
|
||||
t.Fatalf("step %d (press=%v at %s): got %+v after %d asks; want %s after %d", i, s.press, now.Format(time.TimeOnly), got, calls, s.want, s.wantCalls)
|
||||
}
|
||||
outcome = CheckinClaimed
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Every other plugin's check-in is settled for the Beijing day: neither
|
||||
// the loop after 30 minutes nor a press asks again (#2696 changes Qoder's
|
||||
// alone).
|
||||
func TestPluginCheckinOthersSettledForTheDay(t *testing.T) {
|
||||
for _, first := range []string{CheckinInactive, CheckinDone, CheckinClaimed} {
|
||||
t.Run(first, func(t *testing.T) {
|
||||
claudeHome(t)
|
||||
now := time.Date(2026, 10, 18, 1, 0, 0, 0, time.UTC)
|
||||
outcome, calls := first, 0
|
||||
p := pluginCheckinCounter("fakeco", &outcome, &calls)
|
||||
p.checkiner(func() time.Time { return now }).checkinNow(context.Background(), false)
|
||||
outcome = CheckinClaimed
|
||||
for _, step := range []time.Duration{31 * time.Minute, 5 * time.Hour} {
|
||||
now = now.Add(step)
|
||||
for _, press := range []bool{false, true} {
|
||||
got := p.checkiner(func() time.Time { return now }).checkinNow(context.Background(), press)
|
||||
if len(got) != 1 || got[0].Outcome != first || calls != 1 {
|
||||
t.Fatalf("press=%v at %s: got %+v after %d asks; want %s kept after 1", press, now, got, calls, first)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user