ysm119 on Discord: each Restart of Codex in magpie left the ChatGPT desktop app on "ChatGPT 遇到了问题 / 请重试" till it was quit and opened again. magpie ends the app's own app-server cleanly (code 0); a signed-in ChatGPT 26.1021 then fails "Hosted AppServerManager identity is not ready" on the one it starts, logs fatal_error_broadcasted and shows the page. That is the app's bug; magpie now follows it up. - provider/codex_app_crash.go: for 60s after every end magpie makes (the watcher's step, RestartCodexApp, RestartSwitchedCodexApp) the app's logs are read for a whole fatal_error_broadcasted line stamped after the end. On one, with no request through magpie since or in flight and no Codex turn opened since, the app is quit and opened once. Otherwise it is left as it is and logged. Where it can't be reopened (Linux, an app that didn't quit) the Agents row says "The Codex app hit an error · quit it and open it again" (appSnag) until the app-servers seen then are gone or the app is closed. Unreadable logs reopen nothing. - agent/codex_app_crash.go: the logs as the app's file logger writes them (macOS ~/Library/Logs/com.openai.codex, Windows %LOCALAPPDATA%\Codex\Logs and the Store package's LocalCache, Linux $XDG_STATE_HOME/codex/logs; YYYY/MM/DD folders, tail-read, half lines dropped). The relaunch is the Agents row's: on macOS ChatGPT.app found by its bundle id, quit as ⌘Q does and opened once it has ended, never forced; on Windows codexAppReopen. - GUI line in en, zh, zh-TW, ja, de; docs/subsystems/agent-wiring.md. Run on mote (macOS) at this head on origin/main08982805e: - go vet ./internal/agent ./internal/provider ./internal/gui (darwin and GOOS=windows), GOOS=linux go vet ./internal/agent ./internal/provider; go build ./...; gofmt -l clean. - go test ./internal/provider ok; go test -run 'TestCodexApp|Restart|Reopen' ./internal/agent ok. - go test ./internal/gui: red only in TestMainWindowCorners (#3949) and TestPanelHiddenByWailsMarksPageOutOfSight (#5322), AppKit window tests red on mote's macOS 27 and filed before this change. - win-run and wsl-run: go test -run TestCodexApp ./internal/agent ./internal/provider ok (the macOS relaunch test skips on Windows, as TestWorkBuddySidecarOutlivesQuitOnMac does, #4115). - node --test codex-app-snag, codex-app-out, codex-app-back, i18n-keys, i18n-en-no-cjk: chromium and webkit, every language, 980 and 440px. i18n-keys' "a plugin's words are its own" stays red for "View routing" (#5327/#5332, red on main since73c98ebc2); this change added a word there and took it out again. - Core script budget: under it, not raised. Broken by hand, each red then restored: - codexAppCrashStep's call removed: 4 provider tests red. - the watch not armed in RestartSwitchedCodexApp: TestCodexAppRestartsWatchForTheErrorPage red; in RestartCodexApp: TestCodexAppRowRestartWatchesForTheErrorPage red. - the turn and request checks off: TestCodexAppInUseAfterItsErrorPageIsLeft red. - the snag not set: TestCodexAppSnagSaidTillTheAppRestarts red. - the stamp's >= since check dropped, or a half-written last line kept: TestCodexAppCrashedReadsItsOwnLogs red. - a wrong Store package path: TestCodexAppCrashedReadsEachSystemsFolder red. Not tried: a real signed-in ChatGPT app reaching the identity-not-ready page, and a real quit and reopen of the user's ChatGPT.app (the relaunch is tested with faked process listing, quit and open in a sandbox HOME). The log line and folders are read from ChatGPT 26.1021's file-based-logger and the reporters' logs; a later app that renames them reopens nothing, as before this change.
85 lines
5.0 KiB
JavaScript
85 lines
5.0 KiB
JavaScript
// Run with Node's test runner and Playwright on the module path; see README.md.
|
|
// ysm119 on Discord (#4550): after magpie restarted the Codex app's
|
|
// app-server, a signed-in ChatGPT app showed "ChatGPT hit a snag" till it
|
|
// was quit and opened again. magpie reopens it itself when nothing runs;
|
|
// where it couldn't (Linux, an app that didn't quit), the Agents row says
|
|
// to (appSnag), over what it would say of its provider. Every language,
|
|
// both engines, wide and narrow. No backend, the API is faked.
|
|
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 codex = (appSnag) => ({
|
|
id: "codex", name: "Codex", path: "/fixture/config.toml", wired: true,
|
|
fields: [{ key: "model", label: "model", value: "gpt-6.1-sol", options: [{ value: "gpt-6.1-sol", label: "gpt-6.1-sol", ref: "gpt-6.1-sol" }] }],
|
|
appSnag,
|
|
});
|
|
|
|
const words = {
|
|
en: "The Codex app hit an error · quit it and open it again",
|
|
zh: "Codex 应用出错了 · 请退出后重新打开",
|
|
"zh-TW": "Codex 應用程式出錯了 · 請結束後重新開啟",
|
|
ja: "Codex アプリでエラーが発生しました · 終了してもう一度開いてください",
|
|
de: "Die Codex-App hat einen Fehler · beende sie und öffne sie erneut",
|
|
};
|
|
|
|
function serve(lang, snag) {
|
|
const state = { agents: [codex(snag)], profiles: [], settings: { lang, theme: "light" } };
|
|
return async (route) => {
|
|
const url = new URL(route.request().url());
|
|
if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:false};` });
|
|
if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
|
|
if (url.pathname === "/api/state") return route.fulfill({ json: state });
|
|
if (url.pathname === "/api/plugins") return route.fulfill({ json: { plugins: [] } });
|
|
if (url.pathname === "/api/usage/quotas") return route.fulfill({ json: [] });
|
|
if (url.pathname === "/api/groups") return route.fulfill({ json: { groups: [] } });
|
|
if (url.pathname === "/api/agents/cli") return route.fulfill({ json: { agents: {}, pending: false } });
|
|
if (url.pathname === "/api/providers") return route.fulfill({ json: { providers: [], presets: [], excluded: [], gateway: { running: true, window: true } } });
|
|
if (url.pathname.startsWith("/api/")) return route.fulfill({ 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), contentType });
|
|
};
|
|
}
|
|
|
|
const row = '.row.agent[data-id="codex"]';
|
|
|
|
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
|
for (const lang of Object.keys(words)) {
|
|
for (const width of [980, 440]) {
|
|
test(`${engine} ${lang} ${width}px: the Codex row says to quit and reopen the app after its error page`, async (t) => {
|
|
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
|
t.after(() => browser.close());
|
|
const page = await browser.newPage({ viewport: { width, height: 800 } });
|
|
page.setDefaultTimeout(5000);
|
|
page.setDefaultNavigationTimeout(60000);
|
|
const errors = [];
|
|
page.on("pageerror", (e) => errors.push(e.message));
|
|
await page.route("**/*", serve(lang, true));
|
|
await page.goto("http://magpie.test/?view=agents");
|
|
const st = page.locator(`${row} .ag-st-t`);
|
|
await st.waitFor();
|
|
assert.equal((await st.textContent()).trim(), words[lang]);
|
|
assert.ok(await page.locator(`${row} .ag-st.wait, ${row} .wait .ag-st-t, ${row} .wait`).count() > 0, "said as a wait");
|
|
const box = await st.boundingBox();
|
|
assert.ok(box && box.x >= 0 && box.x + box.width <= width + 0.5, "the line is on the page: " + JSON.stringify(box));
|
|
const side = await page.evaluate(() => document.documentElement.scrollWidth - document.documentElement.clientWidth);
|
|
assert.ok(side <= 1, "scrolls sideways: " + side);
|
|
assert.deepEqual(errors, []);
|
|
});
|
|
}
|
|
}
|
|
test(`${engine}: without appSnag the row says nothing of it`, async (t) => {
|
|
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
|
t.after(() => browser.close());
|
|
const page = await browser.newPage({ viewport: { width: 980, height: 800 } });
|
|
await page.route("**/*", serve("en", undefined));
|
|
await page.goto("http://magpie.test/?view=agents");
|
|
await page.locator(`${row} .ag-st-t`).waitFor();
|
|
assert.doesNotMatch(await page.locator(`${row} .ag-st-t`).textContent(), /hit an error/);
|
|
});
|
|
}
|