Files
rose-ash/tests/playwright/reactive-nav.spec.js
giles d81a518732 Fix JIT compiler, CSSX browser support, double-fetch, SPA layout
JIT compiler:
- Fix jit_compile_lambda: resolve `compile` via symbol lookup in env
  instead of embedding VmClosure in AST (CEK dispatches differently)
- Register eval-defcomp/eval-defisland/eval-defmacro runtime helpers
  in browser kernel for bytecoded defcomp forms
- Disable broken .sxbc.json path (missing arity in nested code blocks),
  use .sxbc text format only
- Mark JIT-failed closures as sentinel to stop retrying

CSSX in browser:
- Add cssx.sx symlink + cssx.sxbc to browser web stack
- Add flush-cssx! to orchestration.sx post-swap for SPA nav
- Add cssx.sx to compile-modules.js and mcp_tree.ml bytecode lists

SPA navigation:
- Fix double-fetch: check e.defaultPrevented in click delegation
  (bind-event already handled the click)
- Fix layout destruction: change nav links from outerHTML to innerHTML
  swap (outerHTML destroyed #main-panel when response lacked it)
- Guard JS popstate handler when SX engine is booted
- Rename sx-platform.js → sx-platform-2.js to bust immutable cache

Playwright tests:
- Add trackErrors() helper to all test specs
- Add SPA DOM comparison test (SPA nav vs fresh load)
- Add single-fetch + no-duplicate-elements test
- Improve MCP tool output: show failure details and error messages

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-30 20:48:43 +00:00

113 lines
4.4 KiB
JavaScript

// @ts-check
const { test, expect } = require('playwright/test');
const { BASE_URL, waitForSxReady, trackErrors } = require('./helpers');
test.describe('Reactive Island Navigation', () => {
let t;
test.beforeEach(({ page }) => { t = trackErrors(page); });
test.afterEach(() => { expect(t.errors()).toEqual([]); });
test('counter island works on direct load', async ({ page }) => {
await page.goto(BASE_URL + '/sx/(geography.(reactive.(examples.counter)))', { waitUntil: 'domcontentloaded' });
await waitForSxReady(page);
const island = page.locator('[data-sx-island*="counter"]');
await expect(island).toBeVisible({ timeout: 10000 });
const buttons = island.locator('button');
await expect(buttons).toHaveCount(2, { timeout: 5000 });
const textBefore = await island.textContent();
await buttons.last().click();
await page.waitForTimeout(300);
expect(await island.textContent()).not.toBe(textBefore);
});
test('temperature island works on direct load', async ({ page }) => {
await page.goto(BASE_URL + '/sx/(geography.(reactive.(examples.temperature)))', { waitUntil: 'domcontentloaded' });
await waitForSxReady(page);
const island = page.locator('[data-sx-island*="temperature"]');
await expect(island).toBeVisible({ timeout: 10000 });
const inputs = island.locator('input');
const buttons = island.locator('button');
const interactive = (await inputs.count()) + (await buttons.count());
expect(interactive).toBeGreaterThan(0);
});
test('counter → temperature: temperature island is reactive after SPA nav', async ({ page }) => {
await page.goto(BASE_URL + '/sx/(geography.(reactive.(examples.counter)))', { waitUntil: 'domcontentloaded' });
await waitForSxReady(page);
const counter = page.locator('[data-sx-island*="counter"]');
await expect(counter).toBeVisible({ timeout: 10000 });
// Navigate to temperature via link
const tempLink = page.locator('a[href*="temperature"]').first();
if (await tempLink.count() > 0) {
await tempLink.click();
} else {
await page.goto(BASE_URL + '/sx/(geography.(reactive.(examples.temperature)))', { waitUntil: 'domcontentloaded' });
await waitForSxReady(page);
}
const tempIsland = page.locator('[data-sx-island*="temperature"]');
await expect(tempIsland).toBeVisible({ timeout: 10000 });
const buttons = tempIsland.locator('button');
if (await buttons.count() > 0) {
const textBefore = await tempIsland.textContent();
await buttons.first().click();
await page.waitForTimeout(300);
expect(await tempIsland.textContent()).not.toBe(textBefore);
}
});
test('temperature → counter: counter island is reactive after SPA nav', async ({ page }) => {
await page.goto(BASE_URL + '/sx/(geography.(reactive.(examples.temperature)))', { waitUntil: 'domcontentloaded' });
await waitForSxReady(page);
const temp = page.locator('[data-sx-island*="temperature"]');
await expect(temp).toBeVisible({ timeout: 10000 });
const counterLink = page.locator('a[href*="counter"]').first();
if (await counterLink.count() > 0) {
await counterLink.click();
} else {
await page.goto(BASE_URL + '/sx/(geography.(reactive.(examples.counter)))', { waitUntil: 'domcontentloaded' });
await waitForSxReady(page);
}
const counter = page.locator('[data-sx-island*="counter"]');
await expect(counter).toBeVisible({ timeout: 10000 });
const buttons = counter.locator('button');
await expect(buttons).toHaveCount(2, { timeout: 5000 });
const textBefore = await counter.textContent();
await buttons.last().click();
await page.waitForTimeout(300);
expect(await counter.textContent()).not.toBe(textBefore);
});
test('no JS errors during reactive navigation', async ({ page }) => {
const errors = [];
page.on('pageerror', err => errors.push(err.message));
await page.goto(BASE_URL + '/sx/(geography.(reactive.(examples.counter)))', { waitUntil: 'domcontentloaded' });
await waitForSxReady(page);
const link = page.locator('a[href*="temperature"]').first();
if (await link.count() > 0) {
await link.click();
await expect(page).toHaveURL(/temperature/, { timeout: 5000 });
}
const real = errors.filter(e =>
!e.includes('Failed to fetch') && !e.includes('net::ERR')
);
expect(real).toEqual([]);
});
});