A url link now opens in the app instead of the browser. The server fetches the page (robots.txt honoured, public addresses only, size and time caps), keeps a snapshot on disk until it is reloaded, and cuts it into a lead and sections: by its headings, else by pseudo-headings, else in chunks, or by a model when asked (s), within a daily budget. The pane has its own amber ground, the author and date in its head when the page gives them, and the source in its foot. W opens the original, R reads it again. See docs/pages.md. Pictures and videos are kept, in web pages and in Wikipedia articles: pictures through the server (only addresses seen in a page that was read), videos as a still that loads the player on a click. A section that is only a link (a target, no text, no sections) opens as its article at once, and L opens a target to the right of the node's own pane, never under it. Article text is sized to read like the reader's own. Panes: a pane that already has all its column can give beside the others' tabs no longer peeks over them on hover, and the curves of tabs under a peeking pane are no longer drawn over it. The keypress timing test judges each of its two passes on its own, so a stall from outside the app does not fail it. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014yB6q4BHMwptTX3YFtkRab
112 lines
6.2 KiB
TypeScript
112 lines
6.2 KiB
TypeScript
/**
|
|
* /research with the mock model: its fake web search and fetch (no network) are shown step by step
|
|
* above the status line, the section it writes carries links to the pages it read, those open as
|
|
* the column's web page (W opens the original in a new tab), and Esc stops a run without keeping
|
|
* anything it did.
|
|
*/
|
|
import { expect, test, type Page } from "@playwright/test";
|
|
import { command, idle, jump, keys, openPage, settle, state } from "./helpers";
|
|
|
|
async function open(page: Page) {
|
|
// Record what would open in a new tab instead of opening it.
|
|
await page.addInitScript(() => {
|
|
(globalThis as any).__opened = [];
|
|
window.open = ((url: string) => ((globalThis as any).__opened.push(String(url)), null)) as typeof window.open;
|
|
});
|
|
await openPage(page, "Explicata");
|
|
}
|
|
|
|
test.describe.configure({ mode: "serial" });
|
|
|
|
test.afterEach(({ page }) => settle(page));
|
|
|
|
test("/research shows its searches and pages, writes a section, and links its claim to a page it read", async ({ page }) => {
|
|
await open(page);
|
|
expect(await state(page, (s) => s.web)).toEqual({ on: true, searches: 5, fetches: 5 });
|
|
await jump(page, "The tree underneath");
|
|
await command(page, "/research how tides work");
|
|
|
|
const panel = page.locator(".agent-panel");
|
|
await expect(panel).toBeVisible();
|
|
await expect(panel).toHaveAttribute("data-agent", "running");
|
|
await expect(panel.locator(".agent-head")).toContainText("researching on the web");
|
|
// Esc stops it, and says so as a button that presses Esc.
|
|
await expect(panel.locator('.agent-head .key[data-key="Escape"]')).toHaveCount(1);
|
|
await expect(panel.locator(".agent-steps")).toContainText("searched “how tides work”: 3 results");
|
|
await expect(panel.locator(".agent-steps")).toContainText("read “How tides work” · example.org");
|
|
await expect(panel).toHaveAttribute("data-agent", "done");
|
|
// The edits are steps too, after the research.
|
|
const steps = await panel.locator(".agent-steps li").allTextContents();
|
|
const searched = steps.findIndex((s) => s.startsWith("searched"));
|
|
const edited = steps.findIndex((s) => s.startsWith("added “On how tides work”"));
|
|
expect(searched).toBeGreaterThanOrEqual(0);
|
|
expect(edited).toBeGreaterThan(searched);
|
|
expect(steps).toContain("linked “pulled by the Moon” to How tides work (example.org)");
|
|
// The summary lists the sources it linked.
|
|
await expect(panel.locator(".agent-summary")).toContainText("mock agent");
|
|
await expect(panel.locator(".agent-sources a")).toHaveText("How tides work");
|
|
await expect(panel.locator(".agent-sources a")).toHaveAttribute("href", "https://example.org/research/tides");
|
|
await expect(page.locator(".status .message")).toContainText("sources: How tides work (example.org)");
|
|
await idle(page);
|
|
|
|
// The section is in the library, with the phrase linked to the page: a web link, marked ↗.
|
|
const link = await state(page, (s) => {
|
|
const snap = s.snap;
|
|
const sec = Object.values(snap.nodes).find((n: any) => n.title === "On how tides work") as any;
|
|
const note = sec && sec.children.map((c: string) => snap.nodes[c]).find((c: any) => c.kind === "note" && c.ref);
|
|
return note ? { ref: note.ref, words: note.anchors[0].text, body: note.body, by: snap.nodes[sec.id].by } : null;
|
|
});
|
|
expect(link).toEqual({ ref: { kind: "url", url: "https://example.org/research/tides", title: "How tides work" }, words: "pulled by the Moon", body: "", by: "llm" });
|
|
|
|
// Esc puts the finished panel away.
|
|
await keys(page, "Escape");
|
|
await expect(panel).toHaveCount(0);
|
|
|
|
// The link opens: go to the section, Tab to the linked words, Enter (twice in the column: a
|
|
// preview first) opens the page as the column's web page (the mock web has no such page, so it
|
|
// says why and offers the original); W opens the original in a new tab.
|
|
await jump(page, "On how tides work");
|
|
await keys(page, "l");
|
|
const sec = page.locator(".node.open", { hasText: "pulled by the Moon" }).last();
|
|
await expect(sec.locator(".lmark.l-url")).toHaveText("↗");
|
|
await keys(page, "Tab");
|
|
expect(await state(page, (s) => s.snap.nodes[s.focus.node].body.slice(s.focus.range?.[0], s.focus.range?.[1]))).toBe("pulled by the Moon");
|
|
for (let i = 0; i < 2 && !(await page.locator(".wiki-page.web").count()); i++) await keys(page, "Enter");
|
|
const web = page.locator(".wiki-page.web");
|
|
await expect(web.locator("a[data-original]")).toHaveAttribute("href", "https://example.org/research/tides");
|
|
expect(new URL(page.url()).pathname.endsWith(`/u/${encodeURIComponent("https://example.org/research/tides")}`)).toBe(true);
|
|
expect(await page.evaluate(() => (globalThis as any).__opened)).toEqual([]);
|
|
await keys(page, "W");
|
|
expect(await page.evaluate(() => (globalThis as any).__opened)).toEqual(["https://example.org/research/tides"]);
|
|
await keys(page, "h");
|
|
await expect(web).toHaveCount(0);
|
|
});
|
|
|
|
test("an ordinary request that asks to look something up uses the web too", async ({ page }) => {
|
|
await open(page);
|
|
await jump(page, "The tree underneath");
|
|
await command(page, "look up neap tides");
|
|
await expect(page.locator(".agent-panel .agent-steps")).toContainText("searched “look up neap tides”");
|
|
await expect(page.locator(".agent-panel")).toHaveAttribute("data-agent", "done");
|
|
await idle(page);
|
|
await keys(page, "Escape");
|
|
});
|
|
|
|
test("Esc stops a research run, and nothing it did is kept", async ({ page }) => {
|
|
await open(page);
|
|
await jump(page, "The tree underneath");
|
|
const before = await state(page, (s) => Object.keys(s.snap.nodes).length);
|
|
await command(page, "/research stop me");
|
|
const panel = page.locator(".agent-panel");
|
|
await expect(panel.locator(".agent-steps")).toContainText("searched “stop me”");
|
|
await keys(page, "Escape");
|
|
await expect(page.locator(".status .message")).toContainText("stopped; nothing it did was kept");
|
|
await expect(panel).toHaveAttribute("data-agent", "done");
|
|
await expect(panel.locator(".agent-summary")).toHaveText("Stopped. Nothing it did was kept.");
|
|
await idle(page);
|
|
expect(await state(page, (s) => Object.keys(s.snap.nodes).length)).toBe(before);
|
|
expect(await state(page, (s) => Object.values(s.snap.nodes).some((n: any) => n.title === "On stop me"))).toBe(false);
|
|
await keys(page, "Escape");
|
|
await expect(panel).toHaveCount(0);
|
|
});
|