gui: a provider's editor says Close while nothing waits for its Save
The provider editor mixes two kinds of control. An account's auto-switch, a key's concurrency and spend pills and the Claude Code rows act at once and say so in the status pill, while the rest waits for Save. Its Cancel said Cancel either way, so after a switch that had already been made, it read as if Cancel would take it back. The button now says Close while the draft matches what is saved (providerDirty, the same check Cancel's discard question asks), and Cancel once a field waits for Save. It is read again after each input, change and click in the editor. A new provider's editor keeps Cancel. Escape and the backdrop are unchanged. Tests: six files that pressed the editor's Cancel on a clean editor press its .ed-cancel now. lane-limit's draft-pill test brings the pill into sight before opening its menu: under four files at once a scroll landing after the click closed it (Chromium, 2 of 4). Run (mote, at this tree): - lane-limit.test.cjs: 24 pass. - the 29 GUI files that press an editor's Cancel, Chromium and WebKit, four at a time: 491 pass, 13 red. 12 are red on68dd531c6the same way ("Working only unpicks", "Try again takes the models unticked", #4392, #4410). The other is login-import, Chromium en, once per run under the four-way run, at a different line each time. It passed 3 of 3 alone, and at 6x and 12x CPU throttling, here and on68dd531c6. Already filed under load: #5035, #5597. - go test ./internal/gui -run 'TestCoreScriptBudget|TestI18n|TestCSS': ok. Broken by hand: lane-limit against the old app.js, 8 of 24 red (no Close, in the Relay and the Codex editor, both engines, en and zh). Not tried: the real app window, and the whole GUI suite.
This commit is contained in:
@@ -9432,6 +9432,13 @@ function duplicateProvider(p) {
|
||||
renderProviders();
|
||||
}
|
||||
|
||||
// closeWhenClean: an editor's Cancel says Close while nothing waits for its
|
||||
// Save; its switches and pills that act at once are done already
|
||||
function closeWhenClean(ed, cancel) {
|
||||
const say = () => { cancel.textContent = t(providerDirty() ? "Cancel" : "Close"); };
|
||||
for (const ev of ["input", "change", "click"]) ed.addEventListener(ev, () => setTimeout(say));
|
||||
say();
|
||||
}
|
||||
// renderEditor: an existing provider (p), a new preset (presetID), or custom.
|
||||
function renderEditor(p, presetID) {
|
||||
// its own icons, not the page's kept ones, which the rows after it take back
|
||||
@@ -9443,6 +9450,8 @@ function renderEditor(p, presetID) {
|
||||
providerDraftRef = draft;
|
||||
providerDraftBase = providerDraftValue();
|
||||
}
|
||||
const cancel = p && editor.querySelector(":scope > .bar .ed-cancel");
|
||||
if (cancel) closeWhenClean(editor, cancel);
|
||||
return editor;
|
||||
} finally { keptIcons = kept; }
|
||||
}
|
||||
@@ -9748,7 +9757,7 @@ function drawEditor(p, presetID) {
|
||||
del.title = t("{agent} stays signed in; magpie just stops offering it", { agent: a.agentName });
|
||||
del.onclick = () => providerAction("delete", { id: p.id }, t("{name} removed", { name: p.name }));
|
||||
bar.append(del, el("span", "grow"));
|
||||
const cancel = el("button", "text", t("Cancel"));
|
||||
const cancel = el("button", "text ed-cancel", t("Cancel"));
|
||||
cancel.onclick = cancelEdit;
|
||||
const saveBtn = el("button", "text primary", t("Save"));
|
||||
saveBtn.onclick = () => {
|
||||
@@ -10421,7 +10430,7 @@ function drawEditor(p, presetID) {
|
||||
bar.append(dup);
|
||||
}
|
||||
bar.append(el("span", "grow"));
|
||||
const cancel = el("button", "text", t("Cancel"));
|
||||
const cancel = el("button", "text ed-cancel", t("Cancel"));
|
||||
cancel.onclick = cancelEdit;
|
||||
const saveBtn = el("button", "text primary", t(isNew ? "Add" : "Save"));
|
||||
const save = () => {
|
||||
|
||||
@@ -87,7 +87,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
assert.deepEqual(fit, { inside: true, url: true });
|
||||
|
||||
// one with no Balance URL keeps Advanced shut, as before
|
||||
await page.locator(".editor .bar").getByRole("button", { name: await tr("Cancel"), exact: true }).click();
|
||||
await page.locator(".editor .bar .ed-cancel").click();
|
||||
await page.locator(".row.provider", { hasText: "Plain" }).click();
|
||||
assert.equal(await page.locator(".editor details.advanced").evaluate((d) => d.open), false, "nothing set, nothing opened");
|
||||
|
||||
|
||||
@@ -73,12 +73,12 @@ function serve(lang, posts, lanes) {
|
||||
const words = {
|
||||
en: {
|
||||
busy: "1/1 running · 2 queued", running: "3 running", one: "1 at once", two: "2 at once", three: "3 at once", four: "4 at once", five: "5 at once", seven: "7 at once", none: "No limit at once",
|
||||
menu: "Requests at once", def: "Provider's", other: "Other…", save: "Save", queue: "Queue size", wait: "Queue wait",
|
||||
menu: "Requests at once", def: "Provider's", other: "Other…", save: "Save", cancel: "Cancel", close: "Close", queue: "Queue size", wait: "Queue wait",
|
||||
badQueue: "Queue size: a whole number from 0 to 10000",
|
||||
},
|
||||
zh: {
|
||||
busy: "1/1 运行中 · 2 排队", running: "3 运行中", one: "并发 1", two: "并发 2", three: "并发 3", four: "并发 4", five: "并发 5", seven: "并发 7", none: "并发不限",
|
||||
menu: "同时请求数", def: "沿用提供商", other: "其他…", save: "保存", queue: "排队上限", wait: "排队等待",
|
||||
menu: "同时请求数", def: "沿用提供商", other: "其他…", save: "保存", cancel: "取消", close: "关闭", queue: "排队上限", wait: "排队等待",
|
||||
badQueue: "排队上限:0 到 10000 的整数",
|
||||
},
|
||||
};
|
||||
@@ -210,6 +210,8 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
await item(page, "2").click();
|
||||
const p = await posted(posts, n);
|
||||
assert.deepEqual(p.body, { id: "codex", account: "me@example.com", limit: 2 });
|
||||
await page.waitForTimeout(250);
|
||||
assert.equal(await page.locator(".editor > .bar .ed-cancel").textContent(), w.close, "a signed-in provider's editor says Close too");
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
@@ -247,6 +249,9 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
await box.fill("5");
|
||||
assert.equal(await pill(page, "k2").textContent(), w.five, "the provider's limit as typed");
|
||||
assert.equal(await pill(page, "k1").textContent(), w.one, "its own limit stays");
|
||||
// brought into sight first: a scroll that lands after the click closes the menu
|
||||
await pill(page, "k2").scrollIntoViewIfNeeded();
|
||||
await page.waitForTimeout(250);
|
||||
await pill(page, "k2").click();
|
||||
await menu(page).waitFor();
|
||||
assert.match(await item(page, w.def).textContent(), new RegExp(w.five), "the menu's provider's limit as typed");
|
||||
@@ -259,6 +264,34 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test(`${engine} ${lang}: the editor says Close while nothing waits for Save, and Cancel once something does`, async (t) => {
|
||||
// a key's pill acts at once, so after it there is nothing to cancel
|
||||
const lanes = { now: {}, reads: 0 };
|
||||
const { page, errors, posts } = await open(t, "Relay", lanes);
|
||||
const bar = page.locator(".editor > .bar");
|
||||
const says = () => bar.locator(".ed-cancel").textContent();
|
||||
assert.equal(await says(), w.close);
|
||||
await pill(page, "k2").click();
|
||||
await menu(page).waitFor();
|
||||
const n = posts.length;
|
||||
await item(page, "3").click();
|
||||
await posted(posts, n);
|
||||
await page.waitForTimeout(250);
|
||||
assert.equal(await says(), w.close, "a pill that acts at once leaves nothing to cancel");
|
||||
const box = page.locator(".editor input.concurrency");
|
||||
await box.fill("5");
|
||||
await page.waitForTimeout(50);
|
||||
assert.equal(await says(), w.cancel, "a typed Concurrency waits for Save");
|
||||
await box.fill("2");
|
||||
await page.waitForTimeout(50);
|
||||
assert.equal(await says(), w.close, "typed back as saved");
|
||||
await bar.getByRole("button", { name: w.close, exact: true }).click();
|
||||
await page.locator(".editor").waitFor({ state: "detached" });
|
||||
assert.equal(await page.locator(".action-confirm").count(), 0, "nothing to discard, nothing asked");
|
||||
assert.deepEqual(await page.evaluate(() => ["zh", "zh-TW", "ja", "de"].filter((l) => !I18N[l].Close)), []);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test(`${engine} ${lang}: the queue's length and wait are saved with the editor, and refused out of range`, async (t) => {
|
||||
const lanes = { now: {}, reads: 0 };
|
||||
const { page, errors, posts } = await open(t, "Relay", lanes);
|
||||
|
||||
@@ -70,7 +70,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
const link = ed.locator(".ehead .link");
|
||||
assert.equal(await link.count() ? await link.textContent() : null, links[name], `${name}: its head's link`);
|
||||
assert.deepEqual(errors, [], `${name}: nothing throws`);
|
||||
await ed.locator(".bar").getByRole("button", { name: w.cancel, exact: true }).click();
|
||||
await ed.locator(".bar .ed-cancel").click();
|
||||
await ed.waitFor({ state: "detached" });
|
||||
}
|
||||
});
|
||||
|
||||
@@ -92,7 +92,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
ed = await open("My Relay");
|
||||
assert.equal(await nameBox(ed).count(), 1, "custom: one Name box");
|
||||
assert.equal(await ed.locator("input.provider-name").count(), 0);
|
||||
await ed.locator(".bar").getByRole("button", { name: w.cancel, exact: true }).click();
|
||||
await ed.locator(".bar .ed-cancel").click();
|
||||
await ed.waitFor({ state: "detached" });
|
||||
assert.deepEqual(errors, [], "nothing throws");
|
||||
});
|
||||
|
||||
@@ -63,7 +63,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
await page.locator(".row.provider", { hasText: "Qianfan API" }).click();
|
||||
await page.locator(".editor").waitFor();
|
||||
assert.equal(await page.locator(".editor .stepplan").count(), 0);
|
||||
await page.locator(".editor .bar").getByRole("button", { name: words[lang].cancel, exact: true }).click();
|
||||
await page.locator(".editor .bar .ed-cancel").click();
|
||||
await page.locator(".editor").waitFor({ state: "detached" });
|
||||
|
||||
// the one not signed in takes a paste, for its own id
|
||||
@@ -77,7 +77,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
assert.equal(posts[0].body.text, "magpie-qianfan:{}");
|
||||
|
||||
// the one signed in signs out, for its own id
|
||||
await page.locator(".editor .bar").getByRole("button", { name: words[lang].cancel, exact: true }).click();
|
||||
await page.locator(".editor .bar .ed-cancel").click();
|
||||
await page.locator(".editor").waitFor({ state: "detached" });
|
||||
await page.locator(".row.provider", { hasText: "Qianfan Plan" }).click();
|
||||
await page.locator(".editor .stepplan").getByRole("button", { name: words[lang].out, exact: true }).click();
|
||||
@@ -87,7 +87,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
assert.equal(await page.locator(".editor .stepplan .ended").count(), 0);
|
||||
|
||||
// the one Baidu ended says so and takes a new paste, for its own id
|
||||
await page.locator(".editor .bar").getByRole("button", { name: words[lang].cancel, exact: true }).click();
|
||||
await page.locator(".editor .bar .ed-cancel").click();
|
||||
await page.locator(".editor").waitFor({ state: "detached" });
|
||||
await page.locator(".row.provider", { hasText: "Qianfan Old" }).click();
|
||||
assert.match(await page.locator(".editor .stepplan .ended").innerText(), new RegExp(words[lang].ended));
|
||||
|
||||
@@ -146,7 +146,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
// the editor's Cancel puts a waiting sign-in away: opened again, the
|
||||
// editor has Add another, not the box
|
||||
await begin();
|
||||
await page.locator(".editor .bar button", { hasText: new RegExp("^" + w.cancel + "$") }).last().click();
|
||||
await page.locator(".editor .bar .ed-cancel").click();
|
||||
await page.locator(".editor .accts").waitFor({ state: "detached" });
|
||||
for (let i = 0; i < 40 && ctl.canceled.length < 3; i++) await page.waitForTimeout(25);
|
||||
assert.deepEqual(ctl.canceled, ["q1", "q2", "q3"]);
|
||||
|
||||
@@ -68,7 +68,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
assert.equal(posts[0].body.text, "magpie-stepfun:{}");
|
||||
|
||||
// the one signed in signs out, for its own id
|
||||
await page.locator(".editor .bar").getByRole("button", { name: words[lang].cancel, exact: true }).click();
|
||||
await page.locator(".editor .bar .ed-cancel").click();
|
||||
await page.locator(".editor").waitFor({ state: "detached" });
|
||||
await page.locator(".row.provider", { hasText: "StepFun" }).filter({ hasNotText: "Work" }).click();
|
||||
await page.locator(".editor .stepplan").getByRole("button", { name: words[lang].out, exact: true }).click();
|
||||
|
||||
Reference in New Issue
Block a user