Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 43s
Clicking a blog link now fragment-swaps #content with URL push + working back
button, no full reload — the SX-htmx engine driving the same OCaml kernel the
server runs. Six bugs in the source-load + boost path, found by bisecting in
chromium, all fixed:
1. Import double-apply (sx_server.ml x2, sx_browser.ml): the import suspension
handlers computed `key = library_name_key lib_spec` then called
`library_loaded_p key` — but library_loaded_p applies library_name_key
itself, so it ran sx_to_list on a string and crashed ("Expected list, got
string"). Only unloaded libs suspend, so it only bit lazy imports. Pass the
spec, not the key.
2. Unloaded-import crash (spec/evaluator.sx + sx_ref.ml library_exports): an
import of a not-yet-loaded library returned nil exports, and bind-import-set
did (keys nil) -> crash. Return an empty dict so the import is a graceful
no-op (lazy symbol resolution covers real usage).
3. value_to_js missing Integer (sx_browser.ml): integers passed to host methods
were mishandled, so dom-query-all's (host-call node-list "item" i) ignored i
and returned node 0 for every index — every element aliased the first, so
only one link ever boosted. Add the Integer -> JS number case.
4. browser-same-origin? rejected relative URLs (browser.sx x2): it only did
(starts-with? url origin), so "/alpha/" was treated as cross-origin and
should-boost-link? refused every relative link. Accept scheme-less,
non-protocol-relative URLs.
5. dom-query-in undefined (orchestration.sx x2): the swap path called a function
that exists nowhere; it's just dom-query with a container arg.
6. Lazy-deps never loaded under source fallback (sx-platform.js): lazy symbol
resolution only fires on the VM GLOBAL_GET path, but source-loaded swap
callbacks run on the CEK and raise instead of lazy-loading, so the post-swap
hs-boot-subtree!/htmx-boot-subtree! were undefined and aborted URL push.
Preload the manifest's lazy-deps.
Verified: native host conformance 271/271; lib/host/playwright/spa-check 4/4
(boot, boost, fragment swap + URL push, back button) in real chromium against an
ephemeral durable host server.
68 lines
3.1 KiB
JavaScript
68 lines
3.1 KiB
JavaScript
// Browser check for the blog SPA (lib/host/blog.sx + lib/host/static.sx). Runs
|
|
// against an ephemeral host server seeded with a couple of posts by
|
|
// run-spa-check.sh, which copies this spec into the Playwright env and sets
|
|
// SX_TEST_URL. Verifies the WASM OCaml kernel boots in the browser, the SX-htmx
|
|
// engine activates sx-boost on #content's links, and clicking a link does a
|
|
// fragment swap (no full page reload) with history — i.e. it's a real SPA.
|
|
const { test, expect } = require('playwright/test');
|
|
|
|
// boot-init sets data-sx-ready="true" on <html> once the WASM kernel + web stack
|
|
// have loaded and the page has been processed. WASM compile + ~25 asset fetches,
|
|
// so allow generous time.
|
|
async function waitReady(page) {
|
|
await expect(page.locator('html[data-sx-ready="true"]')).toHaveCount(1, { timeout: 45000 });
|
|
}
|
|
|
|
// a post link in the listing (trailing slash); skip /new, /login, /tags.
|
|
const POSTLINK = '#content a[href$="/"]';
|
|
|
|
test.describe('blog SPA', () => {
|
|
test('WASM kernel boots and marks the document ready', async ({ page }) => {
|
|
const errors = [];
|
|
page.on('console', (m) => { if (m.type() === 'error') errors.push(m.text()); });
|
|
page.on('pageerror', (e) => errors.push(String(e)));
|
|
await page.goto('/');
|
|
await waitReady(page);
|
|
// the shell shipped the WASM loaders
|
|
expect(await page.locator('script[src*="sx_browser.bc.wasm.js"]').count()).toBe(1);
|
|
expect(await page.locator('script[src*="sx-platform.js"]').count()).toBe(1);
|
|
// no boot-time JS errors
|
|
expect(errors, errors.join('\n')).toEqual([]);
|
|
});
|
|
|
|
test('links inside #content get boosted', async ({ page }) => {
|
|
await page.goto('/');
|
|
await waitReady(page);
|
|
// the engine marks a boosted link with the _sxBoundboost JS property
|
|
await expect
|
|
.poll(() => page.locator(POSTLINK).first().evaluate((a) => !!a._sxBoundboost), { timeout: 15000 })
|
|
.toBe(true);
|
|
});
|
|
|
|
test('clicking a link does a fragment swap — no full reload, URL updates', async ({ page }) => {
|
|
await page.goto('/');
|
|
await waitReady(page);
|
|
// sentinel survives ONLY if there is no full-page reload
|
|
await page.evaluate(() => { window.__noReload = true; });
|
|
const link = page.locator(POSTLINK).first();
|
|
const href = await link.getAttribute('href');
|
|
await link.click();
|
|
await page.waitForURL((u) => u.pathname === href, { timeout: 15000 });
|
|
expect(await page.evaluate(() => window.__noReload)).toBe(true); // no reload
|
|
// content was swapped into #content (a post page carries the post footer)
|
|
await expect(page.locator('#content')).toContainText(/all posts/i, { timeout: 15000 });
|
|
});
|
|
|
|
test('back button restores the listing', async ({ page }) => {
|
|
await page.goto('/');
|
|
await waitReady(page);
|
|
const link = page.locator(POSTLINK).first();
|
|
const href = await link.getAttribute('href');
|
|
await link.click();
|
|
await page.waitForURL((u) => u.pathname === href, { timeout: 15000 });
|
|
await page.goBack();
|
|
await page.waitForURL((u) => u.pathname === '/', { timeout: 15000 });
|
|
await expect(page.locator('#content h1')).toContainText('Posts');
|
|
});
|
|
});
|