check-in: a time of day every daily check-in waits for (times_ang on X)
times_ang asked on X: 可以调整自动签到的时间吗. Before this, the daily
check-in had no time to choose. The loop first looks 2 minutes after start,
asks every 30 minutes, and asks as the Beijing day (UTC+8) turns. So an
account was checked in at the first look after 00:00 Beijing, on whatever
clock the computer kept.
settings.CheckinAt ("15:04", local time) is one time for every check-in:
the built-in WorkBuddy, Trae, MiniMax and Qoder ones and the plugins'
auth.checkin.
- checkinGate puts it on the Beijing day the account is checked in for:
the first HH:MM on the computer's clock at or after that day's start.
- The loop holds each account's first ask of a Beijing day until then,
and wakes at it.
- Within the day nothing changes: a vendor's own turn (a plugin's until),
retries and the before-noon recheck. So a vendor day is never skipped.
- Unset keeps today's behaviour.
- A press (Check in now, `magpie accounts checkin`) is never held.
Where to set it:
- The editor's check-in groups get a Check-in time row (Off/On and a time
box, as the warm-ups do), drawn by checkinnow.js so the core stays in
its budget.
- The Usage card's not-yet line says "checks in from 09:00".
- From the CLI: `magpie settings set checkinAt 09:00`.
Run (on mote unless named):
- go test ./internal/provider ./internal/gui ./internal/tui; settings,
settingsapi and cli.
- The check-in tests again with TZ=UTC and TZ=Pacific/Kiritimati.
- TestCheckinAt*/TestCheckinGate on Windows (win-run).
- TestCoreScriptBudget at the rebased head: 1,533,673 of 1,533,802.
- gofmt; go vet for darwin, linux (nogui) and windows.
- GUI: checkin-at.test.cjs (chromium and webkit, 1100 and 420 wide, en,
zh, zh-TW, ja, de) plus 27 more files the change reaches (check-in,
warm-at, provider-prefs, settings, i18n, gui-de/ja/zh-tw).
New tests, with the zone held in UTC+8 and in UTC-5:
- One ask per Beijing day, at the set time, with no day skipped.
- A press goes ahead of the time.
- A vendor whose day turns at 10:00 gets one ask a day at 20:00.
- Save refuses 25:00.
Broken by hand:
- The gate off: the Beijing 09:00, New York 23:30, press and vendor-day
cases went red.
- The row not drawn: checkin-at 0 of 40.
Not tried:
- Real vendor accounts.
- The real Linux app.
- The whole GUI suite; the full Go suite runs after the tag.
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -55,6 +55,9 @@ func TestSettingsSetGetReset(t *testing.T) {
|
||||
{"redactWords", `["a","b"]`, "a,b"},
|
||||
{"redactWords", "", "[]"},
|
||||
{"codexWarmup", "off", `""`},
|
||||
// the check-in's time of day (times_ang on X), as 09:00
|
||||
{"checkinAt", "9:30", "09:30"},
|
||||
{"checkinAt", "", `""`},
|
||||
{"refusalRetries", "2", "2"},
|
||||
{"otel", `{"enabled":true,"endpoint":"http://127.0.0.1:4318"}`, ""},
|
||||
} {
|
||||
@@ -92,6 +95,7 @@ func TestSettingsRefusesAndWritesNothing(t *testing.T) {
|
||||
{"settings", "set", "usageAlert", "lots"},
|
||||
{"settings", "set", "usageAlert", "200"}, // the save's own range
|
||||
{"settings", "set", "trayUsageEvery", "4"},
|
||||
{"settings", "set", "checkinAt", "25:00"},
|
||||
{"settings", "set", "vision", "nobody/nothing"},
|
||||
{"settings", "set", "otel", `{"bogus":1}`},
|
||||
{"settings", "set", "theme", "--help-me"},
|
||||
|
||||
@@ -18233,7 +18233,9 @@ function checkinRow(q, first, subs) {
|
||||
text = [t("Auto check-in is off for this account"), last].filter(Boolean).join(" · ");
|
||||
} else {
|
||||
kind = on ? "wait" : "";
|
||||
text = [t(on ? "Not checked in yet today" : "Auto check-in is off"), last].filter(Boolean).join(" · ");
|
||||
// and when it will be, with a time of day set (times_ang on X)
|
||||
const at = on && state.settings?.checkinAt ? t("checks in from {at}", { at: state.settings.checkinAt }) : "";
|
||||
text = [t(on ? "Not checked in yet today" : "Auto check-in is off"), at, last].filter(Boolean).join(" · ");
|
||||
}
|
||||
row.dataset.state = kind || "none";
|
||||
const say = el("span", "ci-say");
|
||||
@@ -20051,8 +20053,8 @@ function renderSettings() {
|
||||
$(`#${id}CheckinSegs`).replaceChildren(segs([["off", t("Off")], ["on", t("On")]], s[on] ? "on" : "off", (v) => savePrefs({ ...keep, [on]: v === "on" })));
|
||||
sub.textContent = [say, ...ciLines(s[on + "s"])].filter(Boolean).join(" · ");
|
||||
sub.title = as;
|
||||
list.querySelectorAll(".ci-acct, .ci-now-row").forEach((x) => x.remove());
|
||||
list.append(...checkinAccountRows(s, id === "wb" ? "" : id), ...checkinNowRow(s, id === "wb" ? "" : id));
|
||||
list.querySelectorAll(".ci-acct, .ci-now-row, .ci-at-row").forEach((x) => x.remove());
|
||||
list.append(...checkinAtRow(s, s[on]), ...checkinAccountRows(s, id === "wb" ? "" : id), ...checkinNowRow(s, id === "wb" ? "" : id));
|
||||
}
|
||||
// and the plugins that check in themselves, a group each
|
||||
renderPluginCheckins(s);
|
||||
@@ -22580,7 +22582,7 @@ function renderPluginCheckins(s) {
|
||||
const g = el("div", "list prefs ci-plugin");
|
||||
g.dataset.provider = p.id;
|
||||
g.dataset.feature = "warmups";
|
||||
g.append(row, ...checkinAccountRows(s, "plugin:" + p.id), ...checkinNowRow(s, "plugin:" + p.id));
|
||||
g.append(row, ...checkinAtRow(s, p.on), ...checkinAccountRows(s, "plugin:" + p.id), ...checkinNowRow(s, "plugin:" + p.id));
|
||||
return g;
|
||||
}));
|
||||
// the replaced groups stay gone
|
||||
@@ -22588,6 +22590,15 @@ function renderPluginCheckins(s) {
|
||||
remountProvPrefs();
|
||||
}
|
||||
|
||||
// the time of day every daily check-in asks from (times_ang on X), drawn by checkinnow.js
|
||||
function checkinAtRow(s, on) {
|
||||
if (!on) return [];
|
||||
const row = el("div", "row pref ci-at-row");
|
||||
if (window.ciAtFill) ciAtFill(row, s);
|
||||
else { row.hidden = true; import("./checkinnow.js").then(() => ciAtFill(row, s), () => {}); }
|
||||
return [row];
|
||||
}
|
||||
|
||||
// one account's Check in now (xiaowu_95660), drawn by checkinnow.js
|
||||
function checkinNowRow(s, by) {
|
||||
if (!(s.checkinAccounts || []).some((a) => (a.by || "") === by)) return [];
|
||||
@@ -22672,7 +22683,7 @@ function prefsKeep(s) {
|
||||
trayUsages: s.trayUsages || [],
|
||||
redact: !!s.redact, redactPersonal: !!s.redactPersonal, redactKinds: s.redactKinds || {}, redactWords: s.redactWords || [], redactWordsAnyCase: !!s.redactWordsAnyCase, redactWordsWhole: !!s.redactWordsWhole, redactShape: !!s.redactShape, codexWarmup: s.codexWarmup || "",
|
||||
claudeWarmup: s.claudeWarmup || "", codexWarmAt: s.codexWarmAt || "", claudeWarmAt: s.claudeWarmAt || "",
|
||||
codexWarmAts: warmTimes(s.codexWarmAts, s.codexWarmAt), claudeWarmAts: warmTimes(s.claudeWarmAts, s.claudeWarmAt), workbuddyCheckin: !!s.workbuddyCheckin, traeCheckin: !!s.traeCheckin, minimaxCheckin: !!s.minimaxCheckin, qoderCheckin: !!s.qoderCheckin, noStats: !!s.noStats, noUsageStats: !!s.noUsageStats, signInLinkOnly: !!s.signInLinkOnly,
|
||||
codexWarmAts: warmTimes(s.codexWarmAts, s.codexWarmAt), claudeWarmAts: warmTimes(s.claudeWarmAts, s.claudeWarmAt), workbuddyCheckin: !!s.workbuddyCheckin, traeCheckin: !!s.traeCheckin, minimaxCheckin: !!s.minimaxCheckin, qoderCheckin: !!s.qoderCheckin, checkinAt: s.checkinAt || "", noStats: !!s.noStats, noUsageStats: !!s.noUsageStats, signInLinkOnly: !!s.signInLinkOnly,
|
||||
replyModel: s.replyModel || "", noLoopGuard: !!s.noLoopGuard, claudeLeanPrompt: !!s.claudeLeanPrompt, claudePrintMode: !!s.claudePrintMode, refusalRetries: s.refusalRetries ?? null, retryAfterCap: s.retryAfterCap ?? null,
|
||||
noUpdatePill: !!s.noUpdatePill, noAutoUpdate: !!s.noAutoUpdate, updateEvery: s.updateEvery || 360, autoRestart: !!s.autoRestart, noAutoDownload: !!s.noAutoDownload, updateChannel: s.updateChannel || "",
|
||||
trayUsage: s.trayUsage || "", trayUsageEvery: s.trayUsageEvery || 3, trayNoLogos: !!s.trayNoLogos, trayNoBird: !!s.trayNoBird, trayNoNumber: !!s.trayNoNumber, trayPace: !!s.trayPace, trayNoCost: !!s.trayNoCost, trayWindows: s.trayWindows || {}, vision: s.vision || "", visionEffort: s.visionEffort || "", searcherEffort: s.searcherEffort || "", imageGen: s.imageGen || "", videoGen: s.videoGen || "", imageTimeout: s.imageTimeout || 0, classifyTimeout: s.classifyTimeout || 0, searcher: s.searcher || "", searchFirst: s.searchFirst || "", currency: s.currency || "usd",
|
||||
|
||||
@@ -109,3 +109,30 @@ function checkinNowLine(r, who) {
|
||||
return { bad: true, text: t("Couldn't check in {who}: {why}", { who, why: r?.msg || t("Check-in failed") }) };
|
||||
}
|
||||
}
|
||||
|
||||
// ciAtFill draws the check-in's time of day into row (checkinAt; times_ang
|
||||
// on X): Off asks as each vendor's day starts, On at 09:00 or the time typed.
|
||||
window.ciAtFill = function (row, s) {
|
||||
const at = s.checkinAt || "";
|
||||
const save = (v) => savePrefs({ ...prefsKeep(s), checkinAt: v });
|
||||
const who = el("div", "who");
|
||||
const sub = el("div", "sub", at ? t("From {at} each day, for every vendor's check-in", { at }) : t("As soon as each vendor's day starts"));
|
||||
sub.title = t("A computer asleep then checks in when it wakes.");
|
||||
who.append(el("div", "name", t("Check-in time")), sub);
|
||||
const box = el("div", "warm-at" + (at ? " times" : ""));
|
||||
if (at) {
|
||||
const i = input(at, "09:00", "time");
|
||||
i.className = "at";
|
||||
i.setAttribute("aria-label", t("Time of day"));
|
||||
blurOnEnter(i);
|
||||
i.onchange = () => { if (i.value && i.value !== at) save(i.value); };
|
||||
const one = el("span", "warm-time");
|
||||
one.append(i);
|
||||
const list = el("span", "warm-times");
|
||||
list.append(one);
|
||||
box.append(list);
|
||||
}
|
||||
box.append(segs([["off", t("Off")], ["on", t("On")]], at ? "on" : "off", (v) => save(v === "on" ? at || "09:00" : "")));
|
||||
row.hidden = false;
|
||||
row.append(who, box);
|
||||
};
|
||||
|
||||
@@ -4,6 +4,11 @@
|
||||
// works. {name} slots are filled by t(str, vars).
|
||||
const I18N = {
|
||||
zh: {
|
||||
"Check-in time": "签到时间",
|
||||
"From {at} each day, for every vendor's check-in": "每天 {at} 起签到,所有服务商的签到都按这个时间",
|
||||
"As soon as each vendor's day starts": "每个服务商的新一天一开始就签到",
|
||||
"A computer asleep then checks in when it wakes.": "到点时电脑在睡眠的话,醒来后再签到。",
|
||||
"checks in from {at}": "{at} 起签到",
|
||||
"Archived": "已归档",
|
||||
"Everywhere": "所有地方",
|
||||
"Preference": "偏好",
|
||||
@@ -4841,6 +4846,11 @@ const I18N = {
|
||||
"This report is no longer kept: magpie keeps the last 5.": "这份报告已经不在了:magpie 只保留最近 5 份。",
|
||||
},
|
||||
"zh-TW": {
|
||||
"Check-in time": "簽到時間",
|
||||
"From {at} each day, for every vendor's check-in": "每天 {at} 起簽到,所有服務商的簽到都按這個時間",
|
||||
"As soon as each vendor's day starts": "每個服務商的新一天一開始就簽到",
|
||||
"A computer asleep then checks in when it wakes.": "到點時電腦在睡眠的話,醒來後再簽到。",
|
||||
"checks in from {at}": "{at} 起簽到",
|
||||
"Archived": "已封存",
|
||||
"Everywhere": "所有地方",
|
||||
"Preference": "偏好",
|
||||
@@ -9663,6 +9673,11 @@ const I18N = {
|
||||
"This report is no longer kept: magpie keeps the last 5.": "這份報告已經不在了:magpie 只保留最近 5 份。",
|
||||
},
|
||||
ja: {
|
||||
"Check-in time": "チェックインの時刻",
|
||||
"From {at} each day, for every vendor's check-in": "毎日 {at} からチェックイン(すべてのサービスのチェックインに共通)",
|
||||
"As soon as each vendor's day starts": "各サービスの日付が変わったらすぐにチェックイン",
|
||||
"A computer asleep then checks in when it wakes.": "その時刻にスリープ中なら、復帰後にチェックインします。",
|
||||
"checks in from {at}": "{at} からチェックイン",
|
||||
"Archived": "アーカイブ済み",
|
||||
"Everywhere": "どこでも",
|
||||
"Preference": "好み",
|
||||
@@ -14487,6 +14502,11 @@ const I18N = {
|
||||
"This report is no longer kept: magpie keeps the last 5.": "このレポートはもう残っていません。magpie は最新の 5 件だけを保存します。",
|
||||
},
|
||||
de: {
|
||||
"Check-in time": "Check-in-Zeit",
|
||||
"From {at} each day, for every vendor's check-in": "Täglich ab {at}, für den Check-in jedes Anbieters",
|
||||
"As soon as each vendor's day starts": "Sobald der Tag des jeweiligen Anbieters beginnt",
|
||||
"A computer asleep then checks in when it wakes.": "Schläft der Computer dann, wird beim Aufwachen eingecheckt.",
|
||||
"checks in from {at}": "Check-in ab {at}",
|
||||
"Archived": "Archiviert",
|
||||
"Everywhere": "Überall",
|
||||
"Preference": "Vorliebe",
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,133 @@
|
||||
// Run with Node's test runner and Playwright on the module path; see README.md.
|
||||
// times_ang on X: "magpie 可以调整自动签到的时间吗". Under a daily check-in
|
||||
// that is on, a Check-in time row: Off (as each vendor's day starts) or
|
||||
// On at 09:00, a time typed then saved as settings.checkinAt through
|
||||
// POST /api/settings, and Off again saves ""; a plugin's check-in group
|
||||
// has the same row, a check-in turned off none. An account not checked in
|
||||
// yet says the time on its Usage card. Chromium and WebKit, the window at
|
||||
// 1100 and 420, in English, Chinese, Traditional Chinese, Japanese and
|
||||
// German; 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, provPrefsProviders, openProvPrefs, inEditor } = require("./reader.cjs");
|
||||
|
||||
const assets = path.resolve(__dirname, "../assets");
|
||||
const yesterday = new Date(Date.now() + 8 * 3600e3 - 86400e3).toISOString().slice(0, 10);
|
||||
|
||||
function serve(lang, saved, at) {
|
||||
const settings = { theme: "light", lang, quotaLeft: false, currency: "usd", workbuddy: true, workbuddyCheckin: true, checkinAt: at,
|
||||
trae: true, traeCheckin: false,
|
||||
checkinPlugins: [{ id: "autoclaw", name: "AutoClaw", on: true, checkins: [] }],
|
||||
checkinAccounts: [{ key: "workbuddy|u1", by: "", user: "Ann", on: true }] };
|
||||
const quotas = () => [
|
||||
{ provider: "workbuddy", name: "WorkBuddy", plan: "Pro", user: "Ann", windows: [{ name: "Credits", used: 12 }], checkins: true,
|
||||
checkin: { user: "Ann", day: yesterday, outcome: "claimed", credit: 50 } },
|
||||
];
|
||||
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") {
|
||||
if (route.request().method() === "POST") {
|
||||
const b = route.request().postDataJSON();
|
||||
saved.push(b.checkinAt);
|
||||
settings.checkinAt = b.checkinAt;
|
||||
}
|
||||
return json(settings);
|
||||
}
|
||||
if (url.pathname === "/api/providers") return json(provPrefsProviders(["workbuddy", "autoclaw"], { workbuddy: "WorkBuddy", autoclaw: "AutoClaw" }));
|
||||
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 words = {
|
||||
en: { name: "Check-in time", off: "As soon as each vendor's day starts", on: "From 21:30 each day, for every vendor's check-in", card: "Not checked in yet today · checks in from 21:30" },
|
||||
zh: { name: "签到时间", off: "每个服务商的新一天一开始就签到", on: "每天 21:30 起签到,所有服务商的签到都按这个时间", card: "今日尚未签到 · 21:30 起签到" },
|
||||
"zh-TW": { name: "簽到時間", off: "每個服務商的新一天一開始就簽到", on: "每天 21:30 起簽到,所有服務商的簽到都按這個時間", card: "今日尚未簽到 · 21:30 起簽到" },
|
||||
ja: { name: "チェックインの時刻", off: "各サービスの日付が変わったらすぐにチェックイン", on: "毎日 21:30 からチェックイン(すべてのサービスのチェックインに共通)", card: "今日はまだチェックインしていません · 21:30 からチェックイン" },
|
||||
de: { name: "Check-in-Zeit", off: "Sobald der Tag des jeweiligen Anbieters beginnt", on: "Täglich ab 21:30, für den Check-in jedes Anbieters", card: "Heute noch nicht eingecheckt · Check-in ab 21:30" },
|
||||
};
|
||||
|
||||
function launch(engine) {
|
||||
return engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" });
|
||||
}
|
||||
|
||||
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
||||
for (const width of [1100, 420]) {
|
||||
for (const lang of Object.keys(words)) {
|
||||
const w = words[lang];
|
||||
test(`${engine} ${width} ${lang}: the check-in's time of day is set under Daily check-in`, async (t) => {
|
||||
const browser = await launch(engine);
|
||||
t.after(() => browser.close());
|
||||
const page = await (await browser.newContext({ viewport: { width, height: 900 }, reducedMotion: "reduce" })).newPage();
|
||||
page.setDefaultTimeout(5000);
|
||||
page.setDefaultNavigationTimeout(60000);
|
||||
const errors = [], saved = [];
|
||||
page.on("pageerror", (e) => { if (engine === "webkit" && /due to access control checks/.test(e.message)) return; errors.push(e.message); });
|
||||
await page.route("**/*", serve(lang, saved, ""));
|
||||
await watchSettingsReads(page);
|
||||
await openProvPrefs(page, "workbuddy");
|
||||
await settingsDrawn(page);
|
||||
const row = page.locator(".editor .prov-prefs #wbList .ci-at-row");
|
||||
await row.waitFor();
|
||||
assert.equal((await row.locator(".name").innerText()).trim(), w.name);
|
||||
assert.equal((await row.locator(".sub").innerText()).trim(), w.off);
|
||||
assert.equal(await row.locator("input.at").count(), 0, "no time while Off");
|
||||
assert.equal(await page.locator("#traeList .ci-at-row").count(), 0, "a check-in turned off has none");
|
||||
assert.equal(await page.locator('.ci-plugin[data-provider="autoclaw"] .ci-at-row').count(), 1, "a plugin's check-in has one");
|
||||
|
||||
const on = row.locator(".segs .opt").nth(1);
|
||||
await inEditor(page, on);
|
||||
await on.click();
|
||||
await page.waitForFunction(() => document.querySelector(".editor #wbList .ci-at-row input.at")?.value === "09:00");
|
||||
assert.deepEqual(saved, ["09:00"]);
|
||||
const time = page.locator(".editor #wbList .ci-at-row input.at");
|
||||
await time.fill("21:30");
|
||||
await time.press("Enter");
|
||||
await page.waitForFunction((want) => document.querySelector(".editor #wbList .ci-at-row .sub")?.textContent.trim() === want, w.on);
|
||||
assert.deepEqual(saved, ["09:00", "21:30"]);
|
||||
for (const box of [await page.locator(".editor #wbList .ci-at-row").boundingBox(), await time.boundingBox()]) {
|
||||
assert(box.width > 0 && box.x + box.width <= width, "the row fits");
|
||||
}
|
||||
assert.equal(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth), true, "no sideways scroll");
|
||||
if (process.env.ARTIFACT_DIR) await page.locator(".editor #wbList").screenshot({ path: path.join(process.env.ARTIFACT_DIR, `checkin-at-${engine}-${width}-${lang}.png`) });
|
||||
|
||||
await page.locator(".editor #wbList .ci-at-row .segs .opt").nth(0).click();
|
||||
await page.waitForFunction((want) => document.querySelector(".editor #wbList .ci-at-row .sub")?.textContent.trim() === want, w.off);
|
||||
assert.deepEqual(saved, ["09:00", "21:30", ""]);
|
||||
assert.equal(await page.locator("select").count(), 0);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test(`${engine} ${width} ${lang}: a card not checked in yet says the time`, async (t) => {
|
||||
const browser = await launch(engine);
|
||||
t.after(() => browser.close());
|
||||
const page = await (await browser.newContext({ viewport: { width, height: 900 }, reducedMotion: "reduce" })).newPage();
|
||||
page.setDefaultTimeout(5000);
|
||||
page.setDefaultNavigationTimeout(60000);
|
||||
const errors = [];
|
||||
page.on("pageerror", (e) => { if (engine === "webkit" && /due to access control checks/.test(e.message)) return; errors.push(e.message); });
|
||||
await page.route("**/*", serve(lang, [], "21:30"));
|
||||
await watchSettingsReads(page);
|
||||
await page.goto("http://magpie.test/?view=usage");
|
||||
await settingsDrawn(page);
|
||||
const say = page.locator(".subscription-card", { hasText: "WorkBuddy" }).locator(".wb-checkin .ci-say");
|
||||
await say.first().waitFor();
|
||||
assert.equal((await say.first().innerText()).trim().split(" · ").slice(0, 2).join(" · "), w.card);
|
||||
assert.equal(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth), true, "no sideways scroll");
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,8 @@ package provider
|
||||
// rechecked every 30 minutes but for a captcha or own-app answer, which
|
||||
// waits on the user, and an answer that may be the vendor's day before
|
||||
// (provisional, #3326), asked again every 30 minutes until a claim or an answer from noon on.
|
||||
// The loop asks for a day from the time of day the user set on
|
||||
// (settings.CheckinAt, checkinGate), else as the day turns.
|
||||
// A press asks the vendor again for a done, inactive or ineligible one.
|
||||
// What came of it is kept in the vendor's file by its key for reuse
|
||||
// (see workbuddy_checkin.go for when a failure is tried again).
|
||||
@@ -82,6 +84,7 @@ func (c checkiner) checkinNow(ctx context.Context, soon bool) []WorkBuddyCheckin
|
||||
// and an account the user left out is not asked at all, by the loop
|
||||
// or a press (#1902)
|
||||
off := checkinOff()
|
||||
gate := checkinGate(now)
|
||||
for _, a := range c.accounts() {
|
||||
if !a.On || a.key == "" || asked[a.key] || !c.reaches(a.key, off) {
|
||||
continue
|
||||
@@ -93,6 +96,15 @@ func (c checkiner) checkinNow(ctx context.Context, soon bool) []WorkBuddyCheckin
|
||||
}
|
||||
asked[a.key] = true
|
||||
prev, seen := st[a.key]
|
||||
// the loop asks for a day not yet asked from the user's time of
|
||||
// day on (checkinGate); a press asks at once
|
||||
if !soon && (!seen || prev.Day != day) && now.Before(gate) {
|
||||
if seen {
|
||||
prev.User, prev.By = a.User, c.by
|
||||
out = append(out, prev.shown())
|
||||
}
|
||||
continue
|
||||
}
|
||||
settled := prev.settled(day, now, soon)
|
||||
// a press asks the vendor again for a done, inactive or
|
||||
// ineligible magpie saw no claim for: answered from the record,
|
||||
@@ -157,6 +169,30 @@ func (c checkiner) checkinNow(ctx context.Context, soon bool) []WorkBuddyCheckin
|
||||
return out
|
||||
}
|
||||
|
||||
// checkinGate is when the loop first asks for the Beijing day now is on:
|
||||
// the first time of day settings.CheckinAt names, on now's clock (the
|
||||
// computer's zone), at or after the day's start; the start when none is
|
||||
// set (as before: as the day turns). Every Beijing day holds one, so a
|
||||
// time set never skips one; on a day a clock change leaves without it,
|
||||
// the start.
|
||||
func checkinGate(now time.Time) time.Time {
|
||||
t := now.In(beijing)
|
||||
start := time.Date(t.Year(), t.Month(), t.Day(), 0, 0, 0, 0, beijing)
|
||||
h, m, ok := settings.Clock(settings.Load().CheckinAt)
|
||||
if !ok {
|
||||
return start
|
||||
}
|
||||
l := start.In(now.Location())
|
||||
at := time.Date(l.Year(), l.Month(), l.Day(), h, m, 0, 0, l.Location())
|
||||
if at.Before(start) {
|
||||
at = time.Date(l.Year(), l.Month(), l.Day()+1, h, m, 0, 0, l.Location())
|
||||
}
|
||||
if !at.Before(start.AddDate(0, 0, 1)) {
|
||||
return start
|
||||
}
|
||||
return at
|
||||
}
|
||||
|
||||
// unread is how the accounts checkinNow would look at stand while its file
|
||||
// can't be read (err, logged by readCheckins): each failed with err, at
|
||||
// now, so the loop tries again after wbCheckinRetry and a press says why;
|
||||
|
||||
@@ -0,0 +1,194 @@
|
||||
package provider
|
||||
|
||||
import (
|
||||
"context"
|
||||
"slices"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/yetone/magpie/internal/settings"
|
||||
)
|
||||
|
||||
// checkinAtSet saves at as the check-in's time of day.
|
||||
func checkinAtSet(t *testing.T, at string) {
|
||||
t.Helper()
|
||||
s := settings.Load()
|
||||
s.CheckinAt = at
|
||||
if err := settings.Save(s); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// pluginCheckinClaims is a plugin provider whose one account's check-in
|
||||
// claims at each ask, with until (none when nil) after it, counting asks.
|
||||
func pluginCheckinClaims(id string, until func(time.Time) time.Time, now *time.Time, calls *int) pluginCheckinProvider {
|
||||
return pluginCheckinProvider{ID: id, accounts: []pluginCheckinAcct{{User: "ann", On: true, key: id + "|ann", card: id, do: func(context.Context) WorkBuddyCheckin {
|
||||
*calls++
|
||||
r := WorkBuddyCheckin{Outcome: CheckinClaimed, Credit: 1}
|
||||
if until != nil {
|
||||
r.ValidUntil = until(*now)
|
||||
}
|
||||
return r
|
||||
}}}}
|
||||
}
|
||||
|
||||
// loopAsks runs the daily loop a minute at a time for days from start and
|
||||
// says when it asked, as the held clock read then.
|
||||
func loopAsks(t *testing.T, c checkiner, now *time.Time, start time.Time, days int) []time.Time {
|
||||
t.Helper()
|
||||
var l wbCheckinLoop
|
||||
var asked []time.Time
|
||||
for m := time.Duration(0); m < time.Duration(days)*24*time.Hour; m += time.Minute {
|
||||
*now = start.Add(m)
|
||||
for _, r := range l.tick(context.Background(), c) {
|
||||
if r.Asked {
|
||||
asked = append(asked, *now)
|
||||
}
|
||||
}
|
||||
}
|
||||
return asked
|
||||
}
|
||||
|
||||
// times_ang on X: 可以调整自动签到的时间吗. With a time of day set, the
|
||||
// loop asks for each Beijing day at that time on the computer's clock,
|
||||
// once, every day, in a zone ahead of Beijing's day and one behind it; a
|
||||
// press asks before it; none set asks as the Beijing day turns.
|
||||
func TestCheckinAtTimeOfDay(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
zone *time.Location
|
||||
at string
|
||||
want string // the Beijing time of each ask
|
||||
// catchUp: the first look asks, its Beijing day's time gone by
|
||||
catchUp bool
|
||||
}{
|
||||
{"Beijing at 09:00", time.FixedZone("UTC+8", 8*3600), "09:00", "09:00", false},
|
||||
// 23:30 New York (winter) is 12:30 the next Beijing day; at 03:00
|
||||
// New York, Beijing's 11-05 is past its 23:30 (11-04 New York)
|
||||
{"New York at 23:30", time.FixedZone("UTC-5", -5*3600), "23:30", "12:30", true},
|
||||
{"New York unset", time.FixedZone("UTC-5", -5*3600), "", "00:00", true},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
claudeHome(t)
|
||||
checkinAtSet(t, tc.at)
|
||||
// 03:00 local on 11-05, the loop's first look
|
||||
start := time.Date(2026, 11, 5, 3, 0, 0, 0, tc.zone)
|
||||
now, calls := start, 0
|
||||
c := pluginCheckinClaims("fakeco", nil, &now, &calls).checkiner(func() time.Time { return now })
|
||||
asked := loopAsks(t, c, &now, start, 4)
|
||||
if len(asked) == 0 || asked[0].Equal(start) != tc.catchUp {
|
||||
t.Fatalf("asked at %v; at the first look, want %v", asked, tc.catchUp)
|
||||
}
|
||||
days := map[string]bool{}
|
||||
for i, a := range asked {
|
||||
if i == 0 && tc.catchUp {
|
||||
days[wbCheckinDay(a)] = true
|
||||
continue
|
||||
}
|
||||
if got := a.In(beijing).Format("15:04"); got != tc.want {
|
||||
t.Fatalf("asked at %s (Beijing %s), want Beijing %s; all: %v", a.Format(time.RFC3339), got, tc.want, asked)
|
||||
}
|
||||
if tc.at != "" && a.Format("15:04") != tc.at {
|
||||
t.Fatalf("asked at %s on the computer's clock, want %s", a.Format("15:04"), tc.at)
|
||||
}
|
||||
day := wbCheckinDay(a)
|
||||
if days[day] {
|
||||
t.Fatalf("asked twice on Beijing %s: %v", day, asked)
|
||||
}
|
||||
days[day] = true
|
||||
}
|
||||
// every Beijing day from the first ask's to the last's
|
||||
first, last := asked[0].In(beijing), asked[len(asked)-1].In(beijing)
|
||||
for d := first; !d.After(last); d = d.AddDate(0, 0, 1) {
|
||||
if !days[wbCheckinDay(d)] {
|
||||
t.Fatalf("Beijing %s skipped: %v", wbCheckinDay(d), asked)
|
||||
}
|
||||
}
|
||||
if len(days) < 3 {
|
||||
t.Fatalf("asked on %d days in 4: %v", len(days), asked)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
t.Run("a press before it", func(t *testing.T) {
|
||||
claudeHome(t)
|
||||
checkinAtSet(t, "21:00")
|
||||
now := time.Date(2026, 11, 5, 8, 0, 0, 0, beijing)
|
||||
calls := 0
|
||||
c := pluginCheckinClaims("fakeco", nil, &now, &calls).checkiner(func() time.Time { return now })
|
||||
if rs := c.checkinNow(context.Background(), false); len(rs) != 0 || calls != 0 {
|
||||
t.Fatalf("the loop at 08:00 asked for 21:00: %+v", rs)
|
||||
}
|
||||
if rs := c.checkinNow(context.Background(), true); len(rs) != 1 || !rs[0].Asked || calls != 1 {
|
||||
t.Fatalf("a press at 08:00 didn't ask: %+v", rs)
|
||||
}
|
||||
// asked today, the loop leaves the claim be at 21:00
|
||||
now = now.Add(13 * time.Hour)
|
||||
if c.checkinNow(context.Background(), false); calls != 1 {
|
||||
t.Fatalf("asked again after a press's claim")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// A vendor whose day turns at 10:00 Beijing (a plugin's until, Qoder's)
|
||||
// gets one ask in each of its days with the time set at 20:00: its turn
|
||||
// falls before the time, and the claim at 20:00 is that day's.
|
||||
func TestCheckinAtKeepsVendorDays(t *testing.T) {
|
||||
claudeHome(t)
|
||||
checkinAtSet(t, "20:00")
|
||||
tenNext := func(at time.Time) time.Time {
|
||||
b := at.In(beijing)
|
||||
u := time.Date(b.Year(), b.Month(), b.Day(), 10, 0, 0, 0, beijing)
|
||||
if !u.After(at) {
|
||||
u = u.AddDate(0, 0, 1)
|
||||
}
|
||||
return u
|
||||
}
|
||||
start := time.Date(2026, 11, 5, 3, 0, 0, 0, beijing)
|
||||
now, calls := start, 0
|
||||
c := pluginCheckinClaims("fakeco", tenNext, &now, &calls).checkiner(func() time.Time { return now })
|
||||
asked := loopAsks(t, c, &now, start, 4)
|
||||
var want []time.Time
|
||||
for d := range 4 {
|
||||
want = append(want, time.Date(2026, 11, 5+d, 20, 0, 0, 0, beijing))
|
||||
}
|
||||
if !slices.EqualFunc(asked, want, time.Time.Equal) {
|
||||
t.Fatalf("asked at %v, want %v", asked, want)
|
||||
}
|
||||
// each vendor day [10:00, 10:00) holds one
|
||||
for i := 1; i < len(asked); i++ {
|
||||
if asked[i].Sub(asked[i-1]) != 24*time.Hour {
|
||||
t.Fatalf("asks %v apart", asked[i].Sub(asked[i-1]))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// checkinGate is the time on the Beijing day, wherever the computer's
|
||||
// clock is, and the day's start when none is set or a bad one is.
|
||||
func TestCheckinGate(t *testing.T) {
|
||||
claudeHome(t)
|
||||
ny := time.FixedZone("UTC-5", -5*3600)
|
||||
now := time.Date(2026, 11, 5, 1, 0, 0, 0, beijing) // 12:00 11-04 in New York
|
||||
for _, tc := range []struct {
|
||||
at string
|
||||
now time.Time
|
||||
want time.Time
|
||||
}{
|
||||
{"", now, time.Date(2026, 11, 5, 0, 0, 0, 0, beijing)},
|
||||
{"07:30", now, time.Date(2026, 11, 5, 7, 30, 0, 0, beijing)},
|
||||
{"7:30", now, time.Date(2026, 11, 5, 7, 30, 0, 0, beijing)},
|
||||
// the Beijing day 11-05 runs 11:00 11-04 to 11:00 11-05 in New York
|
||||
{"10:59", now.In(ny), time.Date(2026, 11, 5, 10, 59, 0, 0, ny)},
|
||||
{"11:00", now.In(ny), time.Date(2026, 11, 4, 11, 0, 0, 0, ny)},
|
||||
} {
|
||||
checkinAtSet(t, tc.at)
|
||||
if got := checkinGate(tc.now); !got.Equal(tc.want) {
|
||||
t.Errorf("%q at %v: %v, want %v", tc.at, tc.now, got, tc.want)
|
||||
}
|
||||
}
|
||||
s := settings.Load()
|
||||
s.CheckinAt = "25:00"
|
||||
if err := settings.Save(s); err == nil {
|
||||
t.Fatal("saved 25:00")
|
||||
}
|
||||
}
|
||||
@@ -665,6 +665,10 @@ func (l *wbCheckinLoop) tick(ctx context.Context, c checkinRunner) []WorkBuddyCh
|
||||
cx, cancel := context.WithTimeout(ctx, 2*time.Minute)
|
||||
defer cancel()
|
||||
rs := c.checkinNow(cx, false)
|
||||
// and at the user's time of day, when the day's first ask waits for it
|
||||
if g := checkinGate(now); g.After(now) && (l.again.IsZero() || g.Before(l.again)) {
|
||||
l.again = g
|
||||
}
|
||||
for _, r := range rs {
|
||||
due := time.Time{}
|
||||
if r.Outcome == CheckinFailed {
|
||||
|
||||
@@ -366,6 +366,13 @@ type Settings struct {
|
||||
// "<provider>|<display name>", which provider.adoptLegacyPluginCheckins
|
||||
// carries over).
|
||||
CheckinOff []string `json:"checkinOff,omitempty"`
|
||||
// CheckinAt is the local time of day ("15:04") every daily check-in,
|
||||
// built-in and plugin, waits for before it asks for the vendor's day
|
||||
// (times_ang on X: 可以调整自动签到的时间吗); "" asks as the day turns,
|
||||
// as before. It holds the day's first ask only: the vendor's own turn
|
||||
// (a plugin's until) and the tries after it are kept, so no day is
|
||||
// skipped (provider.checkinGate).
|
||||
CheckinAt string `json:"checkinAt,omitempty"`
|
||||
// ReplyModel is what a reply's model name says when the request went
|
||||
// out under another name than the one asked for (a group's member, a
|
||||
// model's own id, a provider/model id): "" the model the agent asked
|
||||
@@ -2214,6 +2221,9 @@ func saveOwn(s Settings, recording, reads bool) error {
|
||||
return fmt.Errorf("%s's warm-up time of day must look like 06:00 or be off, not %q", user, at)
|
||||
}
|
||||
}
|
||||
if _, _, ok := Clock(s.CheckinAt); s.CheckinAt != "" && !ok {
|
||||
return fmt.Errorf("the check-in's time of day must look like 09:00, not %q", s.CheckinAt)
|
||||
}
|
||||
if !slices.Contains(TrayEvery, s.TrayUsageEvery) {
|
||||
return fmt.Errorf("the menu bar's usage is refreshed every %v minutes, not %d", TrayEvery, s.TrayUsageEvery)
|
||||
}
|
||||
@@ -2518,6 +2528,11 @@ func (s Settings) normal() Settings {
|
||||
*w.at = (*w.ats)[0]
|
||||
}
|
||||
}
|
||||
// the check-in's time of day, as 09:00 whichever way it came
|
||||
s.CheckinAt = strings.TrimSpace(s.CheckinAt)
|
||||
if h, m, ok := Clock(s.CheckinAt); ok {
|
||||
s.CheckinAt = fmt.Sprintf("%02d:%02d", h, m)
|
||||
}
|
||||
// a reply's model name: memberModel, as a magpie before replyModel
|
||||
// kept it, when replyModel isn't set, and kept beside it for that
|
||||
// magpie
|
||||
|
||||
@@ -43,7 +43,7 @@ var Keys = []string{
|
||||
"noStats", "noUsageStats", "otel",
|
||||
// warm-ups and check-ins
|
||||
"codexWarmup", "claudeWarmup", "codexWarmAt", "claudeWarmAt", "codexWarmAts", "claudeWarmAts",
|
||||
"workbuddyCheckin", "traeCheckin", "minimaxCheckin", "qoderCheckin",
|
||||
"workbuddyCheckin", "traeCheckin", "minimaxCheckin", "qoderCheckin", "checkinAt",
|
||||
// models: replies, vision, images, search
|
||||
"replyModel", "noLoopGuard", "claudeLeanPrompt", "claudePrintMode", "refusalRetries", "retryAfterCap",
|
||||
"vision", "visionEffort", "imageGen", "videoGen", "imageTimeout", "classifyTimeout",
|
||||
|
||||
Reference in New Issue
Block a user