Files
magpie/internal/gui/tests/lan-lazycat.test.cjs
T
yetone 16a2dfac9c lan: a LazyCat app offers the box's LAN address, or says how to forward the port
mtoolstec on X (after v0.1.3432) runs magpie from the magpie-lzcapp
package on a LazyCat box. Settings -> Share on local network offered
https://magpie.<box>.heiyu.space/v1, which only devices with LazyCat's
client reach, and http://172.28.3.65:3425/v1, the container bridge,
named "Other containers on this host", which nothing off the box
reaches. Other devices on his LAN wanted http://192.168.0.100:3425/v1.
The package runs magpie on the app's bridge network, and LazyCat
publishes an app's ports only on heiyu.space, not on the box's LAN
address. Its env names the app's domain, never the box's LAN IP.

- On the box's own network (network_mode: host, as LazyCat's Emby, Lucky
  and LAN Sheriff run), magpie now finds the box's LAN addresses. It sees
  the box's bridges/veths, or host.lzcapp is one of its own addresses, and
  takes the IPv4 of the default route's interface, minus host.lzcapp.
  LANURLs lists them first and the app domain after. A MAGPIE_PUBLIC_URL
  of the user's own (not the domain) stays first, and a pinned
  MAGPIE_ADDR still serves only that address. The sidebar names the box
  address, not the domain.
- On a bridge network that address can't be known. The domain is listed
  alone, named "LazyCat client", and the container-bridge address is no
  longer offered under LazyCat (ContainerHostURL ""). The row under the
  address, in Settings and on the Gateway page, says to forward the port
  with LazyCat's "LAN port forwarding" app (局域网端口转发工具). The CLI
  banner (serve, web) says the same.
- New settings/gateway fields: lanLazyCat, lanLazyCatBox; lazyCat,
  lazyCatBox (and boot.js's sideGateway). Strings are in zh, zh-TW, ja
  and de.
- host.lzcapp is looked up only under LAZYCAT_APP_DOMAIN, with a 2s
  timeout and no lock held. An answer is kept; a failure is retried after
  a minute.

Package side: the magpie-lzcapp package (lazycat-contrib, czyt) needs
network_mode: host plus host.lzcapp upstreams and the net.* permissions,
or its usage needs the port-forward steps. An issue is filed there.

Run (mote, macOS, at this tree on origin/main ce6ae593c; then rebased
onto ab084fdf2; api.go, providers.go and i18n.js changed there too and
merged clean):
- gofmt -l: clean. go vet: darwin for gateway/gui/cli; CGO_ENABLED=0
  GOOS=linux -tags nogui ./... and GOOS=windows ./...: ok.
- go test -timeout 45m ./...: ok (before the string reword; after it,
  internal/cli and internal/gateway again: ok).
- wsl-run (Ubuntu 24.04): the LazyCat/default-route/LAN tests in
  internal/gateway and internal/cli: ok.
- GUI: lan-lazycat (new: 2 engines x 5 languages x 1100/420px, 20 tests),
  i18n-keys, i18n-en-no-cjk, gui-de/ja/zh-tw, lan-docker and
  side-gateway-lan: 85 pass, 0 fail. A wider set (lan-*, gateway-*, connect-*,
  key-page, sidebar, phone-*, remote-magpie and others; 835 tests) was
  run before the reword. Its reds were the i18n placeholder check
  (fixed: no <box IP> in the string), and phone-connect-menu 420 (#4706,
  #4707) and remote-magpie (#4398). Those last two are red the same alone
  on origin/main b03a37476 on mote.
- Real Linux containers (Docker on xiaomi-gpu), with a test binary
  printing what the real functions find. LAZYCAT_APP_DOMAIN was set and
  host.lzcapp added as host-gateway.
  - bridge: ifaces [lo eth0], LANURLs [https://magpie.snyht3.heiyu.space],
    ContainerHostURL "".
  - --network host: ifaces [lo services1 eth0 docker0], defaultIfaces
    [eth0], LANURLs [http://192.168.65.3:3425 https://magpie...],
    ContainerHostURL "".
- Broken by hand: LANURLs without the box branch and ContainerHostURL
  without the LazyCat check turn TestLazyCatOffersTheBoxAddress red (6
  failures). The old settings.js turns lan-lazycat red (10 of 10,
  chromium).

Not tried: no LazyCat box is at hand. Not checked on a real box: lzcos's
interface names on the host network, where host.lzcapp points in host
mode, and which interface holds the default route.

At the rebased head: gofmt clean; go vet of internal/gui, gateway and
cli; their Budget/LazyCat/LAN/Container/PublicURL/Parity tests ok; GUI
lan-lazycat, i18n-keys, i18n-en-no-cjk, lan-docker, side-gateway-lan:
76 pass, 0 fail.
2026-11-10 07:34:29 +08:00

113 lines
7.0 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.
// mtoolstec on X ran magpie as a LazyCat (懒猫微服) app. Share on local
// network offered the app's domain, which only devices with LazyCat's
// client reach, and the box's container bridge (172.28.3.65), which
// nothing off the box reaches, named other containers'; other devices on
// the home network wanted http://192.168.0.100:3425/v1.
// - On the box's network (the package's network_mode: host) magpie finds
// the box's LAN address: it comes first, then the domain, named LazyCat
// client's, in Settings' menu, on the Gateway page and in the sidebar.
// - On a bridge network that address can't be known: the domain alone,
// named the same, and a line says how the port gets to the box's LAN
// address (LazyCat's LAN port forwarding app), in Settings and on the
// Gateway page. No bridge address is offered.
// No backend, the API is faked here.
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, reach } = require("./reader.cjs");
const LC = "https://magpie.snyht3.heiyu.space", BOX = "http://192.168.0.100:3999", HERE = "http://127.0.0.1:3999";
const words = {
en: { client: "LazyCat client", head: "LazyCat", lan: "Local network", here: "This computer",
sub: "Only devices with the LazyCat client reach this address. For other devices to use the box’s LAN IP on port 3999, forward port 3999 to Magpie in LazyCat’s LAN port forwarding app" },
zh: { client: "懒猫客户端", head: "懒猫微服", lan: "局域网", here: "本机",
sub: "只有装了懒猫客户端的设备能访问这个地址。要让其他设备用微服的局域网 IP 加 3999 端口访问,请在懒猫的「局域网端口转发工具」里把 3999 端口转发到 Magpie" },
"zh-TW": { client: "懶貓用戶端", head: "懶貓微服", lan: "區域網", here: "本機", sub: /區域網 IP 加 3999 連接埠.*「局域網端口轉發工具」/ },
ja: { client: "LazyCat クライアント", head: "LazyCat", lan: "ローカルネットワーク", here: "このコンピュータ", sub: /LAN IP のポート 3999.*ポート 3999/ },
de: { client: "LazyCat-Client", head: "LazyCat", lan: "Lokales Netzwerk", here: "Dieser Computer", sub: /LAN-IP der Box auf Port 3999.*Port 3999/ },
};
const same = (got, want) => want instanceof RegExp ? assert.match(got, want) : assert.equal(got, want);
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
for (const lang of ["en", "zh", "zh-TW", "ja", "de"]) {
for (const width of [1100, 420]) {
test(`${engine} ${lang} ${width}: a LazyCat app offers the box's LAN address, or says how to get it`, async (t) => {
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
t.after(() => browser.close());
const w = words[lang];
const open = async (view, box) => {
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, bootGateway: true, publicURL: LC, lazyCat: LC,
lazyCatBox: box, lanURLs: box ? [BOX, LC] : [LC] }));
await page.goto("http://magpie.test/?view=" + view);
return { page, errors };
};
const fits = async (page) => assert.equal(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth), true, "wider than the window");
const list = async (page) => {
await page.locator("#gatewayLan .gw-url").first().waitFor();
const rows = page.locator("#gatewayLan .gw-url");
const out = [];
for (let i = 0; i < await rows.count(); i++)
out.push([(await rows.nth(i).locator(".gw-url-label").textContent()).trim(), (await rows.nth(i).locator("code").textContent()).trim()]);
return out;
};
const side = (page) => page.locator("#sideGw span").textContent();
// on the box's network: the box's address first, then the domain
{
const { page, errors } = await open("settings", true);
await page.locator("#sideGw").waitFor({ state: "attached" }); // folded away at 420px, and still drawn
assert.match(await side(page), /192\.168\.0\.100:3999/);
await openPart(page, "network");
await page.locator("#lanList .lan-address-row").waitFor();
assert.equal(await page.locator("#lanList .lan-container").count(), 0);
await reach(page, page.locator("#lanList .lan-interface"));
await page.locator("#lanList .lan-interface").click();
const items = page.locator(".proto-menu .pm-item");
await items.first().waitFor();
assert.deepEqual((await items.locator(".pm-name").allTextContents()).map((x) => x.trim()), [BOX + "/v1", LC + "/v1"]);
assert.deepEqual((await items.locator(".pm-note").allTextContents()).map((x) => x.trim()), ["", w.client]);
await fits(page);
assert.deepEqual(errors, []);
}
{
const { page, errors } = await open("gateway", true);
assert.deepEqual(await list(page), [[w.here, HERE], [w.lan, BOX], [w.client, LC]]);
assert.equal(await page.locator("#gatewayLan .gw-url-none").count(), 0);
await fits(page);
assert.deepEqual(errors, []);
}
// on a bridge network: the domain, and how to reach the box
{
const { page, errors } = await open("settings", false);
await openPart(page, "network");
await page.locator("#lanList .lan-address-row").waitFor();
assert.equal((await page.locator("#lanList .lan-address-text").textContent()).trim(), LC + "/v1");
const note = page.locator("#lanList .lan-container");
assert.equal((await note.locator(".name").textContent()).trim(), w.head);
same((await note.locator(".sub").textContent()).trim(), w.sub);
assert.doesNotMatch(await page.locator("#lanList").textContent(), /172\.28/);
const border = await note.evaluate((r) => getComputedStyle(r).borderLeftWidth);
assert(border === "0px" || border === "", "no left border accent: " + border);
await fits(page);
assert.deepEqual(errors, []);
}
{
const { page, errors } = await open("gateway", false);
assert.deepEqual(await list(page), [[w.here, HERE], [w.client, LC]]);
same((await page.locator("#gatewayLan .gw-url-none").textContent()).trim(), w.sub);
assert.match(await side(page), /magpie\.snyht3\.heiyu\.space/);
await fits(page);
assert.deepEqual(errors, []);
}
});
}
}
}