_meouwu on X: a memory added by hand in several lines showed as one line with its breaks gone; it should keep its format and, folded, show the first line and an ellipsis. Cause: the store never lost the breaks. A memory file's body is m.Text as written (encode/apply trim only the ends). They were lost where it was shown: the Library row clamped the name to two lines with white-space normal, the digest given to agents went through oneLine (strings.Fields), and so did memory_search / memory_list in the memory MCP. Now: - Library: a folded row and a suggestion show firstLine(text) (first line, " …" when more follow); an open row shows the whole text pre-wrap. The editor already kept "\n". - Digest and memory MCP: memory.Indented keeps each line, the lines after the first indented two spaces so the memory stays one list item. - Dream and distill listings stay one line on purpose: the model's reply is read line by line, and a user's memory is Fixed, never rewritten by them. Written in docs/subsystems/memory.md. Memories saved before: their files already hold the breaks, so after updating they show, edit and reach agents in their own lines. Nothing to redo, no migration. Run at 3fabaf8f2 (on origin/mainb332ef7ef, the pushed head), f6452d777 (on1622484a8) and ee84e288a (on54117164c), on the WSL VM magpie-desktop: mote and mica were over their cores with other sessions' suites for ~2h. - go vet -tags gtk3 ./... ok; gofmt -l clean. - go test -tags gtk3 -count=1 -timeout 45m ./... at ee84e288a: 101 ok, 2 FAIL, both red at origin/main2416beed6on the same VM: internal/gui TestClipboardReadBack (#7074, #7073), internal/usage TestRequestStateKeptAcrossACatalogFetchedAgain (#6572). - Whole GUI suite (concurrency 8): 1355 of 29368 red in 221 files under load. Those 221 again at concurrency 3: 71 red; 66 of them red at base54117164ctoo. Of the other 5, 3 pass alone; codex-auto-reset-settings (#6108) and copilot-ghe (#1949) are red at base alone too (2 of 3 and 3 of 3 rounds), commented there. - After the rebase (f6452d777): internal/memory, internal/memdistill and -run "Memory|Budget|I18n" in gateway, gui, library ok. All 84 library-*.test.cjs: 1920 of 1950 pass; each red file alone, beside1622484a8: commands-import, group-steady, mcp-copy-config, mcp-off-fold, open-again and all are red at base too (#7097; all 3 of 3 at base); memory-suggest, mcp-json and bili pass alone. - At 3fabaf8f2 (b332ef7efbrought flying_crp's digest header and memory_save note; conflicts were only both sides adding tests and doc text): go vet memory, gateway, memdistill; go test memory, memdistill, access, and -run "Memory|Budget|I18n|Digest" in gateway, gui, library ok; library-memory*.test.cjs 112 of 112. - library-memory-lines.test.cjs: 5 langs x 980/420 x chromium/webkit. Broken by hand (old code, new tests): TestMultiLineMemoryKeepsItsLines red at the digest step only (save, edit and the file passed: the store kept the breaks), TestIndented and TestMemorySearchKeepsTheLines red, library-memory-lines red ("Release steps: …" expected). Not tried: a macOS run (mote, mica busy), Windows, the real app.
118 lines
6.9 KiB
JavaScript
118 lines
6.9 KiB
JavaScript
// Run with Node's test runner and Playwright on the module path; see README.md.
|
|
// A memory written in several lines keeps them (_meouwu on X: "手动添加的
|
|
// 多行记忆被折叠成了一行,把我的换行都去掉了,应当保留原本的格式,收起展示的
|
|
// 时候显示首行+缩略符"). Folded, its row shows the first line and an
|
|
// ellipsis; open, the row shows every line as written and the editor holds
|
|
// them; one added in the editor is sent with its line breaks. A suggestion
|
|
// folds the same way. Every language, wide and narrow, Chromium and
|
|
// WebKit; 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(process.env.MAGPIE_ASSETS || path.join(__dirname, "../assets"));
|
|
const HOME = "/Users/mem";
|
|
const library = {
|
|
dir: `${HOME}/.magpie/library`, backups: `${HOME}/.magpie/backups`, home: HOME,
|
|
agents: [{ id: "codex", name: "Codex", icon: "", instructions: `${HOME}/.codex/AGENTS.md` }],
|
|
instructions: { shared: "", sets: [{ id: "default", name: "", active: true, text: "" }], agents: [] },
|
|
foundServers: [], projects: [], foundSkills: [], skills: [], servers: [],
|
|
};
|
|
const at = (d) => `2026-11-0${d}T10:00:00Z`;
|
|
const STEPS = "Release steps:\n1. tag the commit\n2. push the tag by name\n never --tags";
|
|
const memories = () => ({
|
|
memories: [
|
|
{ id: "a1", text: STEPS, why: "", kind: "procedure", scope: "global", origin: "user", status: "active", created: at(1), updated: at(2) },
|
|
{ id: "a2", text: "Never push to main", kind: "rule", scope: "global", origin: "user", status: "active", created: at(1), updated: at(1) },
|
|
],
|
|
suggestions: [{ key: "skill:a1", to: "skill", ids: ["a1"], text: STEPS, uses: 4 }],
|
|
projects: {}, digest: true, agents: [],
|
|
});
|
|
|
|
function server(lang, sent) {
|
|
return async (route) => {
|
|
const req = route.request();
|
|
const url = new URL(req.url());
|
|
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: { agents: [], profiles: [], settings: { lang, theme: "light" } } });
|
|
if (url.pathname === "/api/plugins") return route.fulfill({ json: { plugins: [] } });
|
|
if (url.pathname === "/api/library") return route.fulfill({ json: library });
|
|
if (url.pathname === "/api/memory/semantic") return route.fulfill({ json: { on: false } });
|
|
if (url.pathname === "/api/memory/distill") return route.fulfill({ json: { on: false, models: [] } });
|
|
if (url.pathname === "/api/memory") {
|
|
if (req.method() === "POST") sent.push(JSON.parse(req.postData() || "{}"));
|
|
return route.fulfill({ json: memories() });
|
|
}
|
|
if (url.pathname.startsWith("/api/memory")) return route.fulfill({ json: memories() });
|
|
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.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 view = "#view-library";
|
|
const langs = ["en", "zh", "zh-TW", "ja", "de"];
|
|
|
|
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
|
test(engine + ": a memory of several lines keeps them", 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 errors = [];
|
|
t.after(async () => {
|
|
if (errors.length) console.log(errors);
|
|
await browser.close();
|
|
});
|
|
for (const lang of langs) for (const width of [980, 420]) {
|
|
await t.test(`${lang} ${width}`, async () => {
|
|
const ctx = await browser.newContext({ viewport: { width, height: 860 } });
|
|
await ctx.addInitScript(() => { try { localStorage.setItem("magpie.libTab", "memory"); } catch {} });
|
|
const page = await ctx.newPage();
|
|
page.setDefaultTimeout(8000);
|
|
page.setDefaultNavigationTimeout(60000);
|
|
page.on("pageerror", (e) => errors.push(e.message));
|
|
const sent = [];
|
|
await page.route("**/*", server(lang, sent));
|
|
await page.goto("http://magpie.test/");
|
|
await page.locator('button[data-view="library"]').click();
|
|
const row = page.locator(`${view} .lib-mems .lib-mem[data-id="a1"]`);
|
|
await row.waitFor();
|
|
const name = row.locator(".who .name");
|
|
const lineH = await name.evaluate((e) => parseFloat(getComputedStyle(e).lineHeight) || parseFloat(getComputedStyle(e).fontSize) * 1.3);
|
|
|
|
// folded: the first line and an ellipsis, on one line
|
|
assert.equal(await name.textContent(), "Release steps: …");
|
|
assert((await name.evaluate((e) => e.getBoundingClientRect().height)) < lineH * 1.5, "the folded row is more than a line");
|
|
// a suggestion folds the same way
|
|
assert.equal(await page.locator(`${view} .lib-memsugg [data-sugg="skill:a1"] .name`).textContent(), "Release steps: …");
|
|
|
|
// open: every line as written, in the row and in the editor
|
|
await row.evaluate((e) => e.click()); // at 420px the header can sit over it while the page settles
|
|
const ta = page.locator(`${view} textarea[data-lib="mem:a1"]`);
|
|
await ta.waitFor();
|
|
assert.equal(await name.textContent(), STEPS);
|
|
assert.equal(await name.evaluate((e) => getComputedStyle(e).whiteSpace), "pre-wrap");
|
|
assert((await name.evaluate((e) => e.getBoundingClientRect().height)) >= lineH * 3.5, "the open row ran its lines together");
|
|
assert.equal(await ta.inputValue(), STEPS);
|
|
|
|
// a line added in the editor is saved with its break
|
|
await ta.focus();
|
|
await ta.evaluate((e) => e.setSelectionRange(e.value.length, e.value.length));
|
|
await page.keyboard.press("Enter");
|
|
await page.keyboard.type("3. wait for the assets");
|
|
await page.locator(`${view} .lib-memdetail .primary`).click();
|
|
await page.waitForFunction(() => !document.querySelector("#view-library .lib-memdetail"));
|
|
assert.equal(sent.at(-1).text, STEPS + "\n3. wait for the assets");
|
|
assert.deepEqual(errors, []);
|
|
await ctx.close();
|
|
});
|
|
}
|
|
});
|
|
}
|