routing: the last request's story shrinks back on a busy gateway too (shensmart on Discord)
shensmart on Discord (a remote magpie, the page in a local browser): the room under "How the last request was routed" grew with use and, once stretched, never shrank back. Cause (internal/gui/assets/plugins/routing/client.js, holdStory): the story is held at the tallest of the last STORY_HELD requests so the page doesn't jump between requests (dumplings' jitter, routing-ctx-still), and0455b9279made a long one drop out after three. But only a request drawn while answered was counted. On a busy gateway a request is answered as the next starts, both come in one trace, and the newest (the one drawn) is always under way, so nothing new was ever counted and a long story held the box at its height for good. What changed: every request drawn live counts, answered or under way, at the height it has now (the map is renamed done -> told). The anti-jump hold is kept: a request under way is still held at the answered one before it, and a sequential agent behaves as before. Once three newer requests have been told, a long one stops holding the box. No new UI. Guarded by a new case in internal/gui/tests/routing-story-shrinks.test.cjs: a request handed on four times, then traces that each carry one request answered and the next started. en at 1100px and zh at 420px, Chromium and WebKit. On the old client.js (f81913994) it is 0/4 red: "the box shrank back with the newest always under way: 247.5 vs 247.5 (min-height 247.5px)" (en), 356.25 vs 356.25 (zh); the original four cases passed. Run (macOS, NODE_PATH playwright 1.62.0, log kept whole in a file): - Atf81913994+ this change: every internal/gui/tests/routing-*.test.cjs, panel-routing*.test.cjs and i18n-keys.test.cjs, both engines: 1229/1229 pass. go test -count=1 ./internal/gui: ok (83s). - Rebased on origin/mainc4a5e6153(one provider-only commit, nothing under internal/gui), head tree of this commit: routing-story-shrinks, routing-ctx-still and i18n-keys again, 29/29 pass. Not tried: shensmart's own remote magpie and traffic; their version is unknown, and if it predates v0.1.1326 (0455b9279) the plain "long story held for good" case is what they saw, which that release already fixes. No full Go suite (only JS and the gui package changed). Not tried in the real Linux WebKitGTK app (no motion or new browser API involved).
This commit is contained in:
@@ -2010,40 +2010,43 @@ function routingPage(part) {
|
||||
bodies.replaceChildren(grid);
|
||||
}
|
||||
// holdStory keeps the story of the live request, its head and its lines,
|
||||
// as tall as the tallest of the last few requests answered, at this
|
||||
// as tall as the tallest of the last few requests told, at this
|
||||
// width: a request under way is told in fewer lines than one answered
|
||||
// ("is answering…", then "answered in 4.0 s…" over two lines at a
|
||||
// phone's width), and its head gets View usage and Replay, taller than
|
||||
// the words, once it is done. So each new request moved the context
|
||||
// window under it up and back down (dumplings on Discord: the card
|
||||
// jittered on every request). Only the last STORY_HELD answered count: one
|
||||
// jittered on every request). Only the last STORY_HELD told count: one
|
||||
// told in many lines (a request handed on from member to member) no
|
||||
// longer holds the box that tall for good, and it shrinks back once
|
||||
// that many shorter ones have come after it (夜松云 on Discord: the box
|
||||
// grew and never shrank back). A request picked, a replay or a past day
|
||||
// is drawn at its own height. A change of width measures it again at
|
||||
// grew and never shrank back). Each request told counts, answered or
|
||||
// under way, at the height it has now: on a busy gateway a request is
|
||||
// answered as the next starts, the two come in one trace, and the
|
||||
// newest is always under way, so counting only those told answered
|
||||
// held the long one for good (shensmart on Discord, a remote magpie in
|
||||
// a local browser: the room grew with use). A request picked, a replay
|
||||
// or a past day is drawn at its own height. A change of width measures it again at
|
||||
// once, as it is then (the list coming in under it can take a
|
||||
// scrollbar's width off it before the first live request)
|
||||
const STORY_HELD = 3;
|
||||
let storyHold = { key: "", done: new Map() }, storyDrawn = "";
|
||||
let storyHold = { key: "", told: new Map() }, storyDrawn = "";
|
||||
function holdStory() {
|
||||
const follow = !pinned && !rp && !day;
|
||||
const w = steps.clientWidth;
|
||||
const key = JSON.stringify([follow, w, document.documentElement.lang]);
|
||||
if (key === storyHold.key && storyDrawn === headKey + stepsKey) return;
|
||||
if (key !== storyHold.key) storyHold = { key, done: new Map() };
|
||||
if (key !== storyHold.key) storyHold = { key, told: new Map() };
|
||||
storyDrawn = headKey + stepsKey;
|
||||
[logHead, steps].forEach((e) => { e.style.minHeight = ""; });
|
||||
if (!follow || !w || !logR) return;
|
||||
const hs = [logHead, steps].map((e) => e.getBoundingClientRect().height);
|
||||
// an answered request's own height, kept by its id: the last few only
|
||||
if (logR.done) {
|
||||
storyHold.done.set(logR.id, hs);
|
||||
const ids = [...storyHold.done.keys()].sort((x, y) => y - x);
|
||||
for (const id of ids.slice(STORY_HELD)) storyHold.done.delete(id);
|
||||
}
|
||||
// a request's own height as told now, kept by its id: the last few only
|
||||
storyHold.told.set(logR.id, hs);
|
||||
const ids = [...storyHold.told.keys()].sort((x, y) => y - x);
|
||||
for (const id of ids.slice(STORY_HELD)) storyHold.told.delete(id);
|
||||
[logHead, steps].forEach((e, i) => {
|
||||
const held = Math.max(0, ...[...storyHold.done.values()].map((h) => h[i]));
|
||||
const held = Math.max(0, ...[...storyHold.told.values()].map((h) => h[i]));
|
||||
if (held > hs[i]) e.style.minHeight = held + "px";
|
||||
});
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ function serve(lang, feed) {
|
||||
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 r = await new Promise((res) => { feed.next = res; });
|
||||
return trace([r]);
|
||||
return trace([].concat(r));
|
||||
}
|
||||
if (url.pathname === "/api/gateway/history") return json({ cut: false, days: [], routes: [] });
|
||||
if (url.pathname === "/api/groups") return json({ groups: [], models: [], pools: [] });
|
||||
@@ -114,6 +114,53 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
feed.next?.(req(999, 0));
|
||||
await context.close();
|
||||
});
|
||||
|
||||
// A busy gateway (shensmart on Discord, a remote magpie in a local
|
||||
// browser: the room under the story grew and never shrank back):
|
||||
// each request is answered as the next one starts, so the two come
|
||||
// in one trace and the newest is always under way. None of them is
|
||||
// ever drawn answered, yet the long one stops holding the box once
|
||||
// as many requests have been told after it.
|
||||
await t.test(`${lang} ${width}px, the newest always under way`, async () => {
|
||||
const context = await browser.newContext({ viewport: { width, height: 900 }, reducedMotion: "reduce" });
|
||||
const page = await context.newPage();
|
||||
page.setDefaultTimeout(5000);
|
||||
const errors = [];
|
||||
page.on("pageerror", (e) => errors.push(e.message));
|
||||
const feed = { next: null };
|
||||
await page.route("**/*", serve(lang, feed));
|
||||
await page.goto("http://magpie.test/?view=routing");
|
||||
await page.locator(".rt-req").nth(first.length - 1).waitFor();
|
||||
await page.locator(".rt-log .rt-steps li").first().waitFor();
|
||||
await page.waitForTimeout(800);
|
||||
const send = async (r) => {
|
||||
for (let i = 0; i < 60 && !feed.next; i++) await page.waitForTimeout(50);
|
||||
const next = feed.next;
|
||||
assert(next, "the page asks for the next trace");
|
||||
feed.next = null;
|
||||
next(r);
|
||||
await page.waitForTimeout(400);
|
||||
};
|
||||
const story = () => page.evaluate(() => {
|
||||
const s = document.querySelector(".rt-log .rt-steps");
|
||||
const lines = [...s.children].reduce((b, li) => Math.max(b, li.getBoundingClientRect().bottom), s.getBoundingClientRect().top);
|
||||
return { h: s.getBoundingClientRect().height, content: lines - s.getBoundingClientRect().top, held: s.style.minHeight };
|
||||
});
|
||||
|
||||
await send(req(103, 4));
|
||||
const tall = await story();
|
||||
await send([req(104, 0, "start")]);
|
||||
const going = await story();
|
||||
assert(going.h >= tall.h - 0.5, `held while the next is under way: ${going.h} vs ${tall.h}`);
|
||||
for (let id = 105; id <= 110; id++) await send([req(id - 1, 0), req(id, 0, "start")]);
|
||||
const after = await story();
|
||||
assert(after.h < tall.h - 40, `the box shrank back with the newest always under way: ${after.h} vs ${tall.h} (min-height ${after.held || "none"})`);
|
||||
assert(after.h - after.content <= 24, `no empty room under its lines: ${after.h} tall, lines to ${after.content}`);
|
||||
|
||||
assert.deepEqual(errors, []);
|
||||
feed.next?.(req(999, 0));
|
||||
await context.close();
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user