EastonXvii asked for a group like Codex/Astra on account A, then Astra on B, then Sol on C, tried strictly in that order, with the same model on two accounts as two members. Before this, Group.Accounts held the whole group to a set of accounts with no order among one provider's accounts, so the only way was one group per account. A member id may now end with the account: provider/model[:effort][:fast]#<account> (provider.MemberAccount, groupaccount.go). - Every list keyed by a member's spelling (rules, Fast, Off, Weights, Placed, EffortMaps, Pick) and membersFound's dedup key include it, so the same model on two accounts is two members. The vendor is still asked for the model's own id. A group saved before has no "#" and reads as it did. - SaveGroup stores the account's stable id (a typed name is resolved by ResolveAccount). It refuses an account on group/ and auto/ members, and a new account magpie doesn't have. One the stored group had already that is gone since stays, matching nothing. - Gateway: planLevel's keys() leaves the provider's other accounts out for such a member (memberHeld; Held rows with HeldOwn in the trace). Fallback goes to the next member, never to another account under the same member. count_tokens counts on the resolved member's account (heldByGroupAt). Images and videos: drawingTries keeps one try per member account, and each try runs on a request held to that account (memberOn). - Sharing and importing a group drop members' accounts. - GUI: Routing → edit a group → each model row has an account chip (openPicker menu): "Any account", each account, and "Also on another account…", which adds the model on a free account as a member of its own after the row. Strings in en, zh, zh-TW, ja, de. - CLI: models=relay/m#B,relay/m#A,other/m (by name or id); show prints "on <name> alone". TUI effort cycling keeps the account. Run (mote, at the pushed head after rebasing on40d39e117): - gofmt clean. go vet passes for darwin, linux -tags nogui and windows. - go test for internal/provider, internal/cli, internal/tui and internal/gui (full packages, so the budgets are included), and internal/gateway -run Group|Draw|Image|Video|Held|Count|Trace. - GUI: group-member-account.test.cjs (5 languages x 420/1100px x chromium/webkit, plus "reasoning set on a member keeps its account"), i18n-keys, i18n-en-no-cjk, and every routing/group test file (114 files): 578 passed. - Red: menu-input-scroll, 4 of 4, also red on base5c47d59b5(#3402, commented). - Red: mobile-web's "desktop matches origin/main", which needs `git show origin/main`, and a mote-run copy has no .git. - Real run with a sandbox HOME on mote, built with -tags nogui. A fake upstream logged each key. Provider relay has keys A (first) and B, and other has key C. `magpie group add Chain models=relay/astra#B,relay/astra#A,other/sol routing=order`, then `magpie serve`, then a chat to group/chain. Results: - nothing refused → B; - B refused → B, A; - B and A refused → B, A, C (sol on other). B came first, though A is the provider's first key. Broken by hand (each went red): - memberHeld returning "": InOrder and NeverSpills; - membersFound's key without the account: InOrder and Saved; - the CLI's #account resolve turned off: TestGroupMembersOnAccounts; - the drawing loop on r instead of memberOn: Draw asked sk-mine; - drawingTries' key without the account: Draw never reached the second member. - count_tokens spent the other key before heldByGroupAt narrowed it. Not tried: a video group with real vendors (the path is the same as drawing's, through drawingTries and memberOn, with no test of its own). Not tried with real Codex accounts; the e2e used API-key accounts. Not tried on the Linux and Windows apps.
174 lines
10 KiB
JavaScript
174 lines
10 KiB
JavaScript
// Run with Node's test runner and Playwright on the module path; see README.md.
|
|
// A group's model can be sent on one account of its own (EastonXvii on X:
|
|
// Astra on account A, then Astra on B, then Sol on C). The model row has an
|
|
// account chip, "Any account" until one is picked in the app's menu; picked,
|
|
// the row says the account. "Also on another account…" adds the same model on
|
|
// another account as a member of its own, after the row, and the save sends
|
|
// both as provider/model#<account id> in that order. A model whose provider
|
|
// has one account has no chip. In every language, Chromium and WebKit, at a
|
|
// wide and a narrow window.
|
|
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 assets = path.resolve(__dirname, "../assets");
|
|
const A = "a1b2c3d4e5f60718", B = "0f1e2d3c4b5a6978";
|
|
const models = [
|
|
{ id: "codex/gpt-6-astra", name: "gpt-6-astra", provider: "codex", providerName: "Codex", icon: "generic" },
|
|
{ id: "rl/glm-5", name: "glm-5", provider: "rl", providerName: "Relay", icon: "generic" },
|
|
];
|
|
const accounts = {
|
|
codex: [
|
|
{ id: "codex/" + A, name: "me@x.com", provider: "codex", providerName: "Codex", account: true, plan: "Plus" },
|
|
{ id: "codex/" + B, name: "work@corp.example", provider: "codex", providerName: "Codex", account: true, plan: "Team" },
|
|
],
|
|
};
|
|
const groups = (members) => ({
|
|
models, pools: [], accounts,
|
|
groups: [{ id: "work", name: "Work", members, routing: "order", ready: true, accounts: [],
|
|
memberInfo: members.map((id) => ({ id, ready: true })) }],
|
|
});
|
|
|
|
const words = {
|
|
en: { edit: "Edit", save: "Save", any: "Any account", also: "Also on another account…" },
|
|
zh: { edit: "编辑", save: "保存", any: "任意账号", also: "再加一个账号…" },
|
|
"zh-TW": { edit: "編輯", save: "儲存", any: "任意帳號", also: "再加一個帳號…" },
|
|
ja: { edit: "編集", save: "保存", any: "どのアカウントでも", also: "別のアカウントでも追加…" },
|
|
de: { edit: "Bearbeiten", save: "Speichern", any: "Beliebiges Konto", also: "Auch mit einem anderen Konto…" },
|
|
};
|
|
|
|
function serve(lang, posts, members) {
|
|
const state = { agents: [{ id: "codex", name: "Codex", path: "/test/codex", fields: [] }], profiles: [], settings: { lang, theme: "light" } };
|
|
return async (r) => {
|
|
const url = new URL(r.request().url());
|
|
const json = (data) => r.fulfill({ json: data });
|
|
if (url.pathname === "/boot.js") return r.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:true};` });
|
|
if (url.pathname === "/wails/runtime.js") return r.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
|
|
if (url.pathname === "/api/state") return json(state);
|
|
if (url.pathname === "/api/plugins") return json({ plugins: [] });
|
|
if (url.pathname === "/api/gateway/trace") {
|
|
if (url.searchParams.get("wait")) return new Promise(() => {}); // nothing more comes
|
|
return json({ mine: true, now: new Date().toISOString(), seq: 1, totals: { requests: 0, rerouted: 0, errors: 0 }, routes: [] });
|
|
}
|
|
if (url.pathname === "/api/gateway/history") return json({ cut: false, days: [], routes: [] });
|
|
if (url.pathname === "/api/groups") return json(groups(members));
|
|
if (url.pathname.startsWith("/api/groups/")) {
|
|
posts.push({ path: url.pathname, body: JSON.parse(r.request().postData() || "{}") });
|
|
return json(groups(members));
|
|
}
|
|
if (url.pathname === "/api/providers") return json({ providers: [], presets: [], excluded: [], gateway: { running: true, window: true, url: "http://127.0.0.1:3999" } });
|
|
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 r.fulfill({ body: await fs.readFile(file), contentType });
|
|
};
|
|
}
|
|
|
|
async function open(engine, lang, width, members, t) {
|
|
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
|
const page = await (await browser.newContext({ viewport: { width, height: 1600 }, 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}-group-member-account.png`) });
|
|
}
|
|
await browser.close();
|
|
});
|
|
page.setDefaultTimeout(5000);
|
|
page.setDefaultNavigationTimeout(60000);
|
|
const errors = [], posts = [];
|
|
page.on("pageerror", (e) => errors.push(e.message));
|
|
await page.route("**/*", serve(lang, posts, members));
|
|
await page.goto("http://magpie.test/?view=groups");
|
|
const card = page.locator(".rt-group", { hasText: "Work" });
|
|
await card.waitFor();
|
|
return { page, card, errors, posts };
|
|
}
|
|
|
|
const option = (page, text) => page.locator("#pop:not([hidden]) #list li:not(.group)", { has: page.locator(".v", { hasText: new RegExp("^" + text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&") + "$") }) });
|
|
|
|
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]) {
|
|
const w = words[lang];
|
|
test(`${engine} ${lang} ${width}px: a model on accounts of its own, in order`, async (t) => {
|
|
const { page, card, errors, posts } = await open(engine, lang, width, ["codex/gpt-6-astra", "rl/glm-5"], t);
|
|
await card.locator("button", { hasText: w.edit }).click();
|
|
const ed = page.locator(".rt-gedit");
|
|
await ed.locator(".rt-macct").first().waitFor();
|
|
// a chip on the Codex row only: Relay has no accounts listed
|
|
assert.equal(await ed.locator(".rt-macct").count(), 1);
|
|
const chip = () => ed.locator(".rt-macct").first();
|
|
assert.equal((await chip().textContent()).trim(), w.any);
|
|
assert.doesNotMatch((await chip().getAttribute("class")) || "", /\bon\b/);
|
|
|
|
// picked from the app's menu, never a native select
|
|
await chip().click();
|
|
await option(page, "work@corp.example").waitFor();
|
|
assert.equal(await page.locator(".rt-gedit select").count(), 0);
|
|
assert.deepEqual(await page.locator("#pop #list li:not(.group) .v").allTextContents(), [w.any, "me@x.com", "work@corp.example", w.also]);
|
|
await option(page, "work@corp.example").click();
|
|
await page.waitForFunction(() => document.querySelector("#pop").hidden);
|
|
assert.equal((await chip().textContent()).trim(), "work@corp.example");
|
|
assert.match((await chip().getAttribute("class")) || "", /\bon\b/);
|
|
const codexRow = ed.locator(".fbrow", { has: page.locator(".rt-macct") }).first();
|
|
assert((await codexRow.locator(".n small").first().textContent()).includes("work@corp.example"));
|
|
|
|
// the same model on the other account: a member of its own, next
|
|
await chip().click();
|
|
await option(page, w.also).click();
|
|
await option(page, "me@x.com").waitFor();
|
|
assert.deepEqual(await page.locator("#pop:not([hidden]) #list li:not(.group) .v").allTextContents(), ["me@x.com"]);
|
|
await option(page, "me@x.com").click();
|
|
await page.waitForFunction(() => document.querySelectorAll(".rt-gedit .rt-macct").length === 2);
|
|
assert.deepEqual((await ed.locator(".rt-macct").allTextContents()).map((s) => s.trim()), ["work@corp.example", "me@x.com"]);
|
|
// on every account it has already: nothing more to add
|
|
await chip().click();
|
|
await option(page, "me@x.com").waitFor();
|
|
assert.deepEqual(await page.locator("#pop #list li:not(.group) .v").allTextContents(), [w.any, "me@x.com", "work@corp.example"]);
|
|
await page.keyboard.press("Escape");
|
|
await page.waitForFunction(() => document.querySelector("#pop").hidden);
|
|
assert.equal(await ed.locator(".rt-macct").count(), 2);
|
|
|
|
// the row fits a narrow window, the page doesn't scroll sideways
|
|
const over = await page.evaluate(() => {
|
|
const b = document.querySelector(".rt-gedit .rt-macct"), row = b.closest(".fbrow");
|
|
return { page: document.documentElement.scrollWidth - document.documentElement.clientWidth, row: b.getBoundingClientRect().right - row.getBoundingClientRect().right };
|
|
});
|
|
assert(over.page <= 0, `the page scrolls sideways by ${over.page}px`);
|
|
assert(over.row <= 1, `the account chip sticks out of its row by ${over.row}px`);
|
|
|
|
const b = page.locator(".rt-gedit button.primary", { hasText: w.save });
|
|
await b.scrollIntoViewIfNeeded();
|
|
await b.click();
|
|
await page.waitForFunction(() => !document.querySelector(".rt-gedit"));
|
|
const sent = posts.filter((p) => p.path === "/api/groups/save").at(-1).body;
|
|
assert.deepEqual(sent.members, ["codex/gpt-6-astra#" + B, "codex/gpt-6-astra#" + A, "rl/glm-5"]);
|
|
assert.deepEqual(errors, []);
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
// A group saved with members on accounts reads back with each row's
|
|
// account, and its reasoning changed on one keeps the account.
|
|
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
|
test(`${engine}: reasoning set on a member keeps its account`, async (t) => {
|
|
const { page, card, errors, posts } = await open(engine, "en", 1100, ["codex/gpt-6-astra#" + A, "codex/gpt-6-astra#" + B], t);
|
|
await card.locator("button", { hasText: "Edit" }).click();
|
|
const ed = page.locator(".rt-gedit");
|
|
await ed.locator(".rt-macct").first().waitFor();
|
|
assert.deepEqual((await ed.locator(".rt-macct").allTextContents()).map((s) => s.trim()), ["me@x.com", "work@corp.example"]);
|
|
await ed.locator(".rt-fixed:not(.rt-macct):not(.rt-fast)").nth(1).click();
|
|
await option(page, "high reasoning").click();
|
|
const b = page.locator(".rt-gedit button.primary", { hasText: "Save" });
|
|
await b.click();
|
|
await page.waitForFunction(() => !document.querySelector(".rt-gedit"));
|
|
const sent = posts.filter((p) => p.path === "/api/groups/save").at(-1).body;
|
|
assert.deepEqual(sent.members, ["codex/gpt-6-astra#" + A, "codex/gpt-6-astra:high#" + B]);
|
|
assert.deepEqual(errors, []);
|
|
});
|
|
}
|