The owner (11-12): an agent's sheet showed Long conversations twice, every
agent's row above the agent's own, which read as the same setting twice.
Now the sheet shows one row, the agent's own (.own-compact hides
#fullContextRow there). It shows the agent's own value, else every agent's,
and a change posts settings/agent-compact {agent, own: true, full, at}, so
it is that agent's alone. Settings keeps every agent's row for when no agent
holds one. The Context card's note says "Long conversations in {agent}" when
the agent holds its own value (context.js), in en/zh/zh-TW/ja/de.
The agent's context window (agentwindow.js) is picked, never typed as a
syntax: one size for all its models from the app's menu (Each model's own,
128K to 1M, Other size… typed as 300k), and "Set a model apart" adds a
model from the agent's model picker with its own size, a line each, with a
remove button.
Tests rewritten to the one row, keeping what each guarded:
- compact-one-value: Tuned for you and Long conversations are one window,
now through the agent's own value and its post.
- codex-compact-held: Codex's held values are under the agent's row.
- agent-prefs: what an agent's opened row and its panel sheet show
(#fullContextRow hidden, .row.agent-compact visible).
- compact-at: a typed size posts settings/agent-compact for Claude Code,
and never settings/full-context.
- codex-memories-settings "no Codex, no memories row": waits on the
merged row, lists the visible rows in its message.
- agent-compact, agent-window: the new row and the picker.
Run on mote (macOS, Playwright 1.62.0, chromium + webkit, every language
each file covers, narrow and wide), at f9bc297a5 + this change; origin/main
then rebased (main has since changed app.css and app.js; see below):
- go test -run 'TestCoreScriptBudget|TestAssetBudget' ./internal/gui: ok
- agent-window 20/20, agent-compact 8/8, compact-one-value 12/12,
codex-compact-held 20/20, agent-prefs 56/56, claude-cache 8/8,
context-tune 284/284, compact-at 8/8, settings-general 20/20,
i18n-keys 4/4, i18n-en-no-cjk 4/4
- codex-memories-settings 8 pass / 10 fail; after the no-Codex fix that
subtest passes 2/2. The other 8 (chromium "picking a model scrolled the
page 944 !== 1056") fail the same on origin/main dbaf9d68c: #6372.
- agent-details-ready 4 pass / 32 fail, the same on origin/main dbaf9d68c
("Details must end without a height jump: 772.98 -> 852.92"): #6373
(#6369 is the late-settings subtest).
Again at this commit on be8e352a2: the budgets ok, agent-window 20/20,
agent-compact 8/8, compact-one-value 12/12, codex-compact-held 20/20,
agent-prefs 56/56, compact-at 8/8, i18n-keys 4/4.
Broken by hand, each red, then put back:
- .own-compact > #fullContextRow removed and the card note back to the
shared words: compact-one-value 12/12 red, agent-prefs red (en/zh, 1100
and 440, panel). codex-compact-held stayed green; it checks the held
values sit in the agent's row, which still holds them.
- own: true dropped from the agent-compact post: compact-at 4/8 red,
agent-compact red, compact-one-value red.
- "Set a model apart" not drawn: agent-window red.
Not tried: the real app, and a real Codex or Claude Code session reading
the agent's own compaction size.
128 lines
8.0 KiB
JavaScript
128 lines
8.0 KiB
JavaScript
// Run with Node's test runner and Playwright on the module path; see README.md.
|
|
// An agent's Long conversations, one row in its sheet (molianyin4227 on
|
|
// Discord: models differ, so one size for every agent fits none; the owner,
|
|
// 11-12: two rows for the same thing read as a duplicate). Claude Code's
|
|
// and Codex's sheets show one "Long conversations" row, in place of every
|
|
// agent's, with this agent's value (its own, else every agent's): Compact
|
|
// at a size or Full window, each posting settings/agent-compact for that
|
|
// agent alone. Every agent's row is not shown in the sheet. Its label
|
|
// follows every agent's size until the agent has its own, no click or
|
|
// typing scrolls the page, there is no native select.
|
|
// English and Chinese, Chromium and WebKit, wide and narrow; no backend,
|
|
// the API is faked here.
|
|
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 { watchSettingsReads, agentRow, openAgentSettings } = require("./reader.cjs");
|
|
|
|
const assets = path.resolve(__dirname, "../assets");
|
|
|
|
function serve(lang, posts) {
|
|
let settings = { theme: "light", lang, tray: "panel", currency: "usd", version: "0.1.900", dir: "~/.config/magpie", gateway: "http://127.0.0.1:3425", proxyNow: "none", proxySource: "none", visionModels: [], imageGenModels: [], titleModels: [], workbuddyCheckins: [], lanURLs: [], redactWords: [], trayUsageEvery: 3, compactAt: 400000 };
|
|
return async (route) => {
|
|
const req = route.request(), url = new URL(req.url());
|
|
const json = (data) => route.fulfill({ json: data });
|
|
if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:${JSON.stringify(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({ agents: [agentRow("claude", "Claude Code"), agentRow("codex", "Codex")], profiles: [], settings: { lang, theme: "light" } });
|
|
if (url.pathname === "/api/providers") return json({ providers: [], presets: [], excluded: [], gateway: { running: true, window: true } });
|
|
if (url.pathname === "/api/groups") return json({ groups: [], models: [] });
|
|
if (url.pathname === "/api/settings/agent-compact") {
|
|
const body = req.postDataJSON();
|
|
posts.push({ path: url.pathname, body });
|
|
const own = { ...(settings.agentCompacts || {}) };
|
|
if (body.own) own[body.agent] = { ...(body.at && body.at !== 272000 ? { at: body.at } : {}), ...(body.full ? { full: true } : {}) };
|
|
else delete own[body.agent];
|
|
settings = { ...settings, agentCompacts: own };
|
|
return json(settings);
|
|
}
|
|
if (url.pathname === "/api/settings/full-context") {
|
|
const body = req.postDataJSON();
|
|
posts.push({ path: url.pathname, body });
|
|
settings = { ...settings, fullContext: body.on, ...(body.at !== undefined ? { compactAt: body.at === 272000 ? 0 : body.at } : {}) };
|
|
return json(settings);
|
|
}
|
|
if (url.pathname === "/api/settings") {
|
|
if (req.method() === "POST") posts.push({ path: url.pathname, body: req.postDataJSON() });
|
|
return json(settings);
|
|
}
|
|
if (url.pathname === "/api/plugins") return json({ plugins: [] });
|
|
if (url.pathname === "/api/usage/quotas") return json([]);
|
|
if (url.pathname.startsWith("/api/")) return json({});
|
|
const file = path.join(assets, url.pathname === "/" ? "index.html" : url.pathname);
|
|
try {
|
|
await route.fulfill({ body: await fs.readFile(file), contentType: { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".png": "image/png" }[path.extname(file)] });
|
|
} catch {
|
|
await route.fulfill({ status: 404, body: "" });
|
|
}
|
|
};
|
|
}
|
|
|
|
const words = {
|
|
en: { name: "Long conversations", at: (n) => `Compact at ${n}`, full: "Full window", bad: "Compact at: lots is not a number of tokens like 272k" },
|
|
zh: { name: "长对话", at: (n) => `${n} 时压缩`, full: "完整窗口", bad: "压缩阈值:lots 不是 272k 这样的 token 数" },
|
|
};
|
|
|
|
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
|
for (const lang of ["en", "zh"]) {
|
|
for (const width of [900, 420]) {
|
|
const w = words[lang];
|
|
test(`${engine} ${lang} ${width}px: an agent sets its own Long conversations`, async (t) => {
|
|
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: process.env.PLAYWRIGHT_CHANNEL || "chromium" }));
|
|
t.after(() => browser.close());
|
|
const page = await (await browser.newContext({ viewport: { width, height: 760 }, reducedMotion: "reduce" })).newPage();
|
|
page.setDefaultTimeout(5000);
|
|
page.setDefaultNavigationTimeout(60000);
|
|
const errors = [], posts = [];
|
|
page.on("pageerror", (e) => errors.push(e.message));
|
|
await page.route("**/*", serve(lang, posts));
|
|
await watchSettingsReads(page);
|
|
await page.goto("http://magpie.test/?view=agents");
|
|
await openAgentSettings(page, "claude");
|
|
const row = page.locator('.agent-compact[data-agent="claude"]');
|
|
await row.waitFor();
|
|
assert.equal(await row.locator(".name").textContent(), w.name);
|
|
assert.equal(await row.locator("select").count(), 0, "no native select");
|
|
// in every agent's place: that row is not shown in the sheet, so the
|
|
// setting reads once
|
|
assert.equal(await row.evaluate((r) => r.previousElementSibling?.id), "fullContextRow");
|
|
assert(await page.locator(".agent-compact ~ #fullContextRow, #fullContextRow").first().isHidden(), "every agent's row shows beside it");
|
|
assert.equal(await page.getByText(w.name, { exact: true }).filter({ visible: true }).count(), 1, "Long conversations shown twice");
|
|
const seg = (label) => row.getByText(label, { exact: true });
|
|
const on = (label) => seg(label).evaluate((b) => b.classList.contains("on") || b.getAttribute("aria-pressed") === "true" || b.getAttribute("aria-checked") === "true");
|
|
// every agent's value until it has its own
|
|
assert(await on(w.at("400K")), "every agent's size is shown");
|
|
const num = row.locator("input.compact-num");
|
|
assert.equal(await num.inputValue(), "400k");
|
|
const view = () => page.locator("#view-agents").evaluate((v) => v.scrollTop);
|
|
const before = await view();
|
|
await seg(w.full).click();
|
|
await page.waitForFunction(() => document.querySelector(".agent-compact input.compact-num")?.hidden);
|
|
assert.deepEqual(posts.map((p) => [p.path, p.body]), [["/api/settings/agent-compact", { agent: "claude", own: true, full: true, at: 400000 }]]);
|
|
await seg(w.at("400K")).click();
|
|
await page.waitForFunction(() => document.querySelector(".agent-compact input.compact-num")?.hidden === false);
|
|
assert.deepEqual(posts.at(-1).body, { agent: "claude", own: true, full: false, at: 400000 });
|
|
await num.fill("150k");
|
|
await num.press("Enter");
|
|
await seg(w.at("150K")).waitFor();
|
|
assert.deepEqual(posts.at(-1).body, { agent: "claude", own: true, full: false, at: 150000 });
|
|
assert(!posts.some((p) => p.path === "/api/settings/full-context"), "every agent's Long conversations was not sent");
|
|
assert(!posts.some((p) => p.path === "/api/settings"), "set on its own, not with the other preferences");
|
|
assert.equal(await view(), before, "the row scrolled the page");
|
|
// a size that isn't one is refused, nothing sent
|
|
const sent = posts.length;
|
|
await num.fill("lots");
|
|
await num.press("Enter");
|
|
await page.getByText(w.bad).waitFor();
|
|
assert.equal(posts.length, sent, "a bad size sent nothing");
|
|
// it fits a narrow window
|
|
const over = await row.evaluate((r) => r.scrollWidth - r.clientWidth);
|
|
assert(over <= 1, `the row overflows by ${over}px`);
|
|
assert.deepEqual(errors, []);
|
|
});
|
|
}
|
|
}
|
|
}
|