routing: Codex seats of one name are not folded into one account card (RayYanOnline on X)

The accounts list on the Routing page folded accounts by provider and name, so a Team seat and a Pro Lite login (or two logins) that carry one email read as a single card, and the day's counts of all of them went to it. An account is now told apart by its plan as well: the page's foldActs key and the gateway's tallyKey add the lowercased plan when it has one; a seat with no plan keeps the two-part key, so stored tallies and fixtures are unchanged. The key still ignores the id, which flips between codex and codex@user when the live login switches.

Run (mote): routing-codex-seats.test.cjs, chromium and webkit, en zh zh-TW ja de: 5 of 5 each. Red on the old client.js (4 cards where 3 are wanted). TestTallyKeyTellsPlansApart and the tallies tests ok; go test ./internal/gui ok; go vet darwin, linux nogui and windows ok; gofmt clean.
Siblings: the TUI draws no account names (no Who use in internal/tui); the combo picker names members from groups.accounts, which already carries the backend's distinct names (email · Team, email · workspace).
Not tried: the reporter's real accounts; the whole GUI suite and the full Go suite are run after the tag.
This commit is contained in:
yetone
2026-11-13 00:57:33 +08:00
parent 7c37424fcf
commit d6b5f24db5
4 changed files with 101 additions and 4 deletions
+8 -3
View File
@@ -533,12 +533,17 @@ type tallied struct {
Tries []Try `json:"tries"`
}
// tallyKey is what the page groups an account by: its provider and its
// user, however it is weighed into a request (its sign-in may move); a
// tallyKey is what the page groups an account by: its provider, its user
// and its plan (two seats of one email on different plans are two
// accounts, not one), however it is weighed into a request (its sign-in may move); a
// key or a provider by its own id.
func tallyKey(w Weighed) string {
if w.Kind == "account" && w.Who != "" {
b, _ := json.Marshal([]string{w.Provider, strings.ToLower(strings.TrimSpace(w.Who))})
k := []string{w.Provider, strings.ToLower(strings.TrimSpace(w.Who))}
if plan := strings.ToLower(strings.TrimSpace(w.Plan)); plan != "" {
k = append(k, plan) // a plan-less seat keeps the two-part key
}
b, _ := json.Marshal(k)
return string(b)
}
return w.ID
+18
View File
@@ -144,3 +144,21 @@ func TestDayTalliesCountARateLimitAsOne(t *testing.T) {
t.Errorf("tallied %v, want 1 rate and 2 quota", a.Fails)
}
}
// Two seats of one email on different plans are two accounts in the day's
// tallies, as the Routing page's list keys them (RayYanOnline on X); a
// seat with no plan keeps the two-part key.
func TestTallyKeyTellsPlansApart(t *testing.T) {
seat := func(plan string) Weighed {
return Weighed{ID: "codex", Provider: "codex", Kind: "account", Who: "Jd@Example.com", Plan: plan}
}
if a, b := tallyKey(seat("team")), tallyKey(seat("prolite")); a == b {
t.Errorf("a Team seat and a Pro Lite login share the key %s", a)
}
if got, want := tallyKey(seat("")), `["codex","jd@example.com"]`; got != want {
t.Errorf("a seat with no plan: %s, want %s", got, want)
}
if got, want := tallyKey(seat(" Team ")), `["codex","jd@example.com","team"]`; got != want {
t.Errorf("a plan: %s, want %s", got, want)
}
}
@@ -4744,7 +4744,8 @@ function routingPage(part) {
// that same account uses provider@user and the base ID names another.
// Group accounts by their identity, resolving each try in its own route.
const keyOf = (w) => w.kind === "account" && w.who
? JSON.stringify([w.provider, w.who.trim().toLowerCase()]) : w.id;
? JSON.stringify(w.plan && String(w.plan).trim()
? [w.provider, w.who.trim().toLowerCase(), String(w.plan).trim().toLowerCase()] : [w.provider, w.who.trim().toLowerCase()]) : w.id;
// Live: the day's counts come with the history read the page already
// asks for (#3351) — the Usage page's own reading of the day, not the
// last few requests the gateway keeps. What that read cannot say (the
@@ -0,0 +1,73 @@
// Codex accounts in one group on the Routing page (RayYanOnline on X): seats
// that share a name (a Team seat and a Pro Lite login of one email) were
// folded into one card in the accounts list, so several accounts read as
// one. An account is told apart by its plan as well as its name.
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");
function routes(now) {
const reset = new Date(now.getTime() + 4 * 3600e3).toISOString();
const kiro = { provider: "codex", name: "Codex", kind: "account", icon: "codex-color", agent: "codex", plan: "team", model: "gpt-6.1-sol", known: true, used: 10, renews: [reset] };
const named = { ...kiro, id: "codex", who: "jd@example.com" };
const other = { ...kiro, id: "codex@jd@example.com", who: "jd@example.com", plan: "prolite", used: 20 };
const key = { ...kiro, id: "codex@jd@example.com#2", who: "jd@example.com", plan: "plus", used: 30 };
return Array.from({ length: 4 }, (_, i) => {
const time = new Date(now.getTime() - (4 - i) * 1000).toISOString();
const id = ["codex", other.id, key.id][i % 3];
return { id: i + 1, seq: i + 1, time, agent: "claude", model: "kiro/claude-sonnet-4.5", provider: "kiro", order: [named, other, key], done: true,
status: 200, ms: 20, tries: [{ id, model: "gpt-6.1-sol", start: time, done: true, status: 200, ms: 20 }] };
}).reverse();
}
function serve(lang, now, names, users = () => ({})) {
const assets = path.resolve(__dirname, "../assets");
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: { lang, theme: "light" } });
if (url.pathname === "/api/gateway/trace") {
if (url.searchParams.has("wait")) return;
return json({ mine: true, now: now.toISOString(), seq: 4, totals: { requests: 4, rerouted: 0, errors: 0 }, routes: routes(now) });
}
if (url.pathname === "/api/gateway/history") return json({ cut: false, days: [], routes: [] });
if (url.pathname === "/api/groups") return json({ groups: [] });
if (url.pathname === "/api/providers") return json({ providers: [{
id: "codex", name: "Codex", icon: "codex-color", models: [{ id: "gpt-6.1-sol", on: true }], keyList: [],
account: { agent: "codex", user: "jd@example.com · Team", logins: [] },
accountNames: names(), accountUsers: users(),
}], presets: [], excluded: [], gateway: { running: true, window: true } });
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" }[path.extname(file)];
await route.fulfill({ body: await fs.readFile(file).catch(() => ""), contentType });
};
}
for (const engine of process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"]) {
for (const lang of ["en", "zh", "zh-TW", "ja", "de"]) {
test(`${engine} ${lang}: Routing keeps Codex seats of one name apart`, async (t) => {
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
t.after(() => browser.close());
const page = await browser.newPage({ viewport: { width: 1100, height: 1000 } });
page.setDefaultTimeout(5000);
page.setDefaultNavigationTimeout(60000);
const errors = [];
page.on("pageerror", (e) => errors.push(e.message));
await page.route("**/*", serve(lang, new Date(), () => ({}), () => ({})));
await page.goto("http://magpie.test/?view=routing");
await page.locator(".rt-act").first().waitFor();
assert.equal(await page.locator(".rt-act", { hasText: "jd@example.com" }).count(), 3, "three seats are three cards: " + (await page.locator(".rt-acts").innerText()));
const text = (await page.locator(".rt-act", { hasText: "jd@example.com" }).allInnerTexts()).join(" | ").toLowerCase();
for (const plan of ["team", "plus"]) assert.ok(text.includes(plan), plan + " tells its seat apart: " + text);
assert.deepEqual(errors, []);
});
}
}