diff --git a/docs/reference.md b/docs/reference.md index d0ecd9347..6f08a85c7 100644 --- a/docs/reference.md +++ b/docs/reference.md @@ -2260,7 +2260,11 @@ each of these groups ordered by the share used. - **Smart** (the default): of the accounts under 90%, the one whose allowance renews soonest goes first, because what it has left is lost at - the reset. The biggest window decides: the week, then the 5 hours only + the reset. It is not load balancing: every new conversation goes to that + account too, the others showing "one renewing sooner goes first" on the + Routing page, until it runs low (its 5 hours at 90%; a week renewing + soonest is spent to 98%). To spread conversations, set *Stays* to + *Session*, or pick Least used first. The biggest window decides: the week, then the 5 hours only when the weeks renew in the same hour. Reset times are compared to the hour, by the clock: 13:55 and 14:05 are different hours, 14:05 and 14:55 the same. An account diff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.js index b3dae7296..3135c0893 100644 --- a/internal/gui/assets/app.js +++ b/internal/gui/assets/app.js @@ -12302,7 +12302,7 @@ function kindTag(c, kind) { // renderRouting: spread over keys or accounts and stickiness, staged in // the draft and made with Save (01huadalang on Discord) const ROUTINGS = [ - ["", "Smart", "Not load balancing: requests go to one account at a time, the one whose quota renews soonest, since what it has left is lost then; the next takes over when it is at 90% or can't answer. Keys go in their order. To spread requests evenly, pick In turn or Least used first. One out of credit sits out half an hour, one out of quota until it resets, one rate limited as long as the vendor asks, and one that fails a minute, longer each time it fails again."], + ["", "Smart", "Not load balancing: every request, new conversations too, goes to the one account whose quota renews soonest, since what it has left is lost then, until it runs low or can't answer. Keys go in their order. To spread requests evenly, pick In turn or Least used first. One out of credit sits out half an hour, one out of quota until it resets, one rate limited as long as the vendor asks, and one that fails a minute, longer each time it fails again."], ["order", "In order", "Requests go to the first; the next takes over when the one before runs out of quota, hits a rate limit or fails."], // dzxx0496 on Discord: free accounts one after another, the first not // taking the requests back once it renews (routes.Drain) diff --git a/internal/gui/assets/i18n.js b/internal/gui/assets/i18n.js index dd0fd7d31..8562f3290 100644 --- a/internal/gui/assets/i18n.js +++ b/internal/gui/assets/i18n.js @@ -2241,7 +2241,7 @@ const I18N = { "{agent} stays signed in to the first account": "{agent} 将始终登录首选账号", "magpie moves {agent} to an account with room again": "首选账号额度不足时,会再把 {agent} 切到有余量的账号", "Smart": "智能", - "Not load balancing: requests go to one account at a time, the one whose quota renews soonest, since what it has left is lost then; the next takes over when it is at 90% or can't answer. Keys go in their order. To spread requests evenly, pick In turn or Least used first. One out of credit sits out half an hour, one out of quota until it resets, one rate limited as long as the vendor asks, and one that fails a minute, longer each time it fails again.": "不是负载均衡:请求一次只给一个账号,即额度最先重置的那个(它剩下的额度到时就作废),它用到 90% 或无法响应时才换下一个;密钥按顺序。要平均分摊,请选“轮流”或“用量少的优先”。欠费的暂停半小时,额度用完的暂停到重置,被限流的按厂商要求暂停,出错的暂停一分钟,再出错则逐次延长。", + "Not load balancing: every request, new conversations too, goes to the one account whose quota renews soonest, since what it has left is lost then, until it runs low or can't answer. Keys go in their order. To spread requests evenly, pick In turn or Least used first. One out of credit sits out half an hour, one out of quota until it resets, one rate limited as long as the vendor asks, and one that fails a minute, longer each time it fails again.": "不是负载均衡:所有请求(新会话也一样)都给额度最先重置的那一个账号(它剩下的额度到时就作废),直到它快用完或无法响应才换下一个;密钥按顺序。要平均分摊,请选“轮流”或“用量少的优先”。欠费的暂停半小时,额度用完的暂停到重置,被限流的按厂商要求暂停,出错的暂停一分钟,再出错则逐次延长。", "{user} is first in the order; {routing} still goes by each account's quota, so the order only settles ties. In order uses the first first.": "{user} 已排在首位;{routing} 仍按各账号的额度挑选,顺序只在条件相同时起作用。想先用完首选账号,请选「按顺序」。", "In order": "按顺序", "Until used up": "用完再换", @@ -7587,7 +7587,7 @@ const I18N = { "{agent} stays signed in to the first account": "{agent} 將始終登入首選帳號", "magpie moves {agent} to an account with room again": "首選帳號額度不足時,會再把 {agent} 切到有餘量的帳號", "Smart": "智慧", - "Not load balancing: requests go to one account at a time, the one whose quota renews soonest, since what it has left is lost then; the next takes over when it is at 90% or can't answer. Keys go in their order. To spread requests evenly, pick In turn or Least used first. One out of credit sits out half an hour, one out of quota until it resets, one rate limited as long as the vendor asks, and one that fails a minute, longer each time it fails again.": "不是負載平衡:請求一次只給一個帳號,即額度最先重置的那個(它剩下的額度到時就作廢),它用到 90% 或無法回應時才換下一個;金鑰按順序。要平均分攤,請選「輪流」或「用量少的優先」。欠費的暫停半小時,額度用完的暫停到重置,被限流的按廠商要求暫停,出錯的暫停一分鐘,再出錯則逐次延長。", + "Not load balancing: every request, new conversations too, goes to the one account whose quota renews soonest, since what it has left is lost then, until it runs low or can't answer. Keys go in their order. To spread requests evenly, pick In turn or Least used first. One out of credit sits out half an hour, one out of quota until it resets, one rate limited as long as the vendor asks, and one that fails a minute, longer each time it fails again.": "不是負載平衡:所有請求(新對話也一樣)都給額度最先重置的那一個帳號(它剩下的額度到時就作廢),直到它快用完或無法回應才換下一個;金鑰按順序。要平均分攤,請選「輪流」或「用量少的優先」。欠費的暫停半小時,額度用完的暫停到重置,被限流的按廠商要求暫停,出錯的暫停一分鐘,再出錯則逐次延長。", "{user} is first in the order; {routing} still goes by each account's quota, so the order only settles ties. In order uses the first first.": "{user} 已排在首位;{routing} 仍按各帳號的額度挑選,順序只在條件相同時起作用。想先用完首選帳號,請選「按順序」。", "In order": "按順序", "Until used up": "用完再換", @@ -12908,7 +12908,7 @@ const I18N = { "{agent} stays signed in to the first account": "{agent} は最初のアカウントにサインインしたままになります", "magpie moves {agent} to an account with room again": "magpie は {agent} を再び残量のあるアカウントに切り替えます", "Smart": "スマート", - "Not load balancing: requests go to one account at a time, the one whose quota renews soonest, since what it has left is lost then; the next takes over when it is at 90% or can't answer. Keys go in their order. To spread requests evenly, pick In turn or Least used first. One out of credit sits out half an hour, one out of quota until it resets, one rate limited as long as the vendor asks, and one that fails a minute, longer each time it fails again.": "負荷分散ではありません。リクエストは一度に 1 つのアカウント、枠が最も早くリセットされるもの(残りはその時点で失われるため)に送られ、それが 90% に達するか応答できなくなったら次に移ります。キーは順番どおりです。均等に分けるには「交互」か「使用量が最少のものを優先」を選んでください。残高切れは 30 分、枠切れはリセットまで、レート制限はベンダーの指定どおり休み、失敗したものは 1 分、失敗が続くたびに長く休みます。", + "Not load balancing: every request, new conversations too, goes to the one account whose quota renews soonest, since what it has left is lost then, until it runs low or can't answer. Keys go in their order. To spread requests evenly, pick In turn or Least used first. One out of credit sits out half an hour, one out of quota until it resets, one rate limited as long as the vendor asks, and one that fails a minute, longer each time it fails again.": "負荷分散ではありません。リクエストは一度に 1 つのアカウント、枠が最も早くリセットされるもの(残りはその時点で失われるため)に送られます(新しい会話も同じ)。残りが少なくなるか応答できなくなるまで次には移りません。キーは順番どおりです。均等に分けるには「交互」か「使用量が最少のものを優先」を選んでください。残高切れは 30 分、枠切れはリセットまで、レート制限はベンダーの指定どおり休み、失敗したものは 1 分、失敗が続くたびに長く休みます。", "{user} is first in the order; {routing} still goes by each account's quota, so the order only settles ties. In order uses the first first.": "{user} が順番の先頭になりました。{routing} は引き続き各アカウントの枠で選ぶため、順番は条件が同じときだけ効きます。先頭から使い切るには「順番」を選んでください。", "In order": "順番", "Until used up": "使い切ってから次へ", @@ -18260,7 +18260,7 @@ const I18N = { "{agent} stays signed in to the first account": "{agent} bleibt beim ersten Konto angemeldet", "magpie moves {agent} to an account with room again": "magpie wechselt {agent} wieder zu einem Konto mit freiem Kontingent", "Smart": "Intelligent", - "Not load balancing: requests go to one account at a time, the one whose quota renews soonest, since what it has left is lost then; the next takes over when it is at 90% or can't answer. Keys go in their order. To spread requests evenly, pick In turn or Least used first. One out of credit sits out half an hour, one out of quota until it resets, one rate limited as long as the vendor asks, and one that fails a minute, longer each time it fails again.": "Kein Lastausgleich: Anfragen gehen jeweils an ein Konto, dessen Kontingent am frühesten zurückgesetzt wird (was es übrig hat, verfällt dann); das nächste übernimmt, wenn es bei 90 % ist oder nicht antworten kann. Schlüssel gehen der Reihe nach. Für gleichmäßige Verteilung „Abwechselnd“ oder „Am wenigsten genutzte zuerst“ wählen. Eines ohne Guthaben pausiert eine halbe Stunde, eines ohne Kontingent bis zum Zurücksetzen, eines mit Ratenlimit so lange, wie der Anbieter verlangt, und eines, das fehlschlägt, eine Minute, bei jedem weiteren Fehlschlag länger.", + "Not load balancing: every request, new conversations too, goes to the one account whose quota renews soonest, since what it has left is lost then, until it runs low or can't answer. Keys go in their order. To spread requests evenly, pick In turn or Least used first. One out of credit sits out half an hour, one out of quota until it resets, one rate limited as long as the vendor asks, and one that fails a minute, longer each time it fails again.": "Kein Lastausgleich: Jede Anfrage, auch neuer Unterhaltungen, geht an das eine Konto, dessen Kontingent am frühesten zurückgesetzt wird (was es übrig hat, verfällt dann), bis es knapp wird oder nicht antworten kann. Schlüssel gehen der Reihe nach. Für gleichmäßige Verteilung „Abwechselnd“ oder „Am wenigsten genutzte zuerst“ wählen. Eines ohne Guthaben pausiert eine halbe Stunde, eines ohne Kontingent bis zum Zurücksetzen, eines mit Ratenlimit so lange, wie der Anbieter verlangt, und eines, das fehlschlägt, eine Minute, bei jedem weiteren Fehlschlag länger.", "{user} is first in the order; {routing} still goes by each account's quota, so the order only settles ties. In order uses the first first.": "{user} steht jetzt an erster Stelle; {routing} geht weiter nach dem Kontingent jedes Kontos, die Reihenfolge entscheidet nur bei Gleichstand. Der Reihe nach verbraucht zuerst das erste.", "In order": "Der Reihe nach", "Until used up": "Bis aufgebraucht", diff --git a/internal/gui/assets/plugins/routing/client.js b/internal/gui/assets/plugins/routing/client.js index 13dab05be..cae2dfe30 100644 --- a/internal/gui/assets/plugins/routing/client.js +++ b/internal/gui/assets/plugins/routing/client.js @@ -1139,14 +1139,18 @@ function routingPage(part) { // renews sooner (cmpRenews, as the gateway ranks them), "expires" when // the first's credits expire sooner, the key Smart went by (#5646). null when it is // first, or behind for what the row or another reason says already. + // A conversation kept on one Smart puts first anyway says "sooner" or + // "expires", not "kept": a new conversation goes there too, and "kept" + // read as every conversation stuck to one account (YsiCing on X: three + // Codex accounts, two at 0% "conversation kept on another"). function behindWhy(r, w) { const f = r.order[0], x = r.order.find((y) => y.id === w.id); if (!f || !x || x === f || f.rest || f.fallback || x.fallback || x.routing || !x.known || group(x) !== "fine") return null; if (!weighedWith(r, x).includes(f) || memberSplit(r, f, x)) return null; - if (["session", "turn", "cache"].includes(r.affinity?.why)) return "kept"; - if (r.sealedTask || ruleWhy(r, true) || f.learns || !f.known || group(f) !== "fine" || f.useFirst && !x.useFirst) return null; + const kept = ["session", "turn", "cache"].includes(r.affinity?.why) ? "kept" : null; + if (r.sealedTask || ruleWhy(r, true) || f.learns || !f.known || group(f) !== "fine" || f.useFirst && !x.useFirst) return kept; const { c, k, lapse } = cmpRenews(f, x); - return c >= 0 ? null : lapse || expiresAt(f, k) ? "expires" : "sooner"; + return c >= 0 ? kept : lapse || expiresAt(f, k) ? "expires" : "sooner"; } // memberSplit: the group that put x behind f, when it is one that takes @@ -3266,6 +3270,7 @@ function routingPage(part) { : (b = behindWhy(r, w)) === "kept" ? quota(w, "{n} used · conversation kept on another", "{n} left · conversation kept on another") : b === "sooner" && soon ? quota(w, "{n} used · renews in {d} · one renewing sooner goes first", "{n} left · renews in {d} · one renewing sooner goes first", { d: dur(soon - n) }) : b === "expires" && soon ? quota(w, "{n} used · renews in {d} · one whose credits expire sooner goes first", "{n} left · renews in {d} · one whose credits expire sooner goes first", { d: dur(soon - n) }) + : b === "sooner" ? quota(w, "{n} used · one renewing sooner goes first", "{n} left · one renewing sooner goes first") : soon ? quota(w, "{n} used · renews in {d}", "{n} left · renews in {d}", { d: dur(soon - n) }) : quota(w, "{n} used", "{n} left"); } else if (w.kind === "account") s = (!day && winsOf(w)[0]) || (!day && cardError(w) ? t("Allowance unavailable — hover for why") : t("what's left not known yet")); else if (w.routing === "usage") s = t("{n} tokens lately", { n: tokens(w.tokens || 0) }); diff --git a/internal/gui/assets/plugins/routing/i18n.js b/internal/gui/assets/plugins/routing/i18n.js index ae0672947..7e89264a6 100644 --- a/internal/gui/assets/plugins/routing/i18n.js +++ b/internal/gui/assets/plugins/routing/i18n.js @@ -709,6 +709,8 @@ magpie.strings({ "renews in {d}": "{d}后重置", "{n} used · renews in {d} · one renewing sooner goes first": "已用 {n} · {d}后重置 · 先用更早重置的账号", "{n} left · renews in {d} · one renewing sooner goes first": "剩余 {n} · {d}后重置 · 先用更早重置的账号", + "{n} used · one renewing sooner goes first": "已用 {n} · 先用更早重置的账号", + "{n} left · one renewing sooner goes first": "剩余 {n} · 先用更早重置的账号", "{n} used · renews in {d} · one whose credits expire sooner goes first": "已用 {n} · {d}后重置 · 先用积分更早到期的账号", "{n} left · renews in {d} · one whose credits expire sooner goes first": "剩余 {n} · {d}后重置 · 先用积分更早到期的账号", "{n} used · conversation kept on another": "已用 {n} · 会话留在另一个账号", @@ -1469,6 +1471,8 @@ magpie.strings({ "renews in {d}": "{d}後重置", "{n} used · renews in {d} · one renewing sooner goes first": "已用 {n} · {d}後重置 · 先用更早重置的帳號", "{n} left · renews in {d} · one renewing sooner goes first": "剩餘 {n} · {d}後重置 · 先用更早重置的帳號", + "{n} used · one renewing sooner goes first": "已用 {n} · 先用更早重置的帳號", + "{n} left · one renewing sooner goes first": "剩餘 {n} · 先用更早重置的帳號", "{n} used · renews in {d} · one whose credits expire sooner goes first": "已用 {n} · {d}後重置 · 先用點數更早到期的帳號", "{n} left · renews in {d} · one whose credits expire sooner goes first": "剩餘 {n} · {d}後重置 · 先用點數更早到期的帳號", "{n} used · conversation kept on another": "已用 {n} · 對話留在另一個帳號", @@ -2227,6 +2231,8 @@ magpie.strings({ "renews in {d}": "{d} 後に更新", "{n} used · renews in {d} · one renewing sooner goes first": "使用済み {n} · {d} 後に更新 · 先に更新されるアカウントを優先", "{n} left · renews in {d} · one renewing sooner goes first": "残り {n} · {d} 後に更新 · 先に更新されるアカウントを優先", + "{n} used · one renewing sooner goes first": "使用済み {n} · 先に更新されるアカウントを優先", + "{n} left · one renewing sooner goes first": "残り {n} · 先に更新されるアカウントを優先", "{n} used · renews in {d} · one whose credits expire sooner goes first": "使用済み {n} · {d} 後に更新 · クレジットの期限が早いアカウントを優先", "{n} left · renews in {d} · one whose credits expire sooner goes first": "残り {n} · {d} 後に更新 · クレジットの期限が早いアカウントを優先", "{n} used · conversation kept on another": "使用済み {n} · 会話は別のアカウントに固定", @@ -2987,6 +2993,8 @@ magpie.strings({ "renews in {d}": "erneuert sich in {d}", "{n} used · renews in {d} · one renewing sooner goes first": "{n} verbraucht · erneuert sich in {d} · eines, das sich früher erneuert, geht vor", "{n} left · renews in {d} · one renewing sooner goes first": "{n} übrig · erneuert sich in {d} · eines, das sich früher erneuert, geht vor", + "{n} used · one renewing sooner goes first": "{n} verbraucht · eines, das sich früher erneuert, geht vor", + "{n} left · one renewing sooner goes first": "{n} übrig · eines, das sich früher erneuert, geht vor", "{n} used · renews in {d} · one whose credits expire sooner goes first": "{n} verbraucht · erneuert sich in {d} · eines, dessen Guthaben früher abläuft, geht vor", "{n} left · renews in {d} · one whose credits expire sooner goes first": "{n} übrig · erneuert sich in {d} · eines, dessen Guthaben früher abläuft, geht vor", "{n} used · conversation kept on another": "{n} verbraucht · Unterhaltung bleibt bei einem anderen", diff --git a/internal/gui/tests/routing-behind-why.test.cjs b/internal/gui/tests/routing-behind-why.test.cjs index 8a2aad094..50614485c 100644 --- a/internal/gui/tests/routing-behind-why.test.cjs +++ b/internal/gui/tests/routing-behind-why.test.cjs @@ -8,6 +8,15 @@ // The first's own row, and one behind for no such reason, say what they // did. In every language, at a window's width and at 420px, in both // engines. +// +// YsiCing on X: three Codex accounts under Smart, every conversation on +// the Pro one, the other two rows saying "0% used · conversation kept on +// another". Smart puts the account renewing soonest first for a new +// conversation too, so "kept" read as stickiness gone wrong. A row behind +// one that answered a kept conversation and renews sooner says that one +// renews sooner; "kept" is left to a row that renews sooner itself, where +// only the conversation's cache holds it elsewhere. A fresh account, its +// windows not started, says so without a renewal of its own. const assert = require("node:assert/strict"); const fs = require("node:fs/promises"); const path = require("node:path"); @@ -19,13 +28,20 @@ const now = Date.now(); const iso = (ms) => new Date(ms).toISOString(); const H = 3600e3; -// the request: Max first (its week renews in 9h), Design Plan Go behind -// (its week in 20h); affinity, when given, kept it on Max -function routeOf(affinity) { +// the request: Max first (its week renews in 12h), Design Plan Go behind +// (its week in 20h); affinity, when given, kept it on Max. "later": Max's +// week renews after Design Plan Go's (in 30h), so only the kept +// conversation holds it first. "fresh": Design Plan Go's windows not +// started, nothing used, no renewal of the window it used +function routeOf(affinity, kind) { + const maxWeek = kind === "later" ? 30 * H : 12 * H; const max = { id: "claude", provider: "claude", name: "Claude", who: "max@example.com", kind: "account", agent: "claude", model: "claude-haiku-5-5", - known: true, used: 80, renews: [iso(now + 12 * H + 5 * 60e3), iso(now + 2 * H)], usedRenews: iso(now + 12 * H + 5 * 60e3), plan: "max" }; - const od = { id: "opendesign", provider: "opendesign", name: "Open Design", who: "od@example.com", kind: "account", agent: "opendesign", model: "claude-haiku-5.5", - known: true, used: 25, renews: [iso(now + 20 * H + 5 * 60e3), iso(now + 3 * H)], usedRenews: iso(now + 20 * H + 5 * 60e3), plan: "Design Plan Go" }; + known: true, used: 80, renews: [iso(now + maxWeek + 5 * 60e3), iso(now + 2 * H)], usedRenews: iso(now + maxWeek + 5 * 60e3), plan: "max" }; + const od = kind === "fresh" + ? { id: "opendesign", provider: "opendesign", name: "Open Design", who: "od@example.com", kind: "account", agent: "opendesign", model: "claude-haiku-5.5", + known: true, used: 0, renews: [iso(now + 7 * 24 * H), iso(now + 5 * H)], soon: [iso(now + 7 * 24 * H), iso(now + 5 * H)], plan: "Design Plan Go" } + : { id: "opendesign", provider: "opendesign", name: "Open Design", who: "od@example.com", kind: "account", agent: "opendesign", model: "claude-haiku-5.5", + known: true, used: 25, renews: [iso(now + 20 * H + 5 * 60e3), iso(now + 3 * H)], usedRenews: iso(now + 20 * H + 5 * 60e3), plan: "Design Plan Go" }; return { id: 7, seq: 7, time: iso(now - 2000), agent: "claude", model: "group/haiku", provider: "claude", done: true, status: 200, ms: 900, tokens: 1500, group: { id: "haiku", name: "Haiku", routing: "", affinity: "", members: ["claude/claude-haiku-5-5", "opendesign/claude-haiku-5.5"] }, @@ -58,15 +74,21 @@ function serve(lang, route) { }; } -// what the Design Plan row says: behind one renewing sooner, and behind -// the conversation kept on another, each with when its week renews +// what the Design Plan row says: behind one renewing sooner (the +// conversation kept there or not), behind the conversation kept on one +// renewing later, and fresh behind one renewing sooner; then what Max's +// own row says when its week renews in 12h const words = { - en: ["75% left · renews in 20 h · one renewing sooner goes first", "75% left · conversation kept on another · renews in 20 h", "answered this request · renews in 12 h"], - zh: ["剩余 75% · 20 小时后重置 · 先用更早重置的账号", "剩余 75% · 会话留在另一个账号 · 20 小时后重置", "回答了这个请求 · 12 小时后重置"], - "zh-TW": ["剩餘 75% · 20 小時後重置 · 先用更早重置的帳號", "剩餘 75% · 對話留在另一個帳號 · 20 小時後重置"], - ja: ["残り 75% · 20 時間 後に更新 · 先に更新されるアカウントを優先", "残り 75% · 会話は別のアカウントに固定 · 20 時間 後に更新"], - de: ["75% übrig · erneuert sich in 20 h · eines, das sich früher erneuert, geht vor", "75% übrig · Unterhaltung bleibt bei einem anderen · erneuert sich in 20 h"], + en: ["75% left · renews in 20 h · one renewing sooner goes first", "75% left · conversation kept on another · renews in 20 h", "100% left · one renewing sooner goes first", "answered this request · renews in 12 h"], + zh: ["剩余 75% · 20 小时后重置 · 先用更早重置的账号", "剩余 75% · 会话留在另一个账号 · 20 小时后重置", "剩余 100% · 先用更早重置的账号", "回答了这个请求 · 12 小时后重置"], + "zh-TW": ["剩餘 75% · 20 小時後重置 · 先用更早重置的帳號", "剩餘 75% · 對話留在另一個帳號 · 20 小時後重置", "剩餘 100% · 先用更早重置的帳號"], + ja: ["残り 75% · 20 時間 後に更新 · 先に更新されるアカウントを優先", "残り 75% · 会話は別のアカウントに固定 · 20 時間 後に更新", "残り 100% · 先に更新されるアカウントを優先"], + de: ["75% übrig · erneuert sich in 20 h · eines, das sich früher erneuert, geht vor", "75% übrig · Unterhaltung bleibt bei einem anderen · erneuert sich in 20 h", "100% übrig · eines, das sich früher erneuert, geht vor"], }; +// each case: its name, the affinity kept or not, the kind, and which of +// words[lang] the Design Plan row says +const cases = [["", false, "", 0], [", kept on the one renewing sooner", true, "", 0], [", kept on one renewing later", true, "later", 1], + [", fresh, kept on the one renewing sooner", true, "fresh", 2], [", fresh", false, "fresh", 2]]; const rowText = (page, who) => page.locator(".rt-accts > li", { hasText: who }).first().locator(".st, em").first(); @@ -76,8 +98,8 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", t.after(() => browser.close()); for (const lang of Object.keys(words)) { for (const width of [1100, 420]) { - for (const [i, affinity] of [[0, false], [1, true]]) { - await t.test(`${lang} at ${width}px${affinity ? ", kept by affinity" : ""}`, async () => { + for (const [name, affinity, kind, i] of cases) { + await t.test(`${lang} at ${width}px${name}`, async () => { const ctx = await browser.newContext({ viewport: { width, height: 760 }, reducedMotion: "reduce" }); try { const page = await ctx.newPage(); @@ -85,14 +107,14 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", page.setDefaultNavigationTimeout(60000); const errors = []; page.on("pageerror", (e) => errors.push(e.message)); - await page.route("**/*", serve(lang, routeOf(affinity))); + await page.route("**/*", serve(lang, routeOf(affinity, kind))); await page.goto("http://magpie.test/?view=routing"); const od = rowText(page, "od@example.com"); await od.waitFor(); await page.waitForFunction((w) => [...document.querySelectorAll(".rt-accts > li")].some((l) => l.textContent.includes(w)), words[lang][i], { timeout: 4000 }).catch(() => {}); assert.equal((await od.textContent()).trim(), words[lang][i]); // the one that answered says so, and when its week renews (dzxx0496) - if (words[lang][2]) assert.equal((await rowText(page, "max@example.com").textContent()).trim(), words[lang][2]); + if (words[lang][3] && kind !== "later") assert.equal((await rowText(page, "max@example.com").textContent()).trim(), words[lang][3]); const over = await page.evaluate(() => document.documentElement.scrollWidth - innerWidth); assert.ok(over <= 1, `${lang} at ${width}: ${over}px past`); assert.deepEqual(errors, []);