The owner (11-12): Memory should have its own icon, a brain. The Library's Memory tab had a bookmark, and Memory's own requests (the conversations it reads into memories, made as memdistill.Agent "memory") were drawn in Routing's graph, Usage and Sessions with the generic cube under their raw id, since "memory" was no client. - icons/memory.svg: a brain, 16-grid, stroke 1.4 with round caps and joins, as the sidebar's marks are; drawn as a one-tone mask. - navicons.js: the Library's Memory tab draws the same path. - agent.others: a client "memory", named Memory, with that icon, so /api/state's clients and agent.Looks (Usage, Sessions) name and draw it. It has no User-Agent: its requests are known by their token. - TestEveryClientHasNameAndIcon: memdistill.Agent is among the ids the gateway records, so it must be a client with a real icon. - tests/memory-icon.test.cjs: the sidebar's Memory tab draws the path icons/memory.svg has (and no other tab does), and a request from "memory" in Routing is drawn with the memory mask, not the cube. Chromium and WebKit, en/zh/zh-TW/ja/de, 1100 and 420px (no sidebar at 420px, so there the request only). Run on the tree rebased ontoff8b43711(same five-file diff; the go packages and the four GUI files first ran atfa7e466acand again here: TestEveryClientHasNameAndIcon ok, 42 of 42) (mote; mote was at load ~27 and mica ~43, mote was the less loaded): - go test ./internal/agent ./internal/gui ./internal/memdistill ./internal/usageapi: ok. - node --test memory-icon nav-sub-icons routing-client-icons i18n-keys: 42 of 42 ok, both engines. - go vet: darwin agent+gui; GOOS=linux agent (gui needs cgo for wails on linux); GOOS=windows agent+gui: ok. gofmt -l clean. Broken by hand (origin/mainfa7e466acwith the new tests): - TestEveryClientHasNameAndIcon: "the gateway records requests as memory, which isn't among the clients". - memory-icon.test.cjs with no icons/memory.svg: 2 of 2 red; with the svg but the old bookmark path: 12 of 22 red, every 1100px case. Not tried: the real app on any OS; Codex's own memories model row (MEMORIES in app.js) keeps its notebook, as it is Codex's memories, not Magpie Memory. The Magpie Memory MCP server keeps magpie's favicon, as magpie's other servers do.
116 lines
7.2 KiB
JavaScript
116 lines
7.2 KiB
JavaScript
// Run with Node's test runner and Playwright on the module path; see README.md.
|
|
// Magpie Memory has a mark of its own, a brain (the owner, 11-12: the
|
|
// Library's Memory tab had a bookmark, and Memory's own requests the
|
|
// generic cube in Routing). The sidebar's Memory tab and every request
|
|
// Memory makes (client "memory", agent.others) draw the one brain in
|
|
// icons/memory.svg. TestEveryClientHasNameAndIcon holds the client to
|
|
// the Go table. Chromium and WebKit, every language, 1100 and 420px (the
|
|
// sidebar is there at 1100 only). 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 HOME = "/Users/aimer";
|
|
const now = new Date();
|
|
const day = [now.getFullYear(), now.getMonth() + 1, now.getDate()].map((n) => String(n).padStart(2, "0")).join("-");
|
|
const at = (i) => new Date(now.getTime() - (i + 1) * 60e3).toISOString();
|
|
// as agent.Clients() gives them
|
|
const clients = [
|
|
{ id: "claude", name: "Claude Code", icon: "claude-color" },
|
|
{ id: "memory", name: "Memory", icon: "memory" },
|
|
];
|
|
const routes = clients.map((c, i) => ({
|
|
id: 100 + i, seq: 100 + i, time: at(i), agent: c.id, model: "claude-haiku-4-5", provider: "anthropic",
|
|
order: [], tries: [], done: true, status: 200, ms: 900, tokens: 100,
|
|
}));
|
|
const agent = (id, name) => ({ id, name, icon: "", skills: `${HOME}/.${id}/skills`, mcp: `${HOME}/.${id}/mcp.json` });
|
|
const lib = {
|
|
dir: `${HOME}/.magpie/library`, backups: `${HOME}/.magpie/backups`, home: HOME,
|
|
agents: [agent("claude", "Claude Code")],
|
|
instructions: { agents: [], sets: [] }, foundServers: [], projects: [], foundSkills: [], skills: [], servers: [],
|
|
};
|
|
|
|
function serve(lang) {
|
|
const state = { agents: [], clients, profiles: [], settings: { lang, theme: "light" } };
|
|
return 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:${JSON.stringify(lang)},theme:"light",web:false};` });
|
|
if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
|
|
if (url.pathname === "/api/state") return json(state);
|
|
if (url.pathname === "/api/gateway/trace") {
|
|
if (url.searchParams.get("wait")) await new Promise((r) => setTimeout(r, 20e3));
|
|
return json({ mine: true, now: now.toISOString(), seq: 1, totals: { requests: 0, rerouted: 0, errors: 0 }, routes: [] });
|
|
}
|
|
if (url.pathname === "/api/gateway/history") {
|
|
const d = url.searchParams.get("day");
|
|
return json({ cut: false, days: [{ day, requests: routes.length }], routes: d ? routes : [] });
|
|
}
|
|
if (url.pathname === "/api/providers") return json({ providers: [], presets: [], excluded: [], gateway: { url: "http://127.0.0.1:3425", running: true, window: true }, plugins: [] });
|
|
if (url.pathname === "/api/groups") return json({ groups: [], pools: [] });
|
|
if (url.pathname === "/api/library") return json(lib);
|
|
if (url.pathname === "/api/memory") return json({ memories: [] });
|
|
if (url.pathname.startsWith("/api/")) return json({});
|
|
if (!/^\/[\w./-]*$/.test(url.pathname) || url.host !== "magpie.test") return route.fulfill({ status: 404, body: "" });
|
|
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: "" }); }
|
|
};
|
|
}
|
|
|
|
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
|
test(`${engine}: Memory is drawn with its brain`, async (t) => {
|
|
// the brain, as icons/memory.svg has it
|
|
const svgText = await fs.readFile(path.join(assets, "icons/memory.svg"), "utf8").catch(() => "");
|
|
const brain = (svgText.match(/<path d="([^"]+)"/) || [])[1];
|
|
assert.ok(brain, "icons/memory.svg has a path");
|
|
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
|
t.after(() => browser.close());
|
|
for (const lang of ["en", "zh", "zh-TW", "ja", "de"]) for (const width of [1100, 420]) await t.test(`${lang} ${width}px`, async () => {
|
|
const context = await browser.newContext({ viewport: { width, height: 800 }, reducedMotion: "reduce" });
|
|
t.after(() => context.close());
|
|
const page = await context.newPage();
|
|
page.setDefaultTimeout(5000);
|
|
page.setDefaultNavigationTimeout(60000);
|
|
const errors = [];
|
|
page.on("pageerror", (e) => errors.push(e.message));
|
|
await page.route("**/*", serve(lang));
|
|
|
|
if (width === 1100) {
|
|
// the sidebar's Memory tab: the brain, and no other tab has it
|
|
await page.goto("http://magpie.test/?view=library");
|
|
await page.waitForSelector("body.side-nav");
|
|
await page.waitForFunction(() => window.NAV_SUB_IC && document.querySelectorAll('.nav-sub[data-view="library"]:not(.leaving) .nav-s').length >= 8);
|
|
const tabs = await page.evaluate(() => [...document.querySelectorAll('.nav-sub[data-view="library"]:not(.leaving) .nav-s')].map((s) => ({
|
|
text: s.querySelector(":scope > span")?.textContent, d: s.querySelector(":scope > svg path")?.getAttribute("d") || "",
|
|
})));
|
|
const memName = await page.evaluate(() => document.querySelector('[data-seg="memory"]')?.textContent.trim());
|
|
assert.ok(memName, "Library has a Memory tab");
|
|
const mem = tabs.find((x) => x.text === memName);
|
|
assert.ok(mem, `${memName} in ${JSON.stringify(tabs.map((x) => x.text))}`);
|
|
assert.equal(mem.d, brain, `${memName}'s mark is the brain`);
|
|
assert.equal(tabs.filter((x) => x.d === brain).length, 1, "only Memory has the brain");
|
|
}
|
|
|
|
// a request Memory made: its brain and its name, never the cube
|
|
await page.goto("http://magpie.test/?view=routing");
|
|
await page.locator(".rt-days .rt-day").nth(1).click();
|
|
await page.locator(".rt-req").nth(clients.length - 1).waitFor();
|
|
// the mask's picture has come, or failed (a failed one is the cube)
|
|
await page.evaluate(() => new Promise((r) => { const i = new Image(); i.onload = i.onerror = r; i.src = "icons/memory.svg"; }));
|
|
await page.evaluate(() => new Promise((r) => requestAnimationFrame(() => setTimeout(r))));
|
|
const row = await page.locator(".rt-req").evaluateAll((bs) => bs.map((b) => {
|
|
const ic = b.querySelector(".asked .ic");
|
|
return { title: b.title, icon: ic?.dataset.icon, generic: !!ic?.classList.contains("generic"), mask: !!ic?.querySelector(".mask") };
|
|
}).find((x) => x.title.startsWith("Memory · ")));
|
|
assert.ok(row, "Memory's request is listed by its name");
|
|
assert.equal(row.icon, "memory", JSON.stringify(row));
|
|
assert.ok(!row.generic && row.mask, `drawn with icons/memory.svg, not the cube: ${JSON.stringify(row)}`);
|
|
assert.deepEqual(errors, []);
|
|
});
|
|
});
|
|
}
|