Files
loki/scripts/preview/test-knowledge-map.mjs
Cato 964777b7ac Make Memory explain projects, next actions and the research behind them (#1740)
* feat: connect project purpose, next actions and research in Memory

* test: resolve superseding essays through the real dynamic route
2026-11-30 05:51:51 +01:00

132 lines
6.0 KiB
JavaScript
Raw Permalink 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.
// Real shell and component: understand -> inspect -> continue -> hand off.
import assert from "node:assert/strict";
import { readFile } from "node:fs/promises";
import { resolve } from "node:path";
import { pathToFileURL } from "node:url";
import { chromium } from "playwright";
const browser = await chromium.launch();
try {
for (const width of [320, 390, 1280]) {
const page = await browser.newPage({ viewport: { width, height: 900 } });
const errors = [];
page.on("pageerror", (e) => errors.push(String(e)));
await page.goto(pathToFileURL(resolve(".tmp/knowledge-map-preview/index-dark.html")).href);
const workspace = page.getByRole("region", { name: "Connected workspace" });
await workspace.getByRole("heading", { name: "Your ecosystem, explained." }).waitFor();
assert.equal(
await workspace.getByRole("link", { name: /Why we’re building this/ }).getAttribute("href"),
"/thoughts/a-connected-workspace-that-earns-its-place",
);
assert.equal(
await workspace.getByRole("link", { name: /What happens next/ }).getAttribute("href"),
"/roadmap#now",
);
assert.equal(
await workspace.getByText("@example/search", { exact: true }).count(),
0,
"technical component names do not lead the overview",
);
await workspace.getByRole("button", { name: "Explore Atlas", exact: true }).focus();
await page.keyboard.press("Enter");
const detail = page.getByRole("group", { name: "Atlas context" });
await detail.waitFor();
assert((await detail.textContent()).includes("Done when:"));
assert((await detail.textContent()).includes("Review the first guided project walkthrough"));
assert.equal(
await detail.getByRole("link", { name: /Open project workspace/ }).getAttribute("href"),
"/projects/11111111-1111-4111-8111-111111111111",
);
const [handoff] = await Promise.all([
page.waitForEvent("download"),
detail.getByRole("button", { name: "Download brief", exact: true }).click(),
]);
const brief = await readFile(await handoff.path(), "utf8");
assert(brief.includes("Atlas — project handoff"));
assert(brief.includes("Acceptance:"));
assert(brief.includes("not independently verified"));
assert(!brief.includes("Customer research"));
await detail.getByRole("heading", { name: "Recorded project relationships" }).waitFor();
await detail
.getByRole("button", { name: /Canvas/ })
.first()
.click();
await page
.getByRole("group", { name: "Canvas context" })
.getByRole("button", { name: "Back to Atlas" })
.click();
await detail.getByRole("button", { name: "Ecosystem overview" }).click();
await workspace.getByRole("textbox", { name: "Find a project" }).fill("Canvs");
assert.equal(
await workspace.locator(".ui-memory-project").count(),
1,
"SearchKit handles typos",
);
await workspace.getByRole("textbox", { name: "Find a project" }).fill("unfindable");
await workspace.getByRole("button", { name: "Clear search", exact: true }).click();
await workspace.getByRole("radio", { name: "Technical", exact: true }).click();
await workspace.getByRole("button", { name: /@example\/search/ }).click();
await page.getByRole("heading", { name: "Projects using this component" }).waitFor();
await page.getByRole("button", { name: "Ecosystem overview" }).click();
await workspace.getByRole("button", { name: "Export for agents" }).click();
assert(
(await workspace.locator(".ui-memory-export").textContent()).includes(
"private remembered people",
),
);
const [snapshot] = await Promise.all([
page.waitForEvent("download"),
workspace.getByRole("button", { name: "Download private JSON" }).click(),
]);
const exported = JSON.parse(await readFile(await snapshot.path(), "utf8"));
assert.equal(exported.visibility, "private");
assert.equal(exported.nodes.length, 7);
assert.equal(exported.programme.tracks.length, 2);
await workspace.getByRole("button", { name: "Cancel", exact: true }).click();
assert.equal(
await page.evaluate(() => document.documentElement.scrollWidth > innerWidth),
false,
);
assert.deepEqual(errors, []);
console.log(
`${width}px: purpose, rationale, roadmap, next action, project traversal/back, search and private agent handoff passed in the real shell`,
);
await page.close();
}
for (const width of [320, 1280]) {
const page = await browser.newPage({ viewport: { width, height: 900 } });
await page.goto(
pathToFileURL(resolve(".tmp/knowledge-map-preview/index-dark.html")).href + "?busy=1",
);
await page.getByRole("radio", { name: "All projects", exact: true }).click();
assert.equal(
await page.locator(".ui-memory-project").count(),
12,
"500 records do not become 500 cards",
);
await page.getByRole("button", { name: "Show 12 more", exact: true }).click();
assert.equal(await page.locator(".ui-memory-project").count(), 24);
await page.getByRole("textbox", { name: "Find a project" }).fill("Atlas");
await page.getByRole("button", { name: "Explore Atlas", exact: true }).click();
const detail = page.getByRole("group", { name: "Atlas context" });
await detail.waitFor();
assert.equal(
await page.evaluate(() => document.documentElement.scrollWidth > innerWidth),
false,
);
const clipped = await detail.locator(".ui-listrow").evaluateAll(
(rows) =>
rows.filter((node) => {
const box = node.getBoundingClientRect();
const text = node.querySelector(".ui-listrow-secondary")?.getBoundingClientRect();
return text && text.bottom > box.bottom + 1;
}).length,
);
assert.equal(clipped, 0, "relationship rows retain their height");
await page.screenshot({ path: `.tmp/knowledge-map-preview/workspace-detail-${width}.png` });
console.log(`${width}px: 500-node snapshot stays paged and relationships remain readable`);
await page.close();
}
} finally {
await browser.close();
}