host: content-addressed SPA cache + declarative SX-htmx relate picker + SIGPIPE hardening
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 37s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 37s
Three composing pieces that make the blog SPA correct and resilient.
Content-addressed module cache (lib/host/static.sx, serve.sh, blog.sx shell,
conformance.sh): index each web-stack .sxbc by the content hash in its head,
serve GET /sx/h/{hash} immutable text/sx, and emit <script data-sx-manifest>
{file->hash} so the WASM client loads modules content-addressed (localStorage +
immutable) instead of path + max-age. serve.sh builds the index at boot;
conformance.sh now loads static.sx before blog.sx (the shell calls
host/static-manifest-json).
Declarative relate picker (lib/host/blog.sx, lib/dream/form.sx): replace the
inline /relate-picker.js blob — which never ran on swapped-in content, so the
candidate list was empty after a boosted nav to /<slug>/edit — with a declarative
SX-htmx form: sx-get relate-options on "load" + debounced "input", innerHTML-swap
the results ul; infinite scroll via a server-emitted "load more" sentinel
(sx-trigger revealed, sx-swap outerHTML) that pages the rest, q preserved via a
new symmetric dr/url-encode. The engine re-binds these triggers on swapped
content, so the picker populates on full load AND boosted SPA nav. Candidate
relate forms get :sx-disable (plain POST->303->reload, their original behavior;
the engine would otherwise boost them and swap the redirect unreliably).
sx-retry "exponential:1000:30000" on the form+sentinel retries a dropped/offline
fetch forever (the cap bounds the interval, not the attempts).
SIGPIPE hardening (hosts/ocaml/bin/sx_server.ml): the native http-listen server
had no SIGPIPE handler, so a client aborting an in-flight fetch (the engine
cancels superseded requests on a debounced filter/fast nav) closed the socket
mid-write and killed the whole process (exit 141). Ignore SIGPIPE so the failed
write becomes a catchable Sys_error the per-connection handler already swallows.
Tests: host conformance 272/272; relate-picker.spec.js 5/5 incl. a boosted-nav
populate regression; spa-check 4/4.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -1,20 +1,32 @@
|
||||
// Browser check for the relate picker (lib/host/blog.sx). Runs against an
|
||||
// ephemeral host server seeded with a host post + 25 candidates by
|
||||
// run-picker-check.sh, which copies this spec into the Playwright env and sets
|
||||
// SX_TEST_URL. Exercises the login redirect, the JS-driven candidate load,
|
||||
// debounced filter, infinite scroll, and click-to-relate.
|
||||
// SX_TEST_URL. The picker is a DECLARATIVE SX-htmx form (no client JS): the form
|
||||
// GETs /<slug>/relate-options on "load" and on a debounced "input", swapping the
|
||||
// results <ul>; a full page carries a "load more" sentinel that pages on reveal.
|
||||
// Exercises the login redirect, the initial populate, debounced filter, infinite
|
||||
// scroll, click-to-relate, AND populate after a boosted SPA nav (the case the old
|
||||
// inline <script> picker silently failed — a script never runs on swapped content).
|
||||
const { test, expect } = require('playwright/test');
|
||||
|
||||
const USER = process.env.SX_ADMIN_USER || 'admin';
|
||||
const PASS = process.env.SX_ADMIN_PASSWORD || 'letmein';
|
||||
const HOST = 'picker-host'; // the post whose edit page we drive
|
||||
const LIMIT = 20; // host/blog--picker-limit
|
||||
const LIMIT = 20; // host/blog--picker-limit (one page)
|
||||
// the Related picker box (the edit page now has one picker per kind)
|
||||
const REL = '.relate-picker[data-kind="related"]';
|
||||
const RELF = `${REL} .rp-filter`;
|
||||
const RELR = `${REL} .rp-results`;
|
||||
const RELROWS = `${RELR} li:not(.rp-more)`; // candidate rows (exclude the sentinel)
|
||||
const MORE = `${RELR} .rp-more`; // the load-more sentinel
|
||||
|
||||
// Navigate to a guarded path; the host redirects to /login?next=…, so fill the
|
||||
// boot-init marks <html data-sx-ready="true"> once the WASM kernel + web stack
|
||||
// load. WASM compile + asset fetches, so allow generous time.
|
||||
async function waitReady(page) {
|
||||
await expect(page.locator('html[data-sx-ready="true"]')).toHaveCount(1, { timeout: 45000 });
|
||||
}
|
||||
|
||||
// Navigate to a GUARDED path; the host redirects to /login?next=…, so fill the
|
||||
// form and we should land back on the original path (exercises the auth flow).
|
||||
async function loginTo(page, path) {
|
||||
await page.goto(path);
|
||||
@@ -25,6 +37,15 @@ async function loginTo(page, path) {
|
||||
await page.waitForURL((u) => !u.pathname.startsWith('/login'));
|
||||
}
|
||||
|
||||
// Log in directly (for reaching PUBLIC pages while authenticated).
|
||||
async function login(page) {
|
||||
await page.goto('/login');
|
||||
await page.fill('input[name="username"]', USER);
|
||||
await page.fill('input[name="password"]', PASS);
|
||||
await page.click('button[type="submit"]');
|
||||
await page.waitForURL((u) => !u.pathname.startsWith('/login'));
|
||||
}
|
||||
|
||||
test.describe('relate picker', () => {
|
||||
test('edit page has Related + Tags pickers and an is-a-tag toggle', async ({ page }) => {
|
||||
await loginTo(page, `/${HOST}/edit`);
|
||||
@@ -34,29 +55,35 @@ test.describe('relate picker', () => {
|
||||
await expect(page.getByRole('button', { name: 'Make this a tag' })).toBeVisible(); // toggle
|
||||
});
|
||||
|
||||
test('picker loads a page of candidates then loads more on scroll', async ({ page }) => {
|
||||
test('picker populates on load and pages via the load-more sentinel', async ({ page }) => {
|
||||
await loginTo(page, `/${HOST}/edit`);
|
||||
const rows = page.locator(`${RELR} li`);
|
||||
// initial JS load fills exactly one page
|
||||
await expect.poll(() => rows.count(), { timeout: 8000 }).toBe(LIMIT);
|
||||
// scroll the results box to the bottom -> infinite scroll fetches the rest
|
||||
await page.locator(RELR).evaluate((el) => el.scrollTo(0, el.scrollHeight));
|
||||
await expect.poll(() => rows.count(), { timeout: 8000 }).toBeGreaterThan(LIMIT);
|
||||
await waitReady(page); // wait for the WASM kernel before the picker's "load" fires
|
||||
const rows = page.locator(RELROWS);
|
||||
// the declarative form's "load" trigger fills the first page (the populate fix)
|
||||
await expect.poll(() => rows.count(), { timeout: 10000 }).toBeGreaterThanOrEqual(LIMIT);
|
||||
// there are more candidates than one page, so reveal the sentinel (if it hasn't
|
||||
// already auto-revealed) to page in the rest — robust to the exact total and to
|
||||
// the sentinel starting above or below the fold.
|
||||
const more = page.locator(MORE);
|
||||
if (await more.count()) await more.first().scrollIntoViewIfNeeded();
|
||||
await expect.poll(() => rows.count(), { timeout: 10000 }).toBeGreaterThan(LIMIT); // paged in more
|
||||
});
|
||||
|
||||
test('typing in the filter narrows the candidates', async ({ page }) => {
|
||||
await loginTo(page, `/${HOST}/edit`);
|
||||
await expect.poll(() => page.locator(`${RELR} li`).count(), { timeout: 8000 }).toBeGreaterThan(0);
|
||||
await waitReady(page);
|
||||
await expect.poll(() => page.locator(RELROWS).count(), { timeout: 10000 }).toBeGreaterThan(0);
|
||||
await page.fill(RELF, 'Item 13');
|
||||
await expect.poll(() => page.locator(`${RELR} li`).count(), { timeout: 8000 }).toBe(1);
|
||||
await expect.poll(() => page.locator(RELROWS).count(), { timeout: 10000 }).toBe(1);
|
||||
await expect(page.locator(RELR)).toContainText('Picker Item 13');
|
||||
});
|
||||
|
||||
test('clicking a candidate relates it (and it shows on the post page)', async ({ page }) => {
|
||||
await loginTo(page, `/${HOST}/edit`);
|
||||
await waitReady(page);
|
||||
await page.fill(RELF, 'Item 07');
|
||||
await expect.poll(() => page.locator(`${RELR} li`).count(), { timeout: 8000 }).toBe(1);
|
||||
await page.locator(`${RELR} button`).first().click();
|
||||
await expect.poll(() => page.locator(RELROWS).count(), { timeout: 10000 }).toBe(1);
|
||||
await page.locator(`${RELROWS} button`).first().click();
|
||||
// form POST -> 303 back to the edit page; the related list now links the slug
|
||||
await expect(page).toHaveURL(new RegExp(`/${HOST}/edit`));
|
||||
await expect(page.locator('a[href="/picker-item-07/"]')).toHaveCount(1);
|
||||
@@ -65,4 +92,21 @@ test.describe('relate picker', () => {
|
||||
await expect(page.getByRole('heading', { name: 'Related posts' })).toBeVisible();
|
||||
await expect(page.locator('body')).toContainText('Picker Item 07');
|
||||
});
|
||||
|
||||
test('picker populates after a boosted SPA nav to the edit page', async ({ page }) => {
|
||||
// Reach the edit page by CLICKING its link (a boosted SPA nav), not page.goto.
|
||||
// The old inline <script> picker never ran on swapped-in content, so the list
|
||||
// stayed empty here. The declarative form's "load" trigger is re-bound by the
|
||||
// engine on swap, so it populates — that's the regression this guards.
|
||||
await login(page);
|
||||
await page.goto(`/${HOST}/`); // public post page, logged in
|
||||
await waitReady(page);
|
||||
await page.evaluate(() => { window.__noReload = true; });
|
||||
await page.locator(`a[href="/${HOST}/edit"]`).first().click();
|
||||
await page.waitForURL((u) => u.pathname === `/${HOST}/edit`, { timeout: 15000 });
|
||||
expect(await page.evaluate(() => window.__noReload)).toBe(true); // it was a SPA nav, no full reload
|
||||
// the picker, brought in by the swap, loaded its first page of candidates
|
||||
await expect.poll(() => page.locator(RELROWS).count(), { timeout: 12000 }).toBeGreaterThanOrEqual(1);
|
||||
await expect(page.locator(RELR)).toContainText('Picker Item');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user