tz_188 on v0.1.3122: three ZCode sessions at once on Routing, each named
by a long one-line prompt ("这个commit 中的内容帮我再核对一下
51538fc170c6…", a path under /Users/lbx_16/work/b2b/b2b-platform). Every
name ran past its block and over the next blocks' names, so the three
read as one smear. 7a2b9340d had folded line breaks in the name; this is
another cause. The block (.rt-ctx-s) is a <button> laid out as a flex
column. WebKit up to Safari 17 (macOS 14) puts a flex button's children
in an anonymous box of its own, and in a column that box is as wide as
the name's whole nowrap line, so .nm's overflow: hidden clipped nothing
inside the 180px block. Today's Chromium and WebKit don't, which is why
the earlier test (and Playwright 1.62) never saw it. The block is now a
grid of one minmax(0, 1fr) column: a grid button has no such box, and
each name ends in its ellipsis; the whole title is still on hover.
Siblings: a scan of every CSS rule with flex-direction: column against
every class a <button> is made with (el("button"), <button class>,
createElement + className/classList) finds .rt-ctx-s only. Row flex,
block and grid buttons clip correctly in WebKit 17 (probed).
Run (mote, via mote-run):
- routing-ctx-sessions.test.cjs, Playwright 1.62 chromium + webkit:
98/98. New case: three sessions with tz_188's title, a hash and a path,
en/zh/zh-TW/ja/de at 1600/1100/700/390px; each name inside its block's
padding box, cut short (scrollWidth > clientWidth), title on hover, no
page overflow, and the block not a column flex button.
- the same case with Playwright 1.36's WebKit 17.0 (NODE_PATH and
PLAYWRIGHT_BROWSERS_PATH to a separate install on mote): 20/20 pass.
- the whole routing-* GUI set (171 files): 2838 of 2870 pass. The 32 reds
are in routing-intent-entry, many-keys, order-unknown, row-swap,
rule-drag, rule-models, rule-remove, steady, steps-cap and
story-shrinks, the same files 7a2b9340d listed as red on its main (with
rule-models added); none of them reads .rt-ctx-s. Their base-vs-change
comparison is run after this push.
Broken by hand: the old flex CSS put back, WebKit 17.0 red 20/20 ("the
name "/Users/lbx_1" stays inside its block: 44..1174 in 44..228"), and
Playwright 1.62 red 40/40 on the column-flex guard.
Not tried: the reporter's full title bytes (only the screenshot; two of
the three titles are made up from its visible words), the real app's
WKWebView on macOS 14, Windows and Linux, the whole GUI suite (only
routing-*).
Reported-by: tz_188 (Discord)
261 lines
17 KiB
JavaScript
261 lines
17 KiB
JavaScript
// Run with Node's test runner and Playwright on the module path; see README.md.
|
|
// tjhhhh on Discord: with several sessions running through magpie at once,
|
|
// the Routing page's context window went from one session's context to the
|
|
// other's, and which was which couldn't be told. Each session sending now
|
|
// has a small block of its own under the card, named as its agent named it
|
|
// (not its id), with its own newest reading; the newest session comes
|
|
// first and the blocks keep their places while the sessions take turns.
|
|
// Two Codex conversations' requests interleave here; every frame's blocks
|
|
// are watched. A block clicked tells of that session's newest request. One
|
|
// session alone shows none. Every language, both engines, a phone's width.
|
|
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 iso = (ms) => new Date(ms).toISOString();
|
|
const t0 = Date.now();
|
|
const seat = { id: "codex@me", provider: "codex", name: "ChatGPT", who: "me@example.com", kind: "account", model: "gpt-6.1-sol", known: true, plan: "Pro" };
|
|
const SESS = {
|
|
a: { id: "019a7c2e-aaaa-7000-8000-000000000001", title: "Fix the login redirect", folder: "/Users/me/work/web", base: 40000, window: 272000 },
|
|
b: { id: "019a7c2e-bbbb-7000-8000-000000000002", title: "Write the release notes", folder: "/Users/me/work/docs", base: 150000, window: 272000 },
|
|
};
|
|
// a request of session s, its prompt growing by n
|
|
const prompt = (s, n) => ({
|
|
window: SESS[s].window, tokens: SESS[s].base + n * 1000, counted: true, turns: n,
|
|
parts: [
|
|
{ kind: "system", tokens: 9000, items: [{ name: "prompt", tokens: 9000 }] },
|
|
{ kind: "chat", tokens: SESS[s].base - 9000 + n * 1000, items: [{ name: "turn", tag: "turns", n, tokens: SESS[s].base - 9000 + n * 1000 }] },
|
|
],
|
|
});
|
|
let seq = 10;
|
|
function req(id, s, done = true, titled = true) {
|
|
const at = t0 - (200 - id) * 1000;
|
|
return {
|
|
id, seq: ++seq, time: iso(at), agent: "codex", session: SESS[s].id, folder: SESS[s].folder, model: "gpt-6.1-sol", provider: "codex",
|
|
...(titled ? { sessionTitle: SESS[s].title } : {}),
|
|
order: [seat], tries: [{ id: seat.id, model: seat.model, start: iso(at), done, ...(done ? { status: 200, ms: 3000 } : {}) }],
|
|
done, ...(done ? { status: 200, ms: 3000, tokens: 900 } : {}), prompt: prompt(s, id - 100),
|
|
};
|
|
}
|
|
|
|
function serve(lang, first, feed) {
|
|
const state = { agents: [{ id: "codex", name: "Codex", path: "/test/codex", fields: [] }], profiles: [], settings: { lang, theme: "light" } };
|
|
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(state);
|
|
if (url.pathname === "/api/gateway/trace") {
|
|
const trace = (routes) => json({ mine: true, now: new Date().toISOString(), seq: routes.length ? routes[routes.length - 1].seq : Number(url.searchParams.get("after")), totals: { requests: 0, rerouted: 0, errors: 0 }, routes });
|
|
if (!url.searchParams.get("wait")) return trace(first);
|
|
const rs = await new Promise((res) => { feed.next = res; });
|
|
return trace(rs);
|
|
}
|
|
if (url.pathname === "/api/gateway/history") return json({ cut: false, days: [], routes: [] });
|
|
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 route.fulfill({ body: await fs.readFile(file).catch(() => ""), contentType });
|
|
};
|
|
}
|
|
|
|
async function open(browser, lang, width, first) {
|
|
const context = await browser.newContext({ viewport: { width, height: 900 } });
|
|
const page = await context.newPage();
|
|
page.setDefaultTimeout(5000);
|
|
page.setDefaultNavigationTimeout(60000);
|
|
const errors = [];
|
|
page.on("pageerror", (e) => errors.push(e.message));
|
|
const feed = { next: null };
|
|
await page.route("**/*", serve(lang, first, feed));
|
|
await page.goto("http://magpie.test/?view=routing");
|
|
await page.locator(".rt-req").first().waitFor();
|
|
await page.locator(".rt-ctx .ctx-card").waitFor();
|
|
const send = async (...rs) => {
|
|
for (let i = 0; i < 100 && !feed.next; i++) await page.waitForTimeout(50);
|
|
const next = feed.next;
|
|
assert(next, "the page asks for the next trace");
|
|
feed.next = null;
|
|
next(rs);
|
|
await page.waitForTimeout(300);
|
|
};
|
|
return { context, page, errors, send };
|
|
}
|
|
|
|
const blocks = (page) => page.$$eval(".rt-ctx-sess:not([hidden]) .rt-ctx-s", (bs) => bs.map((b) => ({
|
|
name: b.querySelector(".nm").textContent, sub: b.querySelector(".sub").textContent, on: b.getAttribute("aria-pressed") === "true",
|
|
})));
|
|
|
|
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
|
test(`${engine}: each session sending at once has its own context window, by its name`, async (t) => {
|
|
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
|
t.after(() => browser.close());
|
|
for (const lang of ["en", "zh", "zh-TW", "ja", "de"]) {
|
|
for (const width of [1100, 390]) {
|
|
await t.test(`${lang} ${width}px`, async () => {
|
|
// session a began first, then b: b is the newer session
|
|
const { context, page, errors, send } = await open(browser, lang, width, [req(101, "a"), req(102, "b")]);
|
|
t.after(() => context.close());
|
|
await page.locator(".rt-ctx-sess:not([hidden]) .rt-ctx-s").nth(1).waitFor();
|
|
const label = await page.evaluate(([l]) => (l === "en" ? "Each session's context window" : I18N[l]?.["Each session's context window"]), [lang]);
|
|
assert.ok(label, `the strip's label has its ${lang}`);
|
|
assert.equal(await page.locator(".rt-ctx-sess").getAttribute("aria-label"), label);
|
|
|
|
// watch every frame's blocks from here on
|
|
await page.evaluate(() => {
|
|
window.__frames = [];
|
|
window.__on = true;
|
|
const tick = () => {
|
|
window.__frames.push([...document.querySelectorAll(".rt-ctx-sess:not([hidden]) .rt-ctx-s")].map((b) => [b.querySelector(".nm").textContent, b.querySelector(".sub").textContent]));
|
|
if (window.__on) requestAnimationFrame(tick);
|
|
};
|
|
requestAnimationFrame(tick);
|
|
});
|
|
// the sessions take turns, a's and b's requests interleaved
|
|
await send(req(103, "a", false));
|
|
await send(req(103, "a"), req(104, "b", false));
|
|
await send(req(104, "b"), req(105, "a"));
|
|
await send(req(106, "b"));
|
|
const frames = await page.evaluate(() => { window.__on = false; return window.__frames; });
|
|
assert(frames.length > 10, `frames were watched: ${frames.length}`);
|
|
const k = (n) => Math.round(n / 1000) + "K";
|
|
for (const f of frames) {
|
|
// the newest session first, each in its place, by its title
|
|
assert.deepEqual(f.map((x) => x[0]), [SESS.b.title, SESS.a.title], `the blocks kept their places: ${JSON.stringify(f)}`);
|
|
// each block says its own session's reading, never the other's
|
|
assert.match(f[0][1], new RegExp(`^Codex · (${k(SESS.b.base + 2000)}|${k(SESS.b.base + 4000)}|${k(SESS.b.base + 6000)}) / 272K`), JSON.stringify(f));
|
|
assert.match(f[1][1], new RegExp(`^Codex · (${k(SESS.a.base + 1000)}|${k(SESS.a.base + 3000)}|${k(SESS.a.base + 5000)}) / 272K`), JSON.stringify(f));
|
|
}
|
|
let bs = await blocks(page);
|
|
assert.deepEqual(bs.map((b) => b.sub), [`Codex · ${k(SESS.b.base + 6000)} / 272K · ${Math.round((SESS.b.base + 6000) / 2720)}%`, `Codex · ${k(SESS.a.base + 5000)} / 272K · ${Math.round((SESS.a.base + 5000) / 2720)}%`]);
|
|
// the card tells of b's 106; its block is the one lit, and the
|
|
// card names the session by its title, not its id
|
|
assert.deepEqual(bs.map((b) => b.on), [true, false]);
|
|
const crumbs = await page.locator(".rt-ctx .ctx-crumbs").textContent();
|
|
assert.ok(crumbs.includes(SESS.b.title.slice(0, 20)), crumbs);
|
|
assert.ok(!crumbs.includes(SESS.b.id.slice(0, 8)), crumbs);
|
|
|
|
// a's block clicked: the card tells of a's newest, 105
|
|
await page.locator(".rt-ctx-s").nth(1).click();
|
|
await page.waitForFunction(() => document.querySelectorAll(".rt-ctx-s")[1]?.getAttribute("aria-pressed") === "true");
|
|
assert.ok((await page.locator(".rt-ctx .ctx-crumbs").textContent()).includes("#105"));
|
|
assert.ok((await page.locator(".rt-ctx .ctx-crumbs").textContent()).includes(SESS.a.title.slice(0, 20)));
|
|
bs = await blocks(page);
|
|
assert.deepEqual(bs.map((b) => b.name), [SESS.b.title, SESS.a.title], "a click doesn't move the blocks");
|
|
|
|
// at a phone's width the blocks fit the page: nothing runs off it
|
|
const over = await page.evaluate(() => {
|
|
const s = document.querySelector(".rt-ctx-sess").getBoundingClientRect();
|
|
return [...document.querySelectorAll(".rt-ctx-s")].some((b) => b.getBoundingClientRect().right > s.right + 0.5) || document.documentElement.scrollWidth > innerWidth;
|
|
});
|
|
assert.equal(over, false, "the blocks stay inside the page");
|
|
assert.deepEqual(errors, []);
|
|
});
|
|
}
|
|
}
|
|
});
|
|
|
|
test(`${engine}: one session alone shows no blocks, and one with no title is named by its folder`, async (t) => {
|
|
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
|
t.after(() => browser.close());
|
|
const { context, page, errors, send } = await open(browser, "en", 1100, [req(101, "a"), req(102, "a")]);
|
|
t.after(() => context.close());
|
|
await page.waitForTimeout(300);
|
|
assert.equal(await page.locator(".rt-ctx-sess").isHidden(), true, "one session: the card is its own");
|
|
// b comes in without a title yet: named by its folder, never its id
|
|
await send(req(103, "b", true, false));
|
|
await page.locator(".rt-ctx-sess:not([hidden]) .rt-ctx-s").nth(1).waitFor();
|
|
assert.deepEqual((await blocks(page)).map((b) => b.name), ["docs", SESS.a.title]);
|
|
assert.deepEqual(errors, []);
|
|
});
|
|
// tz_188 on Discord: ZCode's sessions are named by their first prompt,
|
|
// a long Chinese one of several lines. WebKit breaks a line at U+2028
|
|
// and U+2029 even where a name is kept to one, so each block stacked
|
|
// the prompt's lines. Its bar took context.css's flex: 1 1 0, so in a
|
|
// block as tall as its lines it was 0px high, and in a shorter block
|
|
// beside a taller one it stretched to fill it. Each name is one line in
|
|
// every block, at every width, in every language, and every bar is 4px.
|
|
test(`${engine}: a session named by a prompt of many lines is one line in its block`, async (t) => {
|
|
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
|
t.after(() => browser.close());
|
|
const prompt = "你的唯一任务是采集并分析用户提供的所有网页内容,逐条提取关键信息。\u2028要求:\u2029一、严格按照格式输出;\r\n二、保留原文中的数字与链接;\u0085三、不要遗漏任何一条。\n\n";
|
|
const titles = { a: SESS.a.title, b: SESS.b.title };
|
|
t.after(() => { SESS.a.title = titles.a; SESS.b.title = titles.b; });
|
|
SESS.a.title = prompt.repeat(40);
|
|
SESS.b.title = prompt;
|
|
for (const lang of ["en", "zh", "zh-TW", "ja", "de"]) {
|
|
for (const width of [1100, 700, 390]) {
|
|
await t.test(`${lang} ${width}px`, async () => {
|
|
const { context, page, errors } = await open(browser, lang, width, [req(101, "a"), req(102, "b"), req(103, "a")]);
|
|
t.after(() => context.close());
|
|
await page.locator(".rt-ctx-sess:not([hidden]) .rt-ctx-s").nth(1).waitFor();
|
|
const got = await page.$$eval(".rt-ctx-s", (bs) => bs.map((b) => {
|
|
const h = (q) => b.querySelector(q).getBoundingClientRect().height;
|
|
return { name: b.querySelector(".nm").textContent, nm: h(".nm"), sub: h(".sub"), bar: h(".ctx-stack") };
|
|
}));
|
|
assert.equal(got.length, 2);
|
|
for (const g of got) {
|
|
assert.ok(!/[\n\r\u2028\u2029\u0085]/.test(g.name), `the name is one line of text: ${JSON.stringify(g.name.slice(0, 80))}`);
|
|
assert.ok(g.name.startsWith("你的唯一任务是采集并分析用户提供的所有网页内容,逐条提取关键信息。 要求: 一、"), g.name.slice(0, 80));
|
|
assert.ok(g.nm < 2 * g.sub, `the name is drawn on one line: ${g.nm}px against the sub-line's ${g.sub}px`);
|
|
assert.equal(Math.round(g.bar), 4, `the bar keeps its 4px: ${g.bar}`);
|
|
}
|
|
const crumbs = await page.locator(".rt-ctx .ctx-crumbs").textContent();
|
|
assert.ok(!/[\n\r\u2028\u2029\u0085]/.test(crumbs), "the card's crumbs name it on one line too");
|
|
assert.deepEqual(errors, []);
|
|
});
|
|
}
|
|
}
|
|
});
|
|
// tz_188 on Discord again, on v0.1.3122: three ZCode sessions at once,
|
|
// each named by a long first prompt of one line. Every name ran past its
|
|
// block and over the next blocks' names, so the three read as one smear.
|
|
// WebKit up to Safari 17 (macOS 14) puts a flex <button>'s children in
|
|
// a box of its own, and in a column that box was as wide as the name's
|
|
// whole line; today's engines don't, so the block is held to a grid here
|
|
// too. Each name ends in its ellipsis inside its own block: CJK, a
|
|
// commit hash and a path alike, with the whole title on hover. Run with
|
|
// Playwright 1.36's WebKit 17.0 on the module path, the old flex block
|
|
// is red on "stays inside its block".
|
|
test(`${engine}: a long session name is cut short inside its own block`, async (t) => {
|
|
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
|
t.after(() => browser.close());
|
|
const names = {
|
|
a: "这个commit 中的内容帮我再核对一下 51538fc170c6deb069c2aaee7b49e004408d,项目在 /Users/lbx_16/work/b2b/b2b-platform。 ...",
|
|
b: "只读,不要修改任何文件:对比 51538fc170c6deb069c2aaee7b49e004408d 和上一个提交,/Users/lbx_16/work/b2b/b2b-platform/src/main/java/com/example/order/OrderService.java",
|
|
c: "/Users/lbx_16/work/b2b/b2b-platform/src/main/resources/mapper/order/OrderDetailMapperExtension.xml51538fc170c6deb069c2aaee7b49e004408d51538fc170c6deb069c2aaee7b49e004408d",
|
|
};
|
|
const was = { a: SESS.a.title, b: SESS.b.title };
|
|
SESS.c = { id: "019a7c2e-cccc-7000-8000-000000000003", folder: "/Users/lbx_16/work/b2b/b2b-platform", base: 233000, window: 1000000 };
|
|
t.after(() => { SESS.a.title = was.a; SESS.b.title = was.b; delete SESS.c; });
|
|
for (const k of ["a", "b", "c"]) SESS[k].title = names[k];
|
|
for (const lang of ["en", "zh", "zh-TW", "ja", "de"]) {
|
|
for (const width of [1600, 1100, 700, 390]) {
|
|
await t.test(`${lang} ${width}px`, async () => {
|
|
const { context, page, errors } = await open(browser, lang, width, [req(101, "a"), req(102, "b"), req(103, "c")]);
|
|
t.after(() => context.close());
|
|
await page.locator(".rt-ctx-sess:not([hidden]) .rt-ctx-s").nth(2).waitFor();
|
|
const got = await page.$$eval(".rt-ctx-s", (bs) => bs.map((b) => {
|
|
const nm = b.querySelector(".nm"), box = b.getBoundingClientRect(), r = nm.getBoundingClientRect(), cs = getComputedStyle(b);
|
|
return { name: nm.textContent, title: b.title, left: r.left, right: r.right, inLeft: box.left + parseFloat(cs.borderLeftWidth) + parseFloat(cs.paddingLeft), inRight: box.right - parseFloat(cs.borderRightWidth) - parseFloat(cs.paddingRight), cut: nm.scrollWidth > nm.clientWidth, flex: cs.display.endsWith("flex") && cs.flexDirection.startsWith("column") };
|
|
}));
|
|
assert.deepEqual(got.map((g) => g.name).sort(), Object.values(names).sort());
|
|
for (const g of got) {
|
|
assert.ok(g.left >= g.inLeft - 0.5 && g.right <= g.inRight + 0.5, `the name ${JSON.stringify(g.name.slice(0, 12))} stays inside its block: ${g.left}..${g.right} in ${g.inLeft}..${g.inRight}`);
|
|
assert.equal(g.flex, false, "a block is no column flex <button>, whose names WebKit 17 lets run out of it");
|
|
assert.ok(g.cut, `the name ${JSON.stringify(g.name.slice(0, 12))} is cut short, to end in its ellipsis`);
|
|
assert.ok(g.title.startsWith(g.name + "\n"), "the whole name shows on hover");
|
|
}
|
|
assert.equal(await page.evaluate(() => document.documentElement.scrollWidth > innerWidth), false, "nothing widens the page");
|
|
assert.deepEqual(errors, []);
|
|
});
|
|
}
|
|
}
|
|
});
|
|
}
|