多喝热水 (Discord #help, Windows, v0.1.1384, Codex desktop with ChatGPT
sign-in): Codex wouldn't open, "config.toml:154:1: invalid type: map,
expected a boolean". That line is the [features.async_compaction] table
1978eabe5 (#2490/#2493) writes.
Codex versions, from codex-rs source and the real binaries:
- up to 0.163.0-alpha.5 (0.160.0, 0.162.1 included) FeaturesToml is a
flattened BTreeMap<String, bool>: any table under [features] fails the
whole config; an unknown bool key is only a warning.
- from 0.163.0-alpha.8, async_compaction is FeatureToml<…>, bool or
table, and model_async_compact_threshold_percent is read only from the
table (the bool gives Codex's default 65).
- the provider table's capabilities = {...} is safe: 0.161 and older
ignore unknown provider keys (schemars-only deny_unknown_fields),
0.162 parses it. 0.160.0 and 0.162.1 load a config holding it.
- ChatGPT.app 26.1013.40934 bundles Codex 0.163.0-alpha.10.2
(Contents/Resources/codex-cli/codex-package.json); the reporter's
Windows app rejects the table, so it bundles one before alpha.8.
Fix: the table is written only when every Codex found here that reads
this config (the CLI on PATH, the desktop app's bundled codex on macOS,
the Store app on Windows, the editor extension, Codex in WSL) has a
version at or after 0.163.0-alpha.8. Otherwise, or when a version can't
be read (the Windows app, the extension), magpie writes the bare
[features] async_compaction = true with no share. A table magpie wrote
before is taken back through its stash (only the keys the stash names
as magpie's; an emptied table goes), so a config already broken opens
again on the next sync. A table or bool the user wrote stays. The stash
records a bool it wrote (`bool`), and the table comes back once every
reader is new enough. Settings' state carries codexAsyncHeld, and the
Codex row says which Codex holds the share back and that it needs
0.163. The note costs app.js 390 bytes; its budget and the core's are
raised by exactly that, the agent's own row in the core.
Run:
- real binaries, sandbox CODEX_HOME/HOME, `codex features list` on the
config magpie writes (TestCodexAsyncConfigLoadsInRealCodex,
MAGPIE_TEST_CODEX_BINS): 0.162.1, 0.163.0-alpha.8 and 0.164.0 load it;
alpha.8 and 0.164.0 report async_compaction true. By hand before the
fix: 0.160.0 and 0.162.1 exit 1 on the table ("invalid type: map,
expected a boolean"), load the bool and nothing; alpha.8 and 0.164.0
load all three.
- broken by hand (table always allowed): the real-binary test is red
for 0.162.1 with Codex's own error, OldCodexGetsTheBareKey red in all
four cases, TableTakenBackForOldCodex red ("magpie's table not
mended"). Green again with the fix.
- go test -tags nogui ./internal/agent ./internal/gui ./internal/edit
./internal/settings: ok (gui after the budget, re-run alone: ok).
- GUI (node --test, chromium + webkit): codex-async-compact,
agent-prefs, settings-general, segs-glide, i18n-keys: 100 pass, 0 fail.
- gofmt -l clean; go vet ./..., GOOS=linux go vet -tags nogui ./...,
GOOS=windows go vet ./...; go build for darwin, linux (nogui),
windows: ok.
Not tried: the Windows box (Store-app detection, reading its bundled
codex's version, a non-Store install), a WSL distro, a real Codex run
past the share, the whole GUI suite. The full go test ./... is queued
behind other sessions' suites (one per machine) and wasn't waited for.
139 lines
10 KiB
JavaScript
139 lines
10 KiB
JavaScript
// Run with Node's test runner and Playwright on the module path; see README.md.
|
|
// Codex's settings, on its opened row: background compaction (#2490): Off /
|
|
// On, and with it on the share of the window Codex starts at, typed as a
|
|
// percent (empty: Codex's own 65%). Each posts settings/codex-async-compact
|
|
// on its own, a value that isn't 0 to 100 is refused before anything is
|
|
// sent, and nothing scrolls the page. Every language, Chromium and WebKit;
|
|
// 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, extra = {}) {
|
|
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, ...extra };
|
|
const models = ["deepseek-v4-flash", "deepseek-v4-pro"].map((id) => ({ id, name: id, on: true, context: 1000000 }));
|
|
const provider = { id: "deepseek", name: "DeepSeek", icon: "generic", chat: "https://api.deepseek.example/v1", responses: "", anthropic: "", models, agents: [], key: { set: true, masked: "sk-…1234" }, ready: true, compacts: { "*": 500000, "deepseek-v4-flash": 272000 } };
|
|
const providers = { providers: [provider], presets: [], excluded: [], gateway: { running: true, window: true } };
|
|
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("codex", "Codex")], profiles: [], settings: { lang, theme: "light" } });
|
|
if (url.pathname === "/api/providers") return json(providers);
|
|
if (url.pathname === "/api/groups") return json({ groups: [], models: [] });
|
|
if (url.pathname.startsWith("/api/provider/")) {
|
|
posts.push({ path: url.pathname, body: req.postDataJSON() });
|
|
return json(providers);
|
|
}
|
|
if (url.pathname === "/api/settings/codex-async-compact") {
|
|
const body = req.postDataJSON();
|
|
posts.push({ path: url.pathname, body });
|
|
settings = { ...settings, codexAsyncCompact: body.on, ...(body.percent !== undefined ? { codexAsyncCompactPercent: body.percent } : {}) };
|
|
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: "Codex background compaction", field: "Background compaction at", bad: "Background compaction at: 150 is not a percent from 1 to 100", off: "Off", on: "On" },
|
|
zh: { name: "Codex 后台压缩", field: "后台压缩阈值", bad: "后台压缩阈值:150 不是 1 到 100 的百分比", off: "关闭", on: "开启" },
|
|
"zh-TW": { name: "Codex 背景壓縮", field: "背景壓縮閾值", bad: "背景壓縮閾值:150 不是 1 到 100 的百分比", off: "關閉", on: "開啟" },
|
|
ja: { name: "Codex のバックグラウンド圧縮", field: "バックグラウンド圧縮のしきい値", bad: "バックグラウンド圧縮のしきい値:150 は 1〜100 のパーセントではありません", off: "オフ", on: "オン" },
|
|
de: { name: "Codex-Hintergrundkomprimierung", field: "Hintergrundkomprimierung ab", bad: "Hintergrundkomprimierung ab: 150 ist kein Prozentwert von 1 bis 100", off: "Aus", on: "An" },
|
|
};
|
|
|
|
// what the row says when a Codex here kept the table out (codexAsyncHeld):
|
|
// one too old for the feature beside the app of no known version, or the app alone
|
|
const held = {
|
|
en: { old: "Codex CLI 0.162.1, Codex app: the share needs Codex 0.163 or later; until it's updated magpie writes only async_compaction = true, at 65%", unknown: "Codex app: the share needs Codex 0.163 or later; until it's updated magpie writes only async_compaction = true, at 65%" },
|
|
zh: { old: "Codex CLI 0.162.1, Codex 应用:阈值需要 Codex 0.163 或更新;更新之前 magpie 只写 async_compaction = true,按 65%", unknown: "Codex 应用:阈值需要 Codex 0.163 或更新;更新之前 magpie 只写 async_compaction = true,按 65%" },
|
|
"zh-TW": { old: "Codex CLI 0.162.1, Codex 應用程式:閾值需要 Codex 0.163 或更新;更新之前 magpie 只寫 async_compaction = true,按 65%", unknown: "Codex 應用程式:閾值需要 Codex 0.163 或更新;更新之前 magpie 只寫 async_compaction = true,按 65%" },
|
|
ja: { old: "Codex CLI 0.162.1, Codex アプリ:しきい値には Codex 0.163 以降が必要です。更新するまで magpie は async_compaction = true だけを書き、65% で圧縮します", unknown: "Codex アプリ:しきい値には Codex 0.163 以降が必要です。更新するまで magpie は async_compaction = true だけを書き、65% で圧縮します" },
|
|
de: { old: "Codex CLI 0.162.1, Codex-App: Die Schwelle braucht Codex 0.163 oder neuer; bis zum Update schreibt magpie nur async_compaction = true, bei 65 %", unknown: "Codex-App: Die Schwelle braucht Codex 0.163 oder neuer; bis zum Update schreibt magpie nur async_compaction = true, bei 65 %" },
|
|
};
|
|
|
|
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
|
for (const lang of Object.keys(words)) {
|
|
const w = words[lang];
|
|
test(`${engine} ${lang}: Codex background compaction is turned on with a threshold`, 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: 900, height: 720 }, reducedMotion: "reduce" })).newPage();
|
|
page.setDefaultTimeout(5000);
|
|
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);
|
|
const row = page.locator("#codexAsyncRow");
|
|
await row.getByText(w.name, { exact: true }).waitFor();
|
|
assert.equal(await row.locator("select").count(), 0, "no native select");
|
|
const num = row.locator("input.compact-num");
|
|
assert(await num.isHidden(), "no threshold while off");
|
|
const view = () => page.locator("#view-agents").evaluate((v) => v.scrollTop);
|
|
const before = await view();
|
|
await row.getByText(w.on, { exact: true }).click();
|
|
await page.waitForFunction(() => document.querySelector("#codexAsyncRow input.compact-num")?.hidden === false);
|
|
assert.deepEqual(posts.map((p) => [p.path, p.body]), [["/api/settings/codex-async-compact", { on: true }]]);
|
|
assert.equal(await num.getAttribute("aria-label"), w.field);
|
|
assert.equal(await num.getAttribute("placeholder"), "65%");
|
|
await num.fill("150");
|
|
await num.press("Enter");
|
|
await page.getByText(w.bad).waitFor();
|
|
assert.equal(posts.length, 1, "a bad percent is not sent");
|
|
await num.fill("70%");
|
|
await num.press("Enter");
|
|
await page.waitForFunction(() => document.querySelector("#codexAsyncRow input.compact-num")?.value === "70%");
|
|
assert.deepEqual(posts.at(-1), { path: "/api/settings/codex-async-compact", body: { on: true, percent: 70 } });
|
|
await row.getByText(w.off, { exact: true }).click();
|
|
await page.waitForFunction(() => document.querySelector("#codexAsyncRow input.compact-num")?.hidden);
|
|
assert.deepEqual(posts.at(-1).body, { on: false });
|
|
assert.equal(await view(), before, "the row scrolled the page");
|
|
assert(!posts.some((p) => p.path === "/api/settings"), "set on its own, not with the other preferences");
|
|
assert.deepEqual(errors, []);
|
|
});
|
|
}
|
|
for (const lang of Object.keys(held)) {
|
|
test(`${engine} ${lang}: the row says when a Codex here kept the share out`, async (t) => {
|
|
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: process.env.PLAYWRIGHT_CHANNEL || "chromium" }));
|
|
t.after(() => browser.close());
|
|
for (const [kind, readers] of [["old", [{ kind: "cli", version: "0.162.1" }, { kind: "app" }]], ["unknown", [{ kind: "app" }]]]) {
|
|
const page = await (await browser.newContext({ viewport: { width: 900, height: 720 }, reducedMotion: "reduce" })).newPage();
|
|
page.setDefaultTimeout(5000);
|
|
const errors = [], posts = [];
|
|
page.on("pageerror", (e) => errors.push(e.message));
|
|
await page.route("**/*", serve(lang, posts, { codexAsyncCompact: true, codexAsyncHeld: readers }));
|
|
await watchSettingsReads(page);
|
|
await page.goto("http://magpie.test/?view=agents");
|
|
await openAgentSettings(page);
|
|
const note = page.locator("#codexAsyncRow .codex-async-held");
|
|
await note.waitFor();
|
|
assert.equal((await note.textContent()).trim(), held[lang][kind]);
|
|
assert.equal(await page.locator("#codexAsyncRow input.compact-num").isVisible(), true);
|
|
assert.deepEqual(errors, []);
|
|
await page.close();
|
|
}
|
|
});
|
|
}
|
|
}
|