Files
magpie/internal/gui/tests/statusline-remote.test.cjs
T
yetone 0e1054ce19 statusline: the gateway serves Claude Code's status line to another computer (steven_4422)
steven_4422 (Discord) runs magpie in Docker and Claude Code on the host.
The status line square writes the host's settings.json, which the
container can't reach, with a command naming a binary inside the container.

GET or POST /v1/magpie/statusline answers the line `magpie statusline`
prints, as text/plain, so the host needs only curl:
  curl -fsS -m 1 -H 'Authorization: Bearer <key>' --data-binary @- http://<host>:3425/v1/magpie/statusline || true
Claude Code's stdin JSON (session_id) adds the model, as /v1/magpie/route
does; ?session= and ?only= work too. The renderer moved to
provider.StatuslineText, shared by the CLI and the endpoint. A caller that
isn't this computer needs a gateway key (lanGuard, unchanged; the handler
also refuses a non-local caller without one). A read-only key is allowed
(GET and POST in readOnlyRoutes) and gets the windows without the model; a
key held to budget, models or accounts sees only its own (scopeQuotas).
corsGuard and origin checks are untouched.
magpie web shows the command in Settings -> About (en, zh, zh-TW, ja, de).
Docs: reference.md, agent-wiring.md, gateway-routing.md, docker pages en/zh/ja.

Run at this head (rebased on d8b3749ef), on mote:
- go build, gofmt -l, GOOS=windows go vet and GOOS=linux go vet -tags nogui
  on gateway, cli, provider: clean.
- go test: internal/gateway ok (a first full run failed once, 888s, name not
  kept; the rerun had no failure), TestStatusline*, TestReadOnlyKeyEveryRoute,
  TestStatuslineEndpointIsTheCLIsLine ok. internal/agent ok earlier, at the
  pre-rebase base.
- TestCoreScriptBudget ok after shortening the new strings (no raise).
- GUI: statusline-remote (22: 2 engines x 5 languages x 1100/400, plus the
  app without the row), public-url-default, i18n-keys, claude-statusline: all pass.
Broken by hand: model made wrong -> TestStatuslineEndpoint red; held-key
scope removed -> red; separator changed in the shared renderer ->
TestStatuslineEndpoint and cli TestStatuslineTellsRouteAndEveryAccount red;
the row's web check inverted -> the GUI test 0 of 22. Removing the
handler's own key check stays green because lanGuard refuses first (the
401 asserts hold through it).
Reds not from this change: cli TestEveryRouteHasACommandOrIsNamed
(GET /api/context/reply, from main), gui TestMainWindowCorners (red on
origin/main on mote), provider TestMoveToPlugin and TestMoveCutShort (red in
the full run, green alone).
Not tried: Docker or any container (not on mote or WSL); the real binary
from another computer over the LAN with a real Claude Code; the whole GUI
suite (running, 1182 files, finishes after the push); Windows and Linux
test runs.
2026-11-04 06:39:37 +08:00

56 lines
2.9 KiB
JavaScript

const assert = require("node:assert/strict");
const { test } = require("node:test");
const { chromium, webkit } = require("playwright");
const { fixture } = require("./fixtures/caller-keys.cjs");
const { openPart } = require("./reader.cjs");
// steven_4422 (Discord): magpie in Docker, Claude Code on the host. The
// status line square writes the host's settings.json with a binary inside
// the container, so magpie web shows the curl the host runs instead, against
// the gateway's own /v1/magpie/statusline. The app (not web) shows no such row.
const PUBLIC = "https://magpie.example.com";
const LANGS = ["en", "zh", "zh-TW", "ja", "de"];
const titles = {
en: "Status line on another computer", zh: "其他电脑上的状态栏", "zh-TW": "其他電腦上的狀態列",
ja: "別のコンピューターのステータスライン", de: "Statuszeile auf einem anderen Rechner",
};
async function setup(t, engine, lang, width, options) {
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
t.after(() => browser.close());
const page = await (await browser.newContext({ viewport: { width, height: 800 }, reducedMotion: "reduce" })).newPage();
page.setDefaultTimeout(6000);
page.setDefaultNavigationTimeout(60000);
const errors = [];
page.on("pageerror", (e) => errors.push(e.message));
await page.route("**/*", fixture(lang, "light", [], { lan: true, ...options }));
await page.goto("http://magpie.test/?view=gateway");
await page.locator("#prefs").waitFor();
if (!(await page.locator("#view-settings").isVisible())) await page.locator("#prefs").click();
await openPart(page, "about");
await page.locator("#about .row").first().waitFor();
return { page, errors };
}
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
for (const lang of LANGS) {
for (const width of [1100, 400]) {
test(`${engine} ${lang} ${width}: magpie web shows the curl for Claude Code on another computer`, async (t) => {
const { page, errors } = await setup(t, engine, lang, width, { lanURLs: [PUBLIC], publicURL: PUBLIC, web: true });
const row = page.locator("#statuslineRemoteRow");
await row.waitFor();
assert.match(await row.locator(".who").textContent(), new RegExp(titles[lang]));
assert.equal(await row.locator("code").textContent(),
"curl -fsS -m 1 -H 'Authorization: Bearer <gateway key>' --data-binary @- " + PUBLIC + "/v1/magpie/statusline || true");
assert.equal(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth), true, "About wider than the window");
assert.deepEqual(errors, []);
});
}
}
test(`${engine}: the app has no such row`, async (t) => {
const { page, errors } = await setup(t, engine, "en", 1100, { lanURLs: ["http://192.168.1.10:3999"] });
assert.equal(await page.locator("#statuslineRemoteRow").count(), 0);
assert.deepEqual(errors, []);
});
}