1EFLOPS runs Claude Code through magpie on Codex's gpt-6.1-sol. In auto mode, Claude Code 2.1.296 says "this session isn't eligible because your requests go through 127.0.0.1:3425 ... ask your gateway to implement https://code.claude.com/docs/en/auto-mode-classifier-billing". What the page asks of a gateway: pass the anthropic-beta header (dangerous-tool-use-2026-09-03), the request's `safeguards` field, and `safeguard_results` in the reply through unchanged, and leave tool-use ids alone. The results are verdicts from Anthropic's own safety classifier. For a gateway that can't provide them, the page's remedy is CLAUDE_CODE_AUTO_MODE_SERVER=0. Pro, Max and Team plans never see the notice. In the bundle, Claude Code falls back on server_unsupported, server_unavailable_disabled or server_no_result, and the notice shows whenever there's no real verdict. Only that variable removes it. Per route: - Claude subscription bridge, Anthropic API key, relays in front of Anthropic, Bedrock and Vertex: already pass the beta, `safeguards` and `safeguard_results` through (e8cd4bac8,8c21a4184). This commit doesn't change them. serverReview now uses the shared AutoModeReviewed rule (adding the subscription account, which never reaches serverReview). - Codex/OpenAI and every other non-Claude model: magpie can't answer honestly. A verdict would be made up, and "unsupported" still shows the notice. So magpie answers nothing on Anthropic's behalf. Instead the Claude Code wiring writes env.CLAUDE_CODE_AUTO_MODE_SERVER="0" to settings.json. It does this only while Claude Code is routed through magpie and no model it can reach there is reviewed. That means checking the models shown to Claude Code (and Claude Desktop's while Desktop is on magpie), a shown group's members, those providers' fallbacks, and the models it is set to (claudeReviewed). If any one is reviewed, the variable stays unset, because /model can move the session onto it (the reason8c21a4184didn't write it at all). The value is rewritten on every model set and Sync, so adding a Claude provider turns the review back on. It is stash-tracked (claude.auto_mode_server): a user's own value is left alone, and magpie's goes on Disconnect, reset or a move off magpie. - T3 Code (sibling): its magpie instance runs Claude Code on the gateway through its own environment, so it gets the same "0" by the models it lists. Not covered: Claude Desktop's Code tab while Claude Code itself isn't routed through magpie. Desktop users are on Pro/Max/Team, which never see the notice. Tests (each fails with its part of the change broken by hand): - TestClaudeAutoModeReview: off on a non-Claude model; on with a Claude model shown, in a group or as a fallback; the user's "1" and "0" kept; dropped on reset and on a move to Claude Code's own model. A group that keeps its models out of the lists (#1783, Unlists) still routes to them, so its Claude member counts: members come from what is served, not from the catalog. - TestT3CodeAutoModeReview. - TestAutoModeReviewedRoutes: subscription, api.anthropic.com, relay, Bedrock and Vertex spellings yes; Codex, DeepSeek's Anthropic API, openai/gpt-6 and claudette no. Mutations that went red: skipping group members, skipping fallbacks, skipping an unlisting group, overwriting the user's value, not dropping it off magpie, always writing it, the T3 env always or never, and the subscription not counted. Real Claude Code 2.1.296, sandbox HOME/CLAUDE_CONFIG_DIR, magpie serve on 127.0.0.1:3591 under a scratch HOME, fake upstreams on 3593 (OpenAI Chat) and 3594 (Anthropic): - Before, on fakeai/fake-gpt, -p --permission-mode auto: the notice is on stderr (2 of 2 fresh config dirs). With the env in settings: none. - With this build, `magpie claude fakeai/fake-gpt` wrote the "0", and a fresh run shows no notice. The same settings without it show the notice. - `magpie provider add fakeanth anthropic=... models=claude-sonnet-5`: Sync took the "0" out. `magpie claude fakeanth/claude-sonnet-5` and a run in auto mode: the upstream got the dangerous-tool-use beta and `safeguards` on both turns, answered not_flagged in message_delta, and there was no notice. Not tried: the Claude subscription bridge with a real account (its plans don't see the notice), and a real Codex account (a fake Chat upstream stood in for it). Run: gofmt -l; go vet -tags nogui ./... for darwin, linux and windows; go test -tags nogui ./... in a scratch HOME with the Go caches pinned. The only red was TestOTelWaterfallIncludesUnbilledFallback, whose first export was cut before the root span under load. That is #1794, filed earlier today; this run is noted there. This change doesn't touch OTel. internal/agent was timed against the unchanged base under the same load and ran at the same pace.
219 lines
13 KiB
JavaScript
219 lines
13 KiB
JavaScript
// Run with Node's test runner and Playwright on the module path; see README.md.
|
|
// wangye1644294 on X: magpie isn't friendly to a first-time user; a guide,
|
|
// routing set up in a click and the agents found here, please. A new user's
|
|
// Agents page (the window's first page, and the panel's first tab) has a Get
|
|
// started card: add a model source, connect an agent (those found here, each
|
|
// connected in a click), and, optionally, a routing group made of their own
|
|
// models in a click. Each step is ticked from the state the server gives,
|
|
// never from having been seen; the card goes once the first two are done,
|
|
// and put away it stays away, kept in the settings, not the page's storage.
|
|
// Both engines, a wide and a narrow window and the panel, every language.
|
|
// 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 assets = path.resolve(__dirname, "../assets");
|
|
const shots = process.env.ARTIFACT_DIR;
|
|
|
|
// world is what the fake server knows, changed by the page's writes
|
|
function newWorld() {
|
|
return { served: 0, wired: false, hidden: false, groups: [] };
|
|
}
|
|
|
|
function agents(w) {
|
|
// with no model served, the agents' pickers have none of magpie's
|
|
const mine = w.served ? [{ value: "relay/m1", label: "m1", ref: "relay/m1", note: "Relay · via magpie" }] : [];
|
|
const field = (value, own) => [{ key: "model", label: "model", value, options: [...own, ...mine] }];
|
|
return [
|
|
{ id: "codex", name: "Codex", icon: "generic", path: "/fixture/codex", wired: w.wired, fields: field(w.wired ? "relay/m1" : "", [{ value: "gpt-5.4", label: "GPT-5.4" }]) },
|
|
{ id: "claude", name: "Claude Code", icon: "generic", path: "/fixture/claude", fields: field("", [{ value: "sonnet", label: "Sonnet" }]) },
|
|
{ id: "opencode", name: "OpenCode", icon: "generic", path: "/fixture/opencode", fields: field("", []) },
|
|
// never connectable: not offered on the card
|
|
{ id: "cursor", name: "Cursor", icon: "generic", path: "/fixture/cursor", fields: [] },
|
|
];
|
|
}
|
|
|
|
const templates = [
|
|
{ kind: "smart", group: { id: "smart-split", name: "Hard to strong, easy to cheap", members: ["relay/m1", "other/m2"] } },
|
|
{ kind: "thrifty", need: "cheap", of: "m1", group: { id: "cheap-first", name: "Cheap first", members: [] } },
|
|
{ kind: "steady", group: { id: "never-stuck", name: "Never stuck", members: ["relay/m1", "other/m2"] } },
|
|
];
|
|
|
|
function server(lang, w, posts) {
|
|
const settings = () => ({ lang, theme: "light", guideHidden: w.hidden || undefined });
|
|
const state = () => ({ agents: agents(w), profiles: [], served: w.served, settings: settings() });
|
|
const groups = () => ({ groups: w.groups, models: [], pools: [], deciders: [], templates });
|
|
return async (route) => {
|
|
const req = route.request(), url = new URL(req.url());
|
|
const json = (data, status = 200) => route.fulfill({ status, json: data });
|
|
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 (req.method() === "POST") posts.push(url.pathname + url.search);
|
|
if (url.pathname === "/api/state") return json(state());
|
|
if (url.pathname === "/api/settings/guide") {
|
|
w.hidden = !!req.postDataJSON().hidden;
|
|
return json(settings());
|
|
}
|
|
if (url.pathname === "/api/agents/connect/codex") {
|
|
w.wired = true;
|
|
return json(state());
|
|
}
|
|
if (url.pathname === "/api/groups/template") {
|
|
const { kind, name } = req.postDataJSON();
|
|
const tp = templates.find((x) => x.kind === kind);
|
|
w.groups.push({ ...tp.group, name });
|
|
return json(groups());
|
|
}
|
|
if (url.pathname === "/api/groups") return json(groups());
|
|
if (url.pathname === "/api/usage/quotas") return json([]);
|
|
if (url.pathname === "/api/plugins") return json({ plugins: [] });
|
|
if (url.pathname === "/api/agents/cli") return json({ agents: {}, pending: false });
|
|
if (url.pathname === "/api/providers") return json({ providers: [], presets: [], excluded: [], gateway: { running: true, window: true } });
|
|
if (url.pathname.startsWith("/api/")) return 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)];
|
|
try { await route.fulfill({ body: await fs.readFile(file), contentType }); } catch { await route.fulfill({ status: 404, body: "" }); }
|
|
};
|
|
}
|
|
|
|
const LAYOUTS = [
|
|
{ name: "window", url: "/?view=agents", viewport: { width: 1100, height: 760 } },
|
|
{ name: "narrow", url: "/?view=agents", viewport: { width: 420, height: 760 } },
|
|
{ name: "panel", url: "/?mode=panel", viewport: { width: 400, height: 640 } },
|
|
];
|
|
const LANGS = ["en", "zh", "zh-TW", "ja", "de"];
|
|
const STRINGS = ["Get started", "Add a model source", "Connect an agent", "Set up routing (optional)", "Hide Get started",
|
|
"A subscription you already pay for, a provider, or an API key", "magpie found these on this computer. Click one to connect it:",
|
|
"A routing group sends each request to the right model, and to the next one when a model fails", "+{n} more below", "{n} of {m} done", "{n} models ready to use", "Add “{name}”"];
|
|
|
|
async function open(browser, layout, lang, w, posts) {
|
|
const context = await browser.newContext({ viewport: layout.viewport, reducedMotion: "reduce" });
|
|
await context.addInitScript(() => { try { localStorage.setItem("magpie.panelTab", "agents"); } catch {} });
|
|
const page = await context.newPage();
|
|
page.setDefaultTimeout(5000);
|
|
page.errors = [];
|
|
page.on("pageerror", (e) => page.errors.push(e.message));
|
|
await page.route("**/*", server(lang, w, posts));
|
|
await page.goto("http://magpie.test" + layout.url);
|
|
await page.locator(".row.agent").first().waitFor();
|
|
return { context, page };
|
|
}
|
|
|
|
const stepDone = (page, step) => page.locator(`.guide-step[data-step="${step}"]`).evaluate((e) => e.classList.contains("done"));
|
|
const tops = (page) => page.evaluate(() => [document.scrollingElement.scrollTop, document.querySelector("#view-agents")?.scrollTop]);
|
|
const sideways = (page) => page.evaluate(() => {
|
|
const v = document.querySelector("#view-agents"), g = document.querySelector(".guide");
|
|
return v.scrollWidth > v.clientWidth + 1 || document.scrollingElement.scrollWidth > innerWidth
|
|
|| (g && [...g.querySelectorAll("*")].some((e) => e.getBoundingClientRect().right > g.getBoundingClientRect().right + 1));
|
|
});
|
|
|
|
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
|
for (const lang of LANGS) {
|
|
for (const layout of LAYOUTS) {
|
|
test(`${engine} ${lang} ${layout.name}: Get started ticks from state, connects in a click and goes once done`, async (t) => {
|
|
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
|
t.after(() => browser.close());
|
|
const w = newWorld(), posts = [];
|
|
const { page } = await open(browser, layout, lang, w, posts);
|
|
const tr = (s, v) => page.evaluate(([s, v]) => t(s, v), [s, v]);
|
|
if (lang !== "en") {
|
|
for (const s of STRINGS) assert.notEqual(await tr(s), s, `${lang} has "${s}"`);
|
|
}
|
|
|
|
// a new user: nothing served, nothing wired
|
|
const card = page.locator("#agentsLead .guide");
|
|
await card.waitFor();
|
|
assert.equal((await page.locator(".guide-h").textContent()), await tr("Get started"));
|
|
assert.equal(await stepDone(page, "source"), false);
|
|
assert.equal(await stepDone(page, "agent"), false);
|
|
assert.equal(await page.locator(".guide-n").textContent(), await tr("{n} of {m} done", { n: 0, m: 2 }));
|
|
// the agents found here are named, Cursor (never connectable) not;
|
|
// with no models yet they can't be connected
|
|
assert.deepEqual(await page.locator(".guide-agent").evaluateAll((bs) => bs.map((b) => b.dataset.id)), ["codex", "claude", "opencode"]);
|
|
assert.ok(await page.locator(".guide-agent").evaluateAll((bs) => bs.every((b) => b.disabled)));
|
|
// routing waits for a model source: no button yet
|
|
assert.equal(await page.locator(".guide-tpl").count(), 0);
|
|
assert.equal(await sideways(page), false, "nothing runs off sideways");
|
|
if (shots && (lang === "en" || lang === "zh")) await page.screenshot({ path: path.join(shots, `getting-started-${engine}-${lang}-${layout.name}-new.png`) });
|
|
|
|
// the first step's button: the window opens the add sheet, the
|
|
// panel the window on Providers
|
|
const top = await tops(page);
|
|
await page.locator('.guide-step[data-step="source"] .guide-go').click();
|
|
if (layout.name === "panel") {
|
|
for (let i = 0; i < 50 && !posts.includes("/api/window/main?view=providers"); i++) await page.waitForTimeout(20);
|
|
assert.ok(posts.includes("/api/window/main?view=providers"), posts.join(" "));
|
|
} else {
|
|
await page.locator("#view-providers").waitFor({ state: "visible" });
|
|
await page.locator("#addSheet").waitFor({ state: "visible" });
|
|
}
|
|
|
|
// a provider added: the step is ticked from the state, the agents can
|
|
// be connected, and a routing group is a click away
|
|
w.served = 12;
|
|
await page.goto("http://magpie.test" + layout.url);
|
|
await card.waitFor();
|
|
assert.equal(await stepDone(page, "source"), true);
|
|
assert.match(await page.locator('.guide-step[data-step="source"] .guide-say').textContent(), /12/);
|
|
assert.equal(await page.locator(".guide-n").textContent(), await tr("{n} of {m} done", { n: 1, m: 2 }));
|
|
const codex = page.locator('.guide-agent[data-id="codex"]');
|
|
assert.equal(await codex.isDisabled(), false);
|
|
const tpl = page.locator(".guide-tpl");
|
|
await tpl.waitFor();
|
|
assert.equal(await tpl.getAttribute("data-kind"), "steady", "the harmless template first; the one that can't be made isn't offered");
|
|
const name = await tr("Never stuck");
|
|
assert.equal(await tpl.textContent(), await tr("Add “{name}”", { name }));
|
|
if (shots && (lang === "en" || lang === "zh")) await page.screenshot({ path: path.join(shots, `getting-started-${engine}-${lang}-${layout.name}-source.png`) });
|
|
|
|
const before = await tops(page);
|
|
await tpl.click();
|
|
await page.locator('.guide-step[data-step="routing"].done').waitFor();
|
|
assert.ok(posts.includes("/api/groups/template"));
|
|
assert.equal(w.groups[0].name, name, "saved under the name shown");
|
|
assert.match(await page.locator('.guide-step[data-step="routing"] .guide-say').textContent(), new RegExp(name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")));
|
|
|
|
// one click connects Codex, and with both steps done the card goes
|
|
await codex.click();
|
|
await card.waitFor({ state: "detached" });
|
|
assert.ok(posts.includes("/api/agents/connect/codex"));
|
|
assert.deepEqual(await tops(page), before, "no click moved the page");
|
|
assert.equal(top[0], before[0]);
|
|
|
|
// done stays done: a reload brings no card back
|
|
await page.goto("http://magpie.test" + layout.url);
|
|
await page.locator(".row.agent").first().waitFor();
|
|
assert.equal(await page.locator(".guide").count(), 0);
|
|
assert.deepEqual(page.errors, []);
|
|
});
|
|
|
|
test(`${engine} ${lang} ${layout.name}: Get started put away stays away, in the settings`, async (t) => {
|
|
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
|
t.after(() => browser.close());
|
|
const w = newWorld(), posts = [];
|
|
const first = await open(browser, layout, lang, w, posts);
|
|
const page = first.page;
|
|
await page.locator("#agentsLead .guide").waitFor();
|
|
const top = await tops(page);
|
|
await page.locator(".guide-x").click();
|
|
await page.locator(".guide").waitFor({ state: "detached" });
|
|
assert.ok(posts.includes("/api/settings/guide"));
|
|
assert.equal(w.hidden, true);
|
|
assert.deepEqual(await tops(page), top, "no click moved the page");
|
|
assert.deepEqual(page.errors, []);
|
|
await first.context.close();
|
|
|
|
// a fresh browser storage (the other window, a reinstall's webview):
|
|
// still away, though no step is done
|
|
const again = await open(browser, layout, lang, w, posts);
|
|
await again.page.waitForTimeout(150);
|
|
assert.equal(await again.page.locator(".guide").count(), 0);
|
|
assert.equal(await again.page.evaluate(() => { try { return Object.keys(localStorage).filter((k) => /guide/i.test(k)).length; } catch { return 0; } }), 0, "nothing kept in localStorage");
|
|
assert.deepEqual(again.page.errors, []);
|
|
});
|
|
}
|
|
}
|
|
}
|