In a browser tab (magpie web, or the app served to a browser) api("open")
always ran window.open in the viewer's browser, so a cindy:// import link
opened the viewer's own Cindy while the "added" status is read from the
host's Cindy database. App import links now go to /api/open and webHost
opens them with the host's system opener (openOnHost); http(s) links stay
the page's. Fixes Cindy, Lody, AionUi and Cherry Studio rows alike.
Run (mote, at this head): go test -tags nogui ./internal/gui ok; go vet nogui,
windows, darwin ok; gofmt clean; GUI import-web-host, import-row, click-scroll,
i18n-keys: 27 pass / 0 fail in chromium and in webkit.
Broken by hand: old app.js, new import-web-host test in chromium: red (the
page tried to launch cindy:// itself, no /api/open request). The Go test does
not compile on the old web.go (no openOnHost).
Not tried: a real remote host with a real Cindy; the old-code run in webkit.
54 lines
3.2 KiB
JavaScript
54 lines
3.2 KiB
JavaScript
// In a browser tab (magpie web, possibly on another machine than the one
|
|
// magpie runs on), Add magpie asks the host to open the app's import link; it
|
|
// never navigates the viewer's own browser to it (Jealousy_Du on X).
|
|
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 LINK = "cindy://provider/import?v=1&data=fixture";
|
|
const cindy = { id: "cindy", name: "Cindy", path: "", icon: "cindy", import: LINK, added: false, fields: [] };
|
|
|
|
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
|
test(`web: Add magpie opens the link on the host (${engine})`, async () => {
|
|
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
|
const page = await browser.newPage({ viewport: { width: 960, height: 600 } });
|
|
page.setDefaultTimeout(8000);
|
|
const opened = [];
|
|
const navs = [];
|
|
page.on("framenavigated", (f) => navs.push(f.url()));
|
|
await page.route("http://magpie.test/**", async (route) => {
|
|
const url = new URL(route.request().url());
|
|
const json = (data) => route.fulfill({ json: data });
|
|
if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: 'window.bootPrefs = {lang:"en",theme:"light",web:true,textSize:100};' });
|
|
if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
|
|
if (url.pathname === "/api/state") return json({ agents: [cindy], profiles: [], settings: { lang: "en", theme: "light", textSize: 100 } });
|
|
if (url.pathname === "/api/providers") return json({ providers: [], gateway: { running: true, window: true } });
|
|
if (url.pathname === "/api/plugins") return json({ plugins: [] });
|
|
if (url.pathname === "/api/open") { opened.push(route.request().postDataJSON().url); return route.fulfill({ status: 204 }); }
|
|
if (url.pathname.startsWith("/api/")) return json({});
|
|
const rel = url.pathname === "/" ? "index.html" : url.pathname.slice(1);
|
|
try {
|
|
const body = await fs.readFile(path.join(assets, rel));
|
|
const type = rel.endsWith(".js") ? "text/javascript" : rel.endsWith(".css") ? "text/css" : rel.endsWith(".html") ? "text/html" : undefined;
|
|
return route.fulfill({ body, contentType: type });
|
|
} catch { return route.fulfill({ status: 404, body: "" }); }
|
|
});
|
|
await page.goto("http://magpie.test/");
|
|
await page.waitForLoadState("networkidle");
|
|
const more = page.locator('.agent-more[aria-expanded="false"]');
|
|
if (await more.count()) await more.click();
|
|
const row = page.locator('.row.agent[data-id="cindy"]');
|
|
await row.scrollIntoViewIfNeeded();
|
|
const asked = page.waitForRequest((r) => r.url().includes("/api/open"));
|
|
await row.locator(".ag-start").click();
|
|
await asked;
|
|
await new Promise((r) => setTimeout(r, 300));
|
|
assert.deepEqual(opened, [LINK]);
|
|
assert.ok(navs.every((u) => u.startsWith("http://magpie.test/")), `navigated: ${navs}`);
|
|
await browser.close();
|
|
});
|
|
}
|