Herzz____ on X, the Windows Codex app: with Codex through magpie the sidebar's project list is empty; they use magpie only when their subscription runs out, and want to switch between magpie and the native sign-in with the projects whole each way. What happens. When the ChatGPT account is used up, magpie becomes Codex's provider (codex.out) without requires_openai_auth: on that account the app's composer gate greys Send for every model, magpie's too (#540). Checked again in ChatGPT.app 26.1029's bundle: the gate picks the account's own snapshot (limitName null) whenever it is blocked, before any per-model additional_rate_limits, so keeping the account during the takeover would still grey Send. The app-server then answers account/read with no account and the app hides its ChatGPT projects and chats (72ca3d593). magpie never touches projects, project_roots or a thread's cwd: its thread moves only rewrite threads.model_provider (sessions/codex_provider.go), so path case or backslashes on Windows play no part. What was wrong. Turning the takeover off by hand (the takeover note's Keep on ChatGPT, the sign-in's Always ChatGPT, or Disconnect) looked the same to codexAppStep as the reset, magpie's own end of it: with Restart the Codex app to follow off (the default) the app's app-server was left running on no account, so the projects stayed gone after the user switched back to have them, until they restarted the app (the Windows app has no Restart of its own). Now Agent.AppOutOff (Always ChatGPT, or Codex not routed through magpie) reaches the step through provider.CodexTakeoverOff, asked only as out goes false, and a takeover ended so counts as the user's change: the app-server is restarted once no Codex turn runs, as for a Connect, and the Windows app reopened if none comes back (existing path). The reset itself still leaves the app running and says so (CodexAppBack); that note now names the ChatGPT projects and chats it lacks (en, zh, zh-TW, ja, de). agent-wiring.md says the same. Switching back to native is already in magpie: Agents > Codex > sign-in > Always ChatGPT (`magpie codex login chatgpt`), or Keep on ChatGPT on the takeover note; ChatGPT (the default) lets magpie take over again. Tests: TestCodexAppRestartedWhenTheTakeoverIsTurnedOff (turned off with a request in flight: held, then restarted; CodexAppBack not said; the hook asked once; the reset still left running and said); TestCodexOwnModelOutThenKeptOnChatGPT and TestCodexOwnModelGoesThroughMagpieWhileUsedUp assert AppOutOff for Keep on ChatGPT, Disconnect and the reset; codex-app-back.test.cjs checks the note names the projects in every language. Broken by hand: offByHand out of byHand, the provider test red (ended [], want [100]); the login half of AppOutOff false, the Keep on ChatGPT test red; the routed half false, the Disconnect check red. Run (mote-run at b87783fbb (this change's tree) on origin/main547585cd9): gofmt -l clean; go build ./...; go vet linux -tags nogui ./... and windows ./..., darwin ./internal/agent ./internal/provider ./internal/gui; go test -tags nogui ./internal/provider ./internal/agent ok; GUI codex-app-back, codex-app-out, i18n-keys, i18n-en-no-cjk, gui-ja, Chromium and WebKit, every language, 155 of 155 pass. Windows (win-run on xiaomi-gpu): the provider and agent Codex app tests ok; the box's running Windows Codex app (26.1029) app-server command line has the shape TestCodexAppOwnServer already holds. Not run: a real used-up ChatGPT account (none at hand), so the restart after Keep on ChatGPT is tried with the stubbed step, not the real app; the full go test ./... waits behind mote's suite lock and runs after the push, any red filed.
138 lines
8.1 KiB
JavaScript
138 lines
8.1 KiB
JavaScript
// Run with Node's test runner and Playwright on the module path; see README.md.
|
|
// A bug report by mail (11-04): after its ChatGPT allowance reset, Codex
|
|
// was back on its account, but the Codex app still showed no account and
|
|
// no usage. Its app-server was the one started while magpie served Codex,
|
|
// and it reads the account only as it starts; with "restart the Codex app
|
|
// when magpie switches its account back" off, nothing restarted it, and
|
|
// nothing said so. The Agents row now says it (appBack), on hover and in
|
|
// the row opened, with a Restart that posts codex/daemon/restart-app.
|
|
// 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 = (appBack) => ({
|
|
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" }] }],
|
|
appBack,
|
|
});
|
|
|
|
const words = {
|
|
en: { line: "Back on ChatGPT", why: "no usage", proj: "projects", restart: "Restart", done: "Codex app-server restarted" },
|
|
zh: { line: "已回到 ChatGPT", why: "用量", proj: "项目", restart: "重启", done: "Codex 的 app-server 已重启" },
|
|
"zh-TW": { line: "已回到 ChatGPT", why: "用量", proj: "專案", restart: "重啟", done: "Codex 的 app-server 已重新啟動" },
|
|
ja: { line: "ChatGPT に戻りました", why: "使用量", proj: "プロジェクト", restart: "再起動", done: "Codex の app-server を再起動しました" },
|
|
de: { line: "Wieder bei ChatGPT", why: "keine Nutzung", proj: "Projekte", restart: "Neu starten", done: "App-Server von Codex neu gestartet" },
|
|
};
|
|
|
|
function serve(lang, posts) {
|
|
let back = true;
|
|
const state = () => ({ agents: [codex(back || undefined)], profiles: [], settings: { lang, theme: "light" } });
|
|
const providers = { providers: [], presets: [], excluded: [], gateway: { running: true, window: true } };
|
|
return async (route) => {
|
|
const url = new URL(route.request().url());
|
|
if (url.pathname === "/api/codex/daemon/restart-app") {
|
|
posts.push(route.request().method());
|
|
back = false;
|
|
return route.fulfill({ json: providers });
|
|
}
|
|
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 });
|
|
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)) {
|
|
const w = words[lang];
|
|
for (const width of [980, 440]) {
|
|
test(`${engine} ${lang} ${width}px: back on ChatGPT, the Codex row says to restart the app and does it`, async (t) => {
|
|
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
|
t.after(() => browser.close());
|
|
for (const where of ["line", "opened"]) {
|
|
await t.test(where, async () => {
|
|
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));
|
|
const posts = [];
|
|
await page.route("**/*", serve(lang, posts));
|
|
await page.goto("http://magpie.test/?view=agents");
|
|
const st = page.locator(`${row} .ag-st-t`);
|
|
await st.waitFor();
|
|
const text = await st.textContent();
|
|
assert.ok(text.includes(w.line), `${JSON.stringify(text)} lacks ${JSON.stringify(w.line)}`);
|
|
assert.doesNotMatch(text, /\{\w+\}/);
|
|
const title = await st.getAttribute("title");
|
|
assert.ok(title && title.includes(w.why), "the hover says why: " + title);
|
|
assert.doesNotMatch(title, /\{\w+\}/);
|
|
let go;
|
|
if (where === "line") {
|
|
go = page.locator(`${row} .ag-st button`, { hasText: w.restart });
|
|
} else {
|
|
await page.locator(`${row} .ag-link`).click();
|
|
const said = page.locator(`${row} .ag-app-back`);
|
|
await said.waitFor();
|
|
const s = await said.textContent();
|
|
assert.ok(s.includes(w.why), "the row opened says why: " + s);
|
|
// what the reporter missed: the app's ChatGPT projects (Herzz____ on X)
|
|
assert.ok(s.includes(w.proj), "the row opened names the projects: " + s);
|
|
assert.doesNotMatch(s, /\{\w+\}/);
|
|
go = page.locator(`${row} .ag-app-back + .ag-vl button`);
|
|
await page.waitForFunction(() => {
|
|
const b = document.querySelector('.row.agent[data-id="codex"] .ag-app-back + .ag-vl button'), r = b.getBoundingClientRect();
|
|
return document.elementFromPoint(r.x + r.width / 2, r.y + r.height / 2) === b;
|
|
});
|
|
}
|
|
assert.equal((await go.textContent()).trim(), w.restart);
|
|
const box = await go.boundingBox(), vw = page.viewportSize().width;
|
|
assert.ok(box && box.x >= 0 && box.x + box.width <= vw + 0.5, "Restart 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);
|
|
await go.click();
|
|
await page.locator("dialog.action-confirm .primary").click();
|
|
await page.waitForFunction(() => !document.querySelector('.row.agent[data-id="codex"] .ag-app-back'));
|
|
await page.waitForFunction((l) => !document.querySelector('.row.agent[data-id="codex"] .ag-st-t')?.textContent.includes(l), w.line);
|
|
assert.deepEqual(posts, ["POST"]);
|
|
assert.deepEqual(errors, []);
|
|
await page.close();
|
|
});
|
|
}
|
|
});
|
|
}
|
|
}
|
|
test(`${engine}: without appBack 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 } });
|
|
const posts = [];
|
|
const handler = serve("en", posts);
|
|
await page.route("**/*", async (route) => {
|
|
if (new URL(route.request().url()).pathname === "/api/state") return route.fulfill({ json: { agents: [codex(undefined)], profiles: [], settings: { lang: "en", theme: "light" } } });
|
|
return handler(route);
|
|
});
|
|
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(), /Back on ChatGPT/);
|
|
await page.locator(`${row} .ag-link`).click();
|
|
await page.locator(`${row} .ag-exp`).waitFor();
|
|
assert.equal(await page.locator(`${row} .ag-app-back`).count(), 0);
|
|
});
|
|
}
|