The owner, 10-20: Settings › General held Codex subagents, Long
conversations, Codex background compaction, thread titles, thread
descriptions, composer predictions, the auto-review model and the
memories model, apart from the agents they set; "很割裂、很分散,不直观".
They now sit with their agent (AGENT_PREFS): in its opened row on the
Agents page (a Settings list in connectPanel), in a sheet from the
tray panel's row ("Settings" line, openAgentPrefs) and from the agent's
menu ("{agent} settings"). Each row is the one element moved between
those places, so its handlers and state go with it. Settings' search
still finds them, with a row that opens the agent's sheet
(#agentPrefLinks). A gateway has no Agents page and none of them.
Strings for zh, zh-TW, ja and de; docs (reference, agent-wiring,
gui-shell) point at the new place. app.js 1,277,298 bytes and the core
scripts 1,469,058, so both budgets rise.
Run on 6416d639c (the dialog morph, on origin/main 75e769a9f), macOS,
playwright 1.62.0:
- agent-prefs.test.cjs (new) plus the 10 migrated files (codex-titles,
codex-descriptions, codex-auto-review, codex-predictions,
codex-memories-settings, codex-async-compact, compact-at,
settings-general, bare-ids, gateway-mode) and modal-morph: 152/152,
chromium and webkit, every language, wide and 420px.
- go test ./internal/gui/: ok after the budget rise.
- gofmt -l clean; go vet darwin, GOOS=linux -tags nogui, GOOS=windows.
Two GUI tests leaned on the Agents page's old height and are moved with it:
agent-models-loading clicked "elsewhere" at (900, 650), which is now
Codex's Disconnect button in its opened row, so it clicks the page's lead
line; agent-expand-steady clicked Goose's row while Codex's opened row
(~554px with its settings) pushed it out of a 560px view, so it wheels
Goose's link into sight first (reader.cjs reach). codex-subagents-lead
and agent-models-redraw clicked controls below Codex's opened row and
timed out in WebKit ("outside of the viewport"); they wait for the row to
finish sliding open, then wheel the control into sight. With Settings ›
General shorter, segs-press-redraw's sweep left Usage's warm-up tabs
above the view in WebKit; it wheels them back when they are. panel-effort
opened Kimi's row below Codex's opened one the same way. login-allow's
wheel loop read the shorter General page's button 50ms after each wheel and
clicked beside it (de, 440px); it uses reach. mobile-web shut each agent
picker by tapping the Agents tab, which a picker opened low in Codex's
taller row covers on a phone; it taps the header's name (the lead line
can sit under the header's tabs, and a tap there opened Library), wheels
each row and field into sight before tapping it, and says which agent and
field a step timed out on. All seven pass in Chromium and WebKit.
After the rebase onto main (32 commits on), with the test fixes above:
- go test ./internal/gui/ ./internal/plugin/ ./internal/agent/ ok;
gofmt -l clean; go vet GOOS=linux -tags nogui and GOOS=windows.
- 95 GUI files (every agent-, codex-, claude-, settings- and modal- file,
and every file either side changed): 1375 pass; the 8 reds were
segs-press-redraw, fixed above. The 16 other files that click an
Agents row: 369/370, rail-tip red on main too (#3091).
- The full suite's reds are listed in the dialog morph's commit; each was
run alone on this head and on origin/main.
- mobile-web's "desktop matches origin/main" compares Settings and the
Agents page with main's assets, so it is red until this is on main; its
phone checks pass in Chromium and WebKit.
154 lines
8.0 KiB
JavaScript
154 lines
8.0 KiB
JavaScript
// The app deliberately undoes unsolicited scrollIntoView (including Playwright's
|
|
// automatic scroll). Bring a control into sight with real wheel input first.
|
|
// Wholly in sight: one cut off by a fraction of a pixel at the view's foot
|
|
// was scrolled the rest of the way by Playwright's click itself, before the
|
|
// app saw the click, and the page moved 1px under it (860 to 861 on the
|
|
// Usage page's Fetch from archive, once the archive switch in its header
|
|
// had moved the rows 4px down).
|
|
async function inView(page, locator) {
|
|
await locator.waitFor({state:"visible"});
|
|
if (await locator.evaluate(e => !e.closest("#view-usage"))) return;
|
|
const view = page.locator("#view-usage");
|
|
const v = await view.boundingBox();
|
|
await page.mouse.move(v.x + v.width / 2, v.y + v.height / 2);
|
|
for (let i = 0; i < 80; i++) {
|
|
const b = await locator.boundingBox();
|
|
if (!b) { await page.waitForTimeout(40); continue; }
|
|
// one taller than the view: its top in sight
|
|
if (b.y >= v.y && (b.y + b.height <= v.y + v.height || (b.height > v.height && b.y < v.y + v.height))) {
|
|
await page.waitForTimeout(300);
|
|
return;
|
|
}
|
|
const delta = b.y < v.y ? -20 : 20;
|
|
await page.mouse.wheel(0, delta);
|
|
await page.waitForTimeout(40);
|
|
}
|
|
throw new Error("control did not come into sight: " + JSON.stringify({view:v,target:await locator.boundingBox(),scroll:await view.evaluate(e=>e.scrollTop)}));
|
|
}
|
|
|
|
// reach is inView for any page: the reader wheels the view the control is
|
|
// in (its .view) until the control is wholly in that view and nothing drawn
|
|
// over it (a sticky bar, the window's foot) takes the point Playwright will
|
|
// press. Playwright's own scroll is put back by the app, as any scroll that
|
|
// isn't the reader's, and one partly in sight it doesn't scroll at all, so
|
|
// its press can wait on a control out of sight or under a bar till it times
|
|
// out (in WebKit; Chromium gets through some of these by a few pixels).
|
|
// Each wheel step waits for its scroll to land before the control is
|
|
// looked at again: a wheel's scroll reaches the page a frame or more after
|
|
// it is sent, and on a busy machine a fixed pause read where the control
|
|
// was before it. The next step was sent on that stale reading, the view
|
|
// went past the control, under the header, and the click that followed
|
|
// was on a control out of sight (#2370).
|
|
async function reach(page, locator) {
|
|
await locator.waitFor({ state: "visible" });
|
|
const id = await locator.evaluate((e) => e.closest(".view")?.id || "");
|
|
if (!id) return;
|
|
const v = await page.locator("#" + id).boundingBox();
|
|
await page.mouse.move(v.x + v.width / 2, v.y + v.height / 2);
|
|
let stalls = 0;
|
|
for (let i = 0; i < 120; i++) {
|
|
const at = await locator.evaluate((e) => {
|
|
const b = e.getBoundingClientRect(), v = e.closest(".view").getBoundingClientRect();
|
|
const x = b.left + b.width / 2, y = b.top + b.height / 2;
|
|
const inside = b.top >= v.top && b.bottom <= v.bottom, hit = document.elementFromPoint(x, y);
|
|
return { clear: inside && !!hit && (e === hit || e.contains(hit)), down: y > v.top + v.height / 2 };
|
|
});
|
|
if (at.clear) { await page.waitForTimeout(300); return; }
|
|
// landed, or the view is at its end and the wheel moves nothing: three
|
|
// of those in turn and the control can't be brought clear
|
|
stalls = (await wheeled(page, id, at.down ? 20 : -20)) ? 0 : stalls + 1;
|
|
if (stalls >= 3) break;
|
|
}
|
|
throw new Error("control did not come clear into sight: " + JSON.stringify({ view: v, target: await locator.boundingBox() }));
|
|
}
|
|
|
|
// wheeled sends one wheel over the view and waits for its scroll to land;
|
|
// false when the view didn't move in a second (it is at its end).
|
|
async function wheeled(page, id, dy) {
|
|
const was = await page.locator("#" + id).evaluate((v) => v.scrollTop);
|
|
await page.mouse.wheel(0, dy);
|
|
return page.waitForFunction(([id, was]) => document.getElementById(id).scrollTop !== was, [id, was], { timeout: 1000 }).then(() => true, () => false);
|
|
}
|
|
|
|
// wheelTo scrolls the page the way a reader does, down till the control's
|
|
// top is at y or above, so a click that moved the page would show; then
|
|
// reach makes sure it is clear in sight. Each wheel lands before the
|
|
// control is looked at again (#2370).
|
|
async function wheelTo(page, locator, y) {
|
|
await locator.waitFor({ state: "visible" });
|
|
const id = await locator.evaluate((e) => e.closest(".view")?.id || "");
|
|
const v = await page.locator("#" + id).boundingBox();
|
|
await page.mouse.move(v.x + v.width / 2, v.y + v.height / 2);
|
|
for (let i = 0; i < 80; i++) {
|
|
if ((await locator.evaluate((e) => e.getBoundingClientRect().top)) <= y) break;
|
|
if (!(await wheeled(page, id, 50))) break;
|
|
}
|
|
await reach(page, locator);
|
|
}
|
|
|
|
async function click(page, locator) {
|
|
await inView(page, locator);
|
|
await locator.click();
|
|
}
|
|
|
|
// Settings is drawn from each read of the settings, and opening the page
|
|
// reads them twice: the page's own read, then the window's load() once the
|
|
// state is in. Every row is replaced by the second draw, so a row found
|
|
// after the first is detached under whatever the test does to it next
|
|
// (#1653: scrollIntoViewIfNeeded in WebKit on a busy machine). Call
|
|
// watchSettingsReads before page.goto; settingsDrawn then waits until load()
|
|
// has asked for its read and every read asked for has been drawn. A page is
|
|
// watched once however many times it is opened.
|
|
const watched = new WeakSet();
|
|
async function watchSettingsReads(page) {
|
|
if (watched.has(page)) return;
|
|
watched.add(page);
|
|
await page.addInitScript(() => {
|
|
const reads = window.__settingsReads = { asked: 0, drawn: 0 };
|
|
const fetch0 = window.fetch;
|
|
window.fetch = function (input, init) {
|
|
const p = fetch0.apply(this, arguments);
|
|
const url = new URL(typeof input === "string" ? input : input.url, location.href);
|
|
if (url.pathname !== "/api/settings" || (init?.method || "GET") !== "GET") return p;
|
|
reads.asked++;
|
|
// drawn a task after its body is in: loadSettings draws in the
|
|
// microtasks that follow
|
|
const drawn = () => setTimeout(() => reads.drawn++);
|
|
return p.then((res) => {
|
|
const text = res.text;
|
|
res.text = function () { return text.call(this).finally(drawn); };
|
|
return res;
|
|
}, (e) => { drawn(); throw e; });
|
|
};
|
|
});
|
|
}
|
|
|
|
// load.done is set in the same run of load() that then asks for the
|
|
// settings, with no wait between, so once it is set the read is counted.
|
|
const settingsDrawn = (page) => page.waitForFunction(() => load.done && __settingsReads.asked === __settingsReads.drawn);
|
|
|
|
// openPart opens a part of Settings (a tab, or its entry in the sidebar's
|
|
// strip) the way the keyboard does. A click waits for the tab to hold still
|
|
// over two animation frames, and on a loaded machine WebKit draws no frames
|
|
// for seconds while the page itself runs on, so the click can sit out the
|
|
// test's whole timeout over a tab that isn't moving (#2150). Enter on the
|
|
// focused button clicks it with no frame to wait for.
|
|
async function openPart(page, id) {
|
|
await page.locator(`:is(#setTab-${id}, .nav-s[data-of=setTab-${id}]):visible`).press("Enter");
|
|
}
|
|
|
|
// agentRow is a connected agent as /api/state lists it, opened by its
|
|
// Details; openAgentSettings opens it on the Agents page, where its own
|
|
// settings are (Settings had them till the owner, 10-20), and waits till
|
|
// they are read and drawn. Watch the settings reads first.
|
|
const agentRow = (id, name) => ({ id, name, icon: id, wired: true, fields: [{ key: "model", label: "model", value: "relay/m1", options: [{ value: "relay/m1", label: "m1", ref: "relay/m1" }] }] });
|
|
async function openAgentSettings(page, id = "codex") {
|
|
const link = page.locator(`.row.agent[data-id="${id}"] .ag-link`);
|
|
await reach(page, link);
|
|
await link.click();
|
|
await page.locator(`.row.agent[data-id="${id}"] .ag-prefs`).waitFor();
|
|
await page.waitForFunction(() => __settingsReads.asked > 0 && __settingsReads.asked === __settingsReads.drawn);
|
|
}
|
|
|
|
module.exports = { inView, reach, wheelTo, click, openPart, watchSettingsReads, settingsDrawn, agentRow, openAgentSettings };
|