gui: Settings › Usage turns each Codex account's auto-use resets on and off (Avalon on Discord)
Avalon followed up on foobra12's report (a Codex reset used by itself,
"这个设置在哪儿找呢"): the switch seemed reachable only from the quota in
the tray. The window's Usage page has it on each Codex card, but nothing
in Settings named it, so a search there found nothing.
Change: Settings › Usage gets "Codex: auto-use resets", with a line on
when a reset is used (week used up and no other account can answer, or
before one expires unused; off until turned on, account by account) and
an Off/On row per signed-in Codex account (s.codexUsers, plus any account
still in codexAutoReset that is no longer signed in, so it can be turned
off). A pick posts settings/codex-auto-reset, the same call as the card's
switch; the card's switch redraws these rows. The row is hidden with no
Codex account. Strings in zh, zh-TW, ja and de.
Run (playwright 1.62.0, NODE_PATH to it):
- new codex-auto-reset-settings.test.cjs: 22/22, chromium and webkit,
en/zh/zh-TW/ja/de at 1100 and 420, plus the no-account case. With the
renderAutoResetOwn call removed by hand it goes red.
- click-scroll, codex-auto-reset, codex-resets-used, gui-de, gui-ja,
gui-zh-tw, i18n-keys, reset-reminder, settings-search,
settings-sections, settings-general, warm-at-own, warm-at-times,
routing-auto-reset: all green.
- old-webkit: 5/6. The red is app.css's ":has()" (Safari 15.4) at
~2836, which is on origin/main 42216ea60 without this change; this
commit doesn't touch app.css.
- gofmt -l; go vet darwin, linux -tags nogui, windows on internal/gui;
go test -tags nogui ./internal/gui/: ok.
Not tried: the real app window with a real Codex account; the full GUI
suite.
This commit is contained in:
@@ -16830,6 +16830,7 @@ function autoResetButton(q) {
|
||||
state.settings = prefs;
|
||||
status(t(on ? "{who} no longer uses a reset by itself" : "{who} uses a reset by itself when its week runs out, or before one expires", { who: q.user }), "ok");
|
||||
renderQuotas();
|
||||
if ($("#codexAutoResetRow")) renderAutoResetOwn(prefs); // Settings › Usage says the same
|
||||
} catch (err) {
|
||||
b.disabled = false;
|
||||
status(err.message, "err");
|
||||
@@ -21210,6 +21211,7 @@ function renderSettings() {
|
||||
renderWarmAt($("#claudeWarmAtSegs"), $("#claudeWarmAtSub"), warmTimes(s.claudeWarmAts, s.claudeWarmAt), s.claudeWarmup, t("Sent through Claude Code."),
|
||||
(v) => savePrefs({ ...keep, claudeWarmAts: v, claudeWarmAt: v[0] || "" }));
|
||||
renderWarmAtOwn(s);
|
||||
renderAutoResetOwn(s);
|
||||
// WorkBuddy's daily check-in pressed for each account, its tab shown
|
||||
// while one is signed in
|
||||
$("#warmTab-wb").hidden = !s.workbuddy && !s.workbuddyCheckin;
|
||||
@@ -22310,6 +22312,49 @@ function renderWarmAt(box, sub, ats, onReset, via, save) {
|
||||
box.append(segs([["off", t("Off")], ["on", t("On")]], ats.length ? "on" : "off", (v) => save(v === "on" ? (ats.length ? ats : ["06:00"]) : [])));
|
||||
}
|
||||
|
||||
// renderAutoResetOwn lists each ChatGPT account under Settings › Usage's
|
||||
// "Codex: auto-use resets", with its switch, the same say as on the
|
||||
// account's card (settings' codexAutoReset, the CLI's quota auto-reset).
|
||||
// Avalon on Discord, after foobra12 asked where it was: it was only on the
|
||||
// accounts' cards, and they found it from the menu bar's panel alone,
|
||||
// nothing for it in the window's Settings. The row shows while a Codex
|
||||
// account is signed in, or one is still on.
|
||||
function renderAutoResetOwn(s) {
|
||||
const head = $("#codexAutoResetRow");
|
||||
const list = head.parentElement;
|
||||
list.querySelectorAll(".ar-own").forEach((r) => r.remove());
|
||||
const on = s.codexAutoReset || [];
|
||||
const users = [...(s.codexUsers || [])];
|
||||
for (const u of on) if (!users.some((x) => x.toLowerCase() === u)) users.push(u);
|
||||
head.hidden = !users.length;
|
||||
let after = head;
|
||||
for (const user of users) {
|
||||
const r = el("div", "row pref ar-own");
|
||||
r.dataset.user = user;
|
||||
const who = el("div", "who");
|
||||
const name = el("div", "name", user);
|
||||
name.title = user;
|
||||
who.append(name);
|
||||
const was = on.includes(user.toLowerCase());
|
||||
const pick = segs([["off", t("Off")], ["on", t("On")]], was ? "on" : "off", async (v) => {
|
||||
try {
|
||||
prefs = await writingPrefs(api("settings/codex-auto-reset", { user, on: v === "on" }));
|
||||
if (state) state.settings = prefs;
|
||||
status(t(v === "on" ? "{who} uses a reset by itself when its week runs out, or before one expires" : "{who} no longer uses a reset by itself", { who: user }), "ok");
|
||||
renderSettings();
|
||||
if (quotas) renderQuotas(); // the account's card says the same
|
||||
} catch (e) {
|
||||
status(t(e.message), "err");
|
||||
renderSettings();
|
||||
}
|
||||
});
|
||||
pick.setAttribute("aria-label", t("Auto-use resets") + " · " + user);
|
||||
r.append(who, pick);
|
||||
after.after(r);
|
||||
after = r;
|
||||
}
|
||||
}
|
||||
|
||||
// renderWarmAtOwn gives each ChatGPT account its own row under Daily
|
||||
// warm-up (#957, Evan26Ma): two accounts started at one time run out
|
||||
// together, one at 06:00 and one at 09:00 take over from one another. An
|
||||
|
||||
@@ -1774,6 +1774,8 @@ const I18N = {
|
||||
"{who} no longer uses a reset by itself": "{who} 不再自动使用重置卡",
|
||||
"Auto-use resets": "自动使用重置卡",
|
||||
"Auto-use resets:": "自动使用重置卡:",
|
||||
"Codex: auto-use resets": "Codex:自动使用重置卡",
|
||||
"A ChatGPT account uses one of its resets by itself when its week is used up and no other account can answer, or before one expires unused. Off until turned on, account by account; each account's card on the Usage page has the same switch.": "ChatGPT 账号在周额度用完、且没有别的账号能接请求时,或者重置卡快到期还没用时,自动用掉一张。默认关闭,按账号单独打开;用量页每个账号的卡片上也有同一个开关。",
|
||||
"Use credits:": "使用积分:",
|
||||
"when its windows run out, so a task goes on": "额度用尽时继续用积分,任务不中断",
|
||||
"no — held when a window runs out": "否,额度用尽即暂停使用",
|
||||
@@ -6471,6 +6473,8 @@ const I18N = {
|
||||
"{who} no longer uses a reset by itself": "{who} 不再自動使用重置卡",
|
||||
"Auto-use resets": "自動使用重置卡",
|
||||
"Auto-use resets:": "自動使用重置卡:",
|
||||
"Codex: auto-use resets": "Codex:自動使用重置卡",
|
||||
"A ChatGPT account uses one of its resets by itself when its week is used up and no other account can answer, or before one expires unused. Off until turned on, account by account; each account's card on the Usage page has the same switch.": "ChatGPT 帳號在週額度用完、且沒有別的帳號能接請求時,或者重置卡快到期還沒用時,自動用掉一張。預設關閉,按帳號單獨開啟;用量頁每個帳號的卡片上也有同一個開關。",
|
||||
"Use credits:": "使用積分:",
|
||||
"when its windows run out, so a task goes on": "額度用盡時繼續用積分,任務不中斷",
|
||||
"no — held when a window runs out": "否,額度用盡即暫停使用",
|
||||
@@ -11142,6 +11146,8 @@ const I18N = {
|
||||
"{who} no longer uses a reset by itself": "{who} はリセットを自動で使用しなくなりました",
|
||||
"Auto-use resets": "リセットを自動使用",
|
||||
"Auto-use resets:": "リセットを自動使用:",
|
||||
"Codex: auto-use resets": "Codex:リセットを自動使用",
|
||||
"A ChatGPT account uses one of its resets by itself when its week is used up and no other account can answer, or before one expires unused. Off until turned on, account by account; each account's card on the Usage page has the same switch.": "ChatGPT アカウントは、週の枠を使い切り、ほかに応答できるアカウントがないとき、または未使用のリセットが期限切れになる前に、リセットを自動で 1 つ使います。オンにするまではオフで、アカウントごとに設定します。使用量ページの各アカウントのカードにも同じスイッチがあります。",
|
||||
"Use credits:": "クレジットを使用:",
|
||||
"when its windows run out, so a task goes on": "枠を使い切ったら使用し、タスクを続行",
|
||||
"no — held when a window runs out": "しない — 枠を使い切ったら停止",
|
||||
@@ -15833,6 +15839,8 @@ const I18N = {
|
||||
"{who} no longer uses a reset by itself": "{who} löst keinen Reset mehr automatisch ein",
|
||||
"Auto-use resets": "Resets automatisch einlösen",
|
||||
"Auto-use resets:": "Resets automatisch einlösen:",
|
||||
"Codex: auto-use resets": "Codex: Resets automatisch einlösen",
|
||||
"A ChatGPT account uses one of its resets by itself when its week is used up and no other account can answer, or before one expires unused. Off until turned on, account by account; each account's card on the Usage page has the same switch.": "Ein ChatGPT-Konto löst selbst einen seiner Resets ein, wenn seine Woche aufgebraucht ist und kein anderes Konto antworten kann, oder bevor einer ungenutzt abläuft. Aus, bis es eingeschaltet wird, Konto für Konto; die Karte jedes Kontos auf der Nutzungsseite hat denselben Schalter.",
|
||||
"Use credits:": "Credits nutzen:",
|
||||
"when its windows run out, so a task goes on": "wenn die Kontingente aufgebraucht sind, damit eine Aufgabe weiterläuft",
|
||||
"no — held when a window runs out": "nein – angehalten, wenn ein Kontingent aufgebraucht ist",
|
||||
|
||||
@@ -423,6 +423,9 @@
|
||||
<div class="who"><div class="name" data-t>Reset reminder</div><div class="sub" id="resetReminderSub"></div></div>
|
||||
<div id="resetReminderSegs"></div>
|
||||
</div>
|
||||
<div class="row pref" id="codexAutoResetRow" hidden>
|
||||
<div class="who"><div class="name" data-t>Codex: auto-use resets</div><div class="sub wraps" data-t>A ChatGPT account uses one of its resets by itself when its week is used up and no other account can answer, or before one expires unused. Off until turned on, account by account; each account's card on the Usage page has the same switch.</div></div>
|
||||
</div>
|
||||
<div class="row pref" id="turnDoneRow">
|
||||
<div class="who"><div class="name" data-t>Task done alert</div><div class="sub" id="turnDoneSub"></div></div>
|
||||
<div id="turnDoneSegs"></div>
|
||||
|
||||
@@ -0,0 +1,147 @@
|
||||
// Run with Node's test runner and Playwright on the module path; see README.md.
|
||||
// Codex resets used by themselves (foobra12 on Discord: 自动给我使用了一张, 这个
|
||||
//设置在哪儿找呢; Avalon: only the tray's quota showed the switch). Settings ›
|
||||
// Usage lists each signed-in Codex account under "Codex: auto-use resets"
|
||||
// with Off/On: Off for every account to begin with, a pick posts
|
||||
// settings/codex-auto-reset for that account and turns the switch, and with
|
||||
// no Codex account the row isn't there. Five languages, 1100 and 420 wide,
|
||||
// both engines; 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");
|
||||
|
||||
function server(lang, users, posts) {
|
||||
const fixed = {
|
||||
theme: "light", lang, tray: "panel", quotaLeft: false, currency: "usd", dock: false, dockWindow: false, proxy: "",
|
||||
redact: false, redactPersonal: false, redactWords: [], codexWarmup: "", claudeWarmup: "", codexWarmAt: "", claudeWarmAt: "",
|
||||
trayUsage: "", trayUsageEvery: 3, vision: "", imageGen: "", version: "0.1.900", dir: "~/.config/magpie",
|
||||
gateway: "http://127.0.0.1:3425", proxyNow: "none", proxySource: "none", visionModels: [], imageGenModels: [], lanURLs: [],
|
||||
fx: { rate: 7.2, at: new Date().toISOString(), stale: false },
|
||||
codexUsers: users, codexAutoReset: [],
|
||||
};
|
||||
let cur = fixed;
|
||||
return async (route) => {
|
||||
const req = route.request(), url = new URL(req.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:false};` });
|
||||
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: { lang, theme: "light" }, fx: fixed.fx });
|
||||
if (url.pathname === "/api/settings/codex-auto-reset") {
|
||||
const body = req.postDataJSON();
|
||||
posts.push(body);
|
||||
const u = body.user.toLowerCase();
|
||||
const on = cur.codexAutoReset.filter((x) => x !== u);
|
||||
if (body.on) on.push(u);
|
||||
cur = { ...cur, codexAutoReset: on };
|
||||
return json(cur);
|
||||
}
|
||||
if (url.pathname === "/api/settings") {
|
||||
if (req.method() === "POST") cur = { ...cur, ...req.postDataJSON() };
|
||||
return json(cur);
|
||||
}
|
||||
if (url.pathname === "/api/plugins") return json({ plugins: [] });
|
||||
if (url.pathname === "/api/usage/quotas") return json([]);
|
||||
if (url.pathname === "/api/groups") return json({ groups: [], models: [] });
|
||||
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)];
|
||||
await route.fulfill({ body: await fs.readFile(file), contentType });
|
||||
};
|
||||
}
|
||||
|
||||
const words = {
|
||||
en: { name: "Codex: auto-use resets", off: "Off", on: "On" },
|
||||
zh: { name: "Codex:自动使用重置卡", off: "关闭", on: "开启" },
|
||||
"zh-TW": { name: "Codex:自動使用重置卡", off: "關閉", on: "開啟" },
|
||||
ja: { name: "Codex:リセットを自動使用", off: "オフ", on: "オン" },
|
||||
de: { name: "Codex: Resets automatisch einlösen", off: "Aus", on: "An" },
|
||||
};
|
||||
|
||||
const users = ["alice@example.com", "a-much-longer-team-seat-address@some-company.example.org"];
|
||||
|
||||
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
||||
for (const lang of Object.keys(words)) {
|
||||
for (const width of [1100, 420]) {
|
||||
test(`${engine} ${lang} ${width}: Settings › Usage turns each Codex account's auto-use resets on and off`, async (t) => {
|
||||
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
||||
const page = await (await browser.newContext({ viewport: { width, height: 700 }, reducedMotion: "reduce" })).newPage();
|
||||
t.after(async () => {
|
||||
if (process.env.ARTIFACT_DIR) {
|
||||
await fs.mkdir(process.env.ARTIFACT_DIR, { recursive: true });
|
||||
await page.screenshot({ path: path.join(process.env.ARTIFACT_DIR, `${engine}-${lang}-${width}-codex-auto-reset-settings.png`) });
|
||||
}
|
||||
await browser.close();
|
||||
});
|
||||
page.setDefaultTimeout(5000);
|
||||
const errors = [], posts = [];
|
||||
page.on("pageerror", (e) => errors.push(e.message));
|
||||
await page.route("**/*", server(lang, users, posts));
|
||||
const posted = async (n) => { for (let i = 0; i < 100 && posts.length < n; i++) await page.waitForTimeout(20); assert.equal(posts.length, n, "posts"); return posts[n - 1]; };
|
||||
const w = words[lang];
|
||||
await watchSettingsReads(page);
|
||||
await page.goto("http://magpie.test/?view=settings&tab=usage");
|
||||
await settingsDrawn(page);
|
||||
const head = page.locator("#codexAutoResetRow");
|
||||
await head.waitFor();
|
||||
assert.equal((await head.locator(".name").textContent()).trim(), w.name);
|
||||
const rows = page.locator(".ar-own");
|
||||
assert.deepEqual(await rows.locator(".name").allTextContents(), users);
|
||||
for (let i = 0; i < users.length; i++) {
|
||||
assert.deepEqual(await rows.nth(i).locator(".opt").allTextContents(), [w.off, w.on]);
|
||||
assert.equal(await rows.nth(i).locator(".opt.on").textContent(), w.off, "off to begin with");
|
||||
}
|
||||
|
||||
// the reader wheels down to the second account's On, past the window's foot
|
||||
await reach(page, rows.nth(1).locator(".opt", { hasText: w.on }));
|
||||
const top = await page.locator("#view-settings").evaluate((v) => v.scrollTop);
|
||||
await rows.nth(1).locator(".opt", { hasText: w.on }).click();
|
||||
assert.deepEqual(await posted(1), { user: users[1], on: true });
|
||||
await page.waitForTimeout(300);
|
||||
const after = page.locator(".ar-own");
|
||||
assert.equal(await after.nth(1).locator(".opt.on").textContent(), w.on);
|
||||
assert.equal(await after.nth(0).locator(".opt.on").textContent(), w.off, "only that account");
|
||||
assert.equal(await page.locator("#view-settings").evaluate((v) => v.scrollTop), top, "no click moved the page");
|
||||
|
||||
// every row fits: nothing runs past the settings view
|
||||
const over = await page.evaluate(() => {
|
||||
const view = document.querySelector("#view-settings").getBoundingClientRect();
|
||||
return [...document.querySelectorAll("#codexAutoResetRow, .ar-own, .ar-own .opt")]
|
||||
.filter((e) => { const r = e.getBoundingClientRect(); return r.right > view.right + 1 || r.left < view.left - 1; })
|
||||
.map((e) => e.className + " " + e.textContent.slice(0, 30));
|
||||
});
|
||||
assert.deepEqual(over, []);
|
||||
assert.equal(await page.evaluate(() => document.documentElement.scrollWidth <= window.innerWidth), true, "no sideways scroll");
|
||||
assert.equal(await head.evaluate((e) => getComputedStyle(e).borderLeftWidth), "0px");
|
||||
|
||||
await reach(page, after.nth(1).locator(".opt", { hasText: w.off }));
|
||||
await after.nth(1).locator(".opt", { hasText: w.off }).click();
|
||||
assert.deepEqual(await posted(2), { user: users[1], on: false });
|
||||
await page.waitForTimeout(300);
|
||||
assert.equal(await page.locator(".ar-own").nth(1).locator(".opt.on").textContent(), w.off);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
test(`${engine}: with no Codex account the row isn't there`, async (t) => {
|
||||
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
||||
const page = await (await browser.newContext({ viewport: { width: 900, height: 600 }, reducedMotion: "reduce" })).newPage();
|
||||
t.after(() => browser.close());
|
||||
page.setDefaultTimeout(5000);
|
||||
const errors = [];
|
||||
page.on("pageerror", (e) => errors.push(e.message));
|
||||
await page.route("**/*", server("en", [], []));
|
||||
await watchSettingsReads(page);
|
||||
await page.goto("http://magpie.test/?view=settings&tab=usage");
|
||||
await settingsDrawn(page);
|
||||
await page.locator("#resetReminderSegs .opt").first().waitFor();
|
||||
assert.equal(await page.locator("#codexAutoResetRow").isVisible(), false);
|
||||
assert.equal(await page.locator(".ar-own").count(), 0);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user