Files
magpie/internal/gui/tests/profile-details.test.cjs
T
yetone 3e88fc09dc agent, gateway: Claude Code on a model Anthropic doesn't review gets auto mode's server review turned off, so it no longer says magpie isn't eligible (1EFLOPS on X)
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
  reason 8c21a4184 didn'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.
2026-10-12 21:53:20 +08:00

190 lines
12 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Run with Node's test runner and Playwright on the module path; see README.md.
// A saved profile's chip shows what the profile holds before it is applied
// (#467 emo172: a click on the chip applied it at once, so what it held
// could be seen only by applying it over the setup in use). A click on the
// chip opens its details: the agents' names, each one's fields under their
// labels (an empty one the agent's default, one that reads as a key shown as
// dots, each of Claude Code's four tiers, one left to follow the main model
// saying so and what that is: #480, they were missing), what the Library
// gives it; nothing is applied, and the chip clicked
// stays where it is on the screen. Apply in the details applies it, once; a
// second click on the chip closes them; ↻ and × are still on the chip. In the
// window and in the tray panel (its list scrolled to its end), in English
// and Chinese. 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 models = ["model-a", "model-b"].map((m) => ({ value: m, label: m }));
const agent = (id, name) => ({ id, name, path: "/test/" + id, fields: [{ key: "model", label: "model", value: "model-a", options: models }] });
const filler = (i) => ({ name: "profile-" + String(i).padStart(2, "0"), summary: "", agents: [] });
const work = {
name: "work", summary: "codex gpt-5",
library: { servers: 1, skills: 1, instructions: true },
agents: [
{ id: "claude", name: "Claude Code", fields: [
{ key: "model", label: "model", value: "magpie/a/main" },
{ key: "opus", label: "opus", value: "", follows: "model" },
{ key: "sonnet", label: "sonnet", value: "magpie/a/s" },
{ key: "haiku", label: "haiku", value: "", follows: "model" },
{ key: "fable", label: "fable", value: "", follows: "model" },
{ key: "subagent", label: "subagents", value: "" },
], servers: ["github"], skills: ["review"], models: { hidden: 0 } },
{ id: "codex", name: "Codex", fields: [
{ key: "model", label: "model", value: "magpie/openai/gpt-5" },
{ key: "effort", label: "effort", value: "high" },
{ key: "token", label: "token", value: "", hidden: true },
], instructions: true, models: { hidden: 8 } },
// an agent with no fields saved, only a model list: shown only its picks
{ id: "opencode", name: "OpenCode", fields: [], models: { hidden: 0, only: true, picked: 3 } },
],
};
function server(lang, calls, count) {
const profiles = [...Array.from({ length: count }, (_, i) => filler(i)), work, filler(99)];
return async (route) => {
const req = route.request(), url = new URL(req.url());
// Get started put away: the profiles strip is what is read, where it sits
const state = () => ({ agents: [agent("codex", "Codex"), agent("claude", "Claude Code")], profiles, settings: { lang, theme: "light", guideHidden: true } });
if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${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 route.fulfill({ json: state() });
if (url.pathname.startsWith("/api/profile/")) {
calls.push(url.pathname.slice("/api/profile/".length) + " " + (req.postDataJSON()?.name || ""));
return route.fulfill({ json: { ...state(), changed: 2 } });
}
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/providers") return route.fulfill({ json: { providers: [], gateway: { running: true } } });
if (url.pathname === "/api/window/fit") return route.fulfill({ status: 204 });
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 words = {
en: { model: "model", effort: "effort", high: "high", def: "agent default", follows: "follows the main model (magpie/a/main)", subagents: "subagents", servers: "MCP servers", skills: "Skills", instructions: "Instructions", on: "on", apply: "Apply", list: "Model list", all: "every model shown", hidden8: "8 hidden", picked3: "only the 3 picked" },
zh: { model: "模型", effort: "推理强度", high: "高", def: "Agent 默认值", follows: "跟随主模型(magpie/a/main)", subagents: "子代理", servers: "MCP 服务器", skills: "技能", instructions: "指令", on: "开启", apply: "应用", list: "模型列表", all: "全部显示", hidden8: "已隐藏 8 个", picked3: "仅显示所选的 3 个" },
};
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
test(engine + ": a profile's details before it is applied", async (t) => {
assert(["chromium", "webkit"].includes(engine), "BROWSER must be chromium or webkit");
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
const pages = [];
t.after(async () => {
if (process.env.ARTIFACT_DIR) {
await fs.mkdir(process.env.ARTIFACT_DIR, { recursive: true });
for (const [i, p] of pages.entries()) await p.screenshot({ path: path.join(process.env.ARTIFACT_DIR, `${engine}-profile-details-${i}.png`) });
}
await browser.close();
});
for (const lang of ["en", "zh"]) for (const panel of [false, true]) {
await t.test(`${lang}, ${panel ? "panel" : "window"}`, async () => {
const w = words[lang], calls = [], errors = [];
const page = await (await browser.newContext({ viewport: panel ? { width: 440, height: 420 } : { width: 900, height: 560 } })).newPage();
pages.push(page);
page.setDefaultTimeout(5000);
page.on("pageerror", (e) => errors.push(e.message));
await page.route("**/*", server(lang, calls, panel ? 30 : 3));
await page.goto("http://magpie.test/" + (panel ? "?mode=panel" : ""));
const chip = page.locator("#profiles .chip", { hasText: /^work/ });
await chip.waitFor({ state: "attached" });
if (panel) {
await page.locator("#profBtn").click();
await page.locator(".profiles.open").waitFor();
await page.waitForTimeout(450);
// the reader scrolls the list to its end, where "work" is
const box = await page.locator(".profiles").boundingBox();
await page.mouse.move(box.x + box.width / 2, box.y + 60);
for (let i = 0; i < 20; i++) { await page.mouse.wheel(0, 40); await page.waitForTimeout(20); }
await page.waitForTimeout(400);
assert(await page.locator(".profiles").evaluate((v) => v.scrollTop) > 0, "the list must be long enough to scroll");
} else {
await chip.scrollIntoViewIfNeeded();
await page.waitForTimeout(300);
}
const top = () => chip.evaluate((c) => c.getBoundingClientRect().top);
// a click opens its details, applying nothing, the chip where it was
const before = await top();
await chip.click();
const detail = page.locator(".prof-detail");
await detail.waitFor();
await page.waitForTimeout(350);
assert.deepEqual(calls, [], "opening the details must change nothing");
assert(Math.abs((await top()) - before) < 1, `the chip clicked must stay where it is: ${before} → ${await top()}`);
assert.equal(await chip.getAttribute("aria-expanded"), "true");
assert(await chip.locator(".x").count() === 2, "↻ and × stay on the chip");
const read = await detail.evaluate((d) => ({
name: d.querySelector(".pd-name").textContent,
apply: d.querySelector(".pd-apply").textContent,
groups: [...d.querySelectorAll(".pd-agent")].map((g) => ({
name: g.querySelector(".pd-gn").textContent,
rows: [...g.querySelectorAll("dt")].map((dt) => dt.textContent + "=" + dt.nextElementSibling.textContent),
})),
inView: (() => { const r = d.getBoundingClientRect(); return r.height > 40 && r.width > 200; })(),
}));
assert.equal(read.name, "work");
assert.equal(read.apply, w.apply);
assert(read.inView, "the details must be drawn");
assert.deepEqual(read.groups, [
{ name: "Claude Code", rows: [`${w.model}=magpie/a/main`, `opus=${w.follows}`, "sonnet=magpie/a/s", `haiku=${w.follows}`, `fable=${w.follows}`, `${w.subagents}=${w.def}`, `${w.list}=${w.all}`, `${w.servers}=github`, `${w.skills}=review`] },
{ name: "Codex", rows: [`${w.model}=magpie/openai/gpt-5`, `${w.effort}=${w.high}`, "token=••••••", `${w.list}=${w.hidden8}`, `${w.instructions}=${w.on}`] },
{ name: "OpenCode", rows: [`${w.list}=${w.picked3}`] },
]);
// a second click closes them; a third opens them again
await chip.click();
await page.waitForTimeout(200);
assert.equal(await detail.count(), 0, "a second click closes the details");
assert(Math.abs((await top()) - before) < 1, "closing them leaves the chip where it is");
await chip.click();
await detail.waitFor();
assert.deepEqual(calls, []);
// Apply applies it, once
await page.locator(".prof-detail .pd-apply").click();
await page.waitForFunction(() => /work/.test(document.querySelector(".status")?.textContent || ""));
assert.deepEqual(calls, ["use work"]);
assert.deepEqual(errors, []);
});
}
// the model list's line in the other languages (#1368)
const lists = {
"zh-TW": ["模型列表=全部顯示", "模型列表=已隱藏 8 個", "模型列表=僅顯示所選的 3 個"],
ja: ["モデル一覧=すべて表示", "モデル一覧=8 件非表示", "モデル一覧=選んだ 3 件のみ"],
de: ["Modellliste=alle angezeigt", "Modellliste=8 ausgeblendet", "Modellliste=nur die 3 ausgewählten"],
};
for (const [lang, want] of Object.entries(lists)) {
await t.test(`${lang}, the model lists`, async () => {
const errors = [];
const page = await (await browser.newContext({ viewport: { width: 900, height: 560 } })).newPage();
pages.push(page);
page.setDefaultTimeout(5000);
page.on("pageerror", (e) => errors.push(e.message));
await page.route("**/*", server(lang, [], 3));
await page.goto("http://magpie.test/");
const chip = page.locator("#profiles .chip", { hasText: /^work/ });
await chip.waitFor({ state: "attached" });
await chip.scrollIntoViewIfNeeded();
await chip.click();
await page.locator(".prof-detail").waitFor();
const rows = await page.locator(".prof-detail").evaluate((d) =>
[...d.querySelectorAll(".pd-agent dt")].map((dt) => dt.textContent + "=" + dt.nextElementSibling.textContent));
assert.deepEqual(rows.filter((r) => r.startsWith(want[0].split("=")[0] + "=")), want);
assert.deepEqual(errors, []);
});
}
});
}