Several libraries on the server: one directory, store, notice stream, link index, pending links, reviewer and jobs each; /api/libraries and /api/l/<id>/…; the page holds one library, named by its address, and switches by a page load
The old single-library layout is not opened (the server says to run the migration, which comes next); the per-document migration, /recover and the old replicas check are gone. A server lock keeps two servers off one data directory. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014yB6q4BHMwptTX3YFtkRab
This commit is contained in:
1 parent
045a8459da
commit
79aa85e883
22 files changed
+1468
-759
No files matched your search
+18
-7
@@ -42,9 +42,20 @@ export async function nodeAt(page: Page, ...path: string[]): Promise<string> {
|
||||
return find(s, ...path);
|
||||
}
|
||||
|
||||
/** Go to the address of the section at these titles from the library root (none: the library, `/`), and wait for the page. */
|
||||
/** The id of the library the tests share: the server's first (what the unprefixed routes act on). */
|
||||
export async function libraryId(page: Page): Promise<string> {
|
||||
return (await (await page.request.get("/api/state")).json()).library;
|
||||
}
|
||||
|
||||
/** An address in the shared library: `/l/<id>` for its root, then a path within it (`/n/<node id>`, `/w/en/Octopus`). */
|
||||
export async function libraryPath(page: Page, part = "/"): Promise<string> {
|
||||
const base = `/l/${await libraryId(page)}`;
|
||||
return part === "/" ? base : base + part;
|
||||
}
|
||||
|
||||
/** Go to the address of the section at these titles from the library root (none: the library, `/l/<id>`), and wait for the page. */
|
||||
export async function openAt(page: Page, ...path: string[]) {
|
||||
await page.goto(path.length ? `/n/${encodeURIComponent(await nodeAt(page, ...path))}` : "/");
|
||||
await page.goto(await libraryPath(page, path.length ? `/n/${encodeURIComponent(await nodeAt(page, ...path))}` : "/"));
|
||||
await page.waitForSelector("article");
|
||||
}
|
||||
|
||||
@@ -61,12 +72,12 @@ export async function openPage(page: Page, ...path: string[]) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Go somewhere: an address as it is (`/`, `/w/en/Octopus`), or a top-level section by its title,
|
||||
* opened as the page (openPage). Does not wait for the page.
|
||||
* Go somewhere: an address in the shared library (`/` its root, `/w/en/Octopus`), or a top-level
|
||||
* section by its title, opened as the page (openPage). Does not wait for the page.
|
||||
*/
|
||||
export async function visit(page: Page, where: string) {
|
||||
if (where.startsWith("/")) return void (await page.goto(where));
|
||||
await page.goto(`/n/${encodeURIComponent(await nodeAt(page, where))}`);
|
||||
if (where.startsWith("/")) return void (await page.goto(await libraryPath(page, where)));
|
||||
await page.goto(await libraryPath(page, `/n/${encodeURIComponent(await nodeAt(page, where))}`));
|
||||
await page.waitForFunction(() => (globalThis as any).__ie?.ready);
|
||||
await hoistHere(page);
|
||||
}
|
||||
@@ -77,7 +88,7 @@ export async function visit(page: Page, where: string) {
|
||||
* has the focus.
|
||||
*/
|
||||
export async function addTop(page: Page, title: string, text: string) {
|
||||
await page.goto("/");
|
||||
await page.goto(await libraryPath(page));
|
||||
await page.waitForFunction(() => (globalThis as any).__ie?.ready);
|
||||
await page.keyboard.press("a");
|
||||
await page.keyboard.type(title);
|
||||
|
||||
@@ -0,0 +1,110 @@
|
||||
/**
|
||||
* Several libraries, from the page: every address names its library (`/l/<id>`), `/` opens the one
|
||||
* last used, :/library lists, makes and opens them (a page load), a new library starts with its root
|
||||
* alone, nothing of one library is found from another (the jump box, nearby and Related, a node's
|
||||
* address), and each library keeps its own view. The panel that lists them is step 4's; these
|
||||
* tests use the command and the API. They make their own libraries and delete them at the end: the
|
||||
* other specs share the first.
|
||||
*/
|
||||
import { expect, test, type Page } from "@playwright/test";
|
||||
import { command, keys, libraryId, settle, state } from "./helpers";
|
||||
|
||||
const ready = (page: Page) => page.waitForFunction(() => (globalThis as any).__ie?.ready);
|
||||
const status = (page: Page) => page.locator(".status .message");
|
||||
const lib = (page: Page) => state(page, (s) => s.library as string);
|
||||
|
||||
test.describe.configure({ mode: "serial" });
|
||||
test.afterEach(({ page }) => settle(page));
|
||||
|
||||
test("a new library starts with its root alone, has an address of its own, and finds nothing of the first", async ({ page }) => {
|
||||
const first = await libraryId(page);
|
||||
await page.goto("/");
|
||||
await ready(page);
|
||||
// `/` opens the first library in a browser that has used none, at its own address.
|
||||
expect(await lib(page)).toBe(first);
|
||||
await expect(page).toHaveURL(new RegExp(`/l/${first}$`));
|
||||
|
||||
await command(page, "/library new Work notes");
|
||||
await page.waitForURL((u) => /^\/l\/[0-9a-z]+$/.test(u.pathname) && !u.pathname.endsWith(first));
|
||||
await ready(page);
|
||||
const work = await lib(page);
|
||||
expect(work).not.toBe(first);
|
||||
await expect(page.locator(".top h1")).toHaveText("Work notes");
|
||||
await expect(page.locator(".docbar .lib-name")).toHaveText("Work notes");
|
||||
// Its root alone: no seed, no starter trees.
|
||||
expect(await state(page, (s) => s.snap.nodes[s.snap.root].children.length)).toBe(0);
|
||||
|
||||
// A section with the same title as one in the first library, and text that mentions the first's titles.
|
||||
await keys(page, "a");
|
||||
await page.keyboard.type("Fixed points");
|
||||
await page.keyboard.press("Enter");
|
||||
await page.waitForFunction(() => Object.values((globalThis as any).__ie.snap.nodes).some((n: any) => n.title === "Fixed points"));
|
||||
await page.waitForFunction(() => (globalThis as any).__ie.synced());
|
||||
|
||||
// The jump box offers this library's nodes only.
|
||||
await keys(page, "/");
|
||||
await page.keyboard.type("Amphidromes");
|
||||
await expect(page.locator(".jump li[data-hit]")).toHaveCount(0);
|
||||
await page.keyboard.press("Escape");
|
||||
await keys(page, "/");
|
||||
await page.keyboard.type("Fixed points");
|
||||
await expect(page.locator(".jump li[data-hit]")).toHaveCount(1);
|
||||
await page.keyboard.press("Escape");
|
||||
|
||||
// The server's routes for it hold only it.
|
||||
const tree = await (await page.request.get(`/api/l/${work}/tree`)).json();
|
||||
expect(Object.values(tree.nodes).map((n: any) => n.title).sort()).toEqual(["Fixed points", "Work notes"]);
|
||||
const firstTree = await (await page.request.get(`/api/l/${first}/tree`)).json();
|
||||
expect(Object.values(firstTree.nodes).some((n: any) => n.title === "Work notes")).toBe(false);
|
||||
// Nearby and Related never come from the first library, though it has a "Fixed points" too.
|
||||
const mine = Object.values(tree.nodes).find((n: any) => n.title === "Fixed points") as { id: string };
|
||||
const nearby = await (await page.request.get(`/api/l/${work}/links/nearby?node=${encodeURIComponent(mine.id)}`)).json();
|
||||
for (const n of nearby.nearby) expect(tree.nodes[n.handle]).toBeTruthy();
|
||||
const related = await (await page.request.get(`/api/l/${work}/links/related?node=${encodeURIComponent(mine.id)}`)).json();
|
||||
for (const r of related.related) expect(tree.nodes[r.node]).toBeTruthy();
|
||||
|
||||
// A node of the first library, at this library's address, is not found here.
|
||||
const amph = Object.values(firstTree.nodes).find((n: any) => n.title === "Amphidromes") as { id: string };
|
||||
await page.goto(`/l/${work}/n/${encodeURIComponent(amph.id)}`);
|
||||
await ready(page);
|
||||
await expect(page.locator(".top h1")).toHaveText("Work notes");
|
||||
await expect(status(page)).toContainText(amph.id);
|
||||
|
||||
// `/` now opens the library last used here.
|
||||
await page.goto("/");
|
||||
await ready(page);
|
||||
expect(await lib(page)).toBe(work);
|
||||
// :/library with a name opens another, by a page load; each keeps its own view.
|
||||
await command(page, "/library Library");
|
||||
await page.waitForURL(new RegExp(`/l/${first}`));
|
||||
await ready(page);
|
||||
expect(await lib(page)).toBe(first);
|
||||
await expect(page.locator(".top h1")).toHaveText("Library");
|
||||
const keysNow = await page.evaluate(() => Object.keys(localStorage).filter((k) => k.startsWith("ie:view:")).sort());
|
||||
expect(keysNow).toEqual(expect.arrayContaining([`ie:view:${first}:main`, `ie:view:${work}:main`]));
|
||||
});
|
||||
|
||||
test("rename and delete over the API; an unknown library's address goes to the first; the last library cannot be deleted", async ({ page }) => {
|
||||
const first = await libraryId(page);
|
||||
const listed = (await (await page.request.get("/api/libraries")).json()).libraries as { id: string; title: string }[];
|
||||
const work = listed.find((l) => l.title === "Work notes")!;
|
||||
expect(work).toBeTruthy();
|
||||
const renamed = await page.request.patch(`/api/libraries/${work.id}`, { data: { title: "Work, renamed" } });
|
||||
expect(renamed.ok()).toBe(true);
|
||||
await page.goto(`/l/${work.id}`);
|
||||
await ready(page);
|
||||
await expect(page.locator(".top h1")).toHaveText("Work, renamed");
|
||||
// The page learns of its library's deletion and stops sending.
|
||||
const gone = await page.request.delete(`/api/libraries/${work.id}`);
|
||||
expect(gone.ok()).toBe(true);
|
||||
expect((await gone.json()).movedTo).toContain(".deleted");
|
||||
await expect(status(page)).toContainText("This library has been deleted");
|
||||
// Its address now goes to the first library, saying so.
|
||||
await page.goto(`/l/${work.id}`);
|
||||
await page.waitForURL(new RegExp(`/l/${first}$`));
|
||||
await ready(page);
|
||||
await expect(status(page)).toContainText(`There is no library ${work.id} here`);
|
||||
// The first, now alone, cannot be deleted.
|
||||
const last = await page.request.delete(`/api/libraries/${first}`);
|
||||
expect(last.status()).toBe(409);
|
||||
});
|
||||
+1
-1
@@ -79,7 +79,7 @@ test("hoisting makes one node the whole page; Esc at its top steps out to its pa
|
||||
await expect(page).toHaveURL(/\/n\/[^/]+$/);
|
||||
// On the root itself, the address is the library's.
|
||||
await page.keyboard.press("O");
|
||||
await expect(page).toHaveURL(/\/$/);
|
||||
await expect(page).toHaveURL(/\/l\/[0-9a-z]+$/);
|
||||
});
|
||||
|
||||
test("with speculation on, the focused sentence is already being written when it is asked for", async ({ page }) => {
|
||||
|
||||
+2
-2
@@ -68,10 +68,10 @@ test("the library root is the first page and a node like any other: its sections
|
||||
const first = await state(page, (s) => s.focus.node);
|
||||
await expect(page).toHaveURL(new RegExp(`/n/${encodeURIComponent(first)}$`));
|
||||
await expect(page).toHaveTitle("Infinispand");
|
||||
// Back up onto the root itself: its address is /, and it is the node the keys act on.
|
||||
// Back up onto the root itself: its address is the library's, /l/<id>, and it is the node the keys act on.
|
||||
await keys(page, "h k");
|
||||
expect(await state(page, (s) => s.focus.node === s.snap.root)).toBe(true);
|
||||
await expect(page).toHaveURL(/\/$/);
|
||||
await expect(page).toHaveURL(/\/l\/[0-9a-z]+$/);
|
||||
await expect(page).toHaveTitle("Library");
|
||||
await keys(page, "D");
|
||||
await expect(status(page)).toHaveText("The library itself cannot be deleted.");
|
||||
|
||||
Reference in new issue
Block a user