Files
rose-ash/tests/playwright/handler-responses.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

132 lines
5.0 KiB
JavaScript

const { test, expect } = require('playwright/test');
const { loadPage, trackErrors } = require('./helpers');
test.describe('Handler responses render correctly', () => {
let t;
test.beforeEach(({ page }) => { t = trackErrors(page); });
test.afterEach(() => { expect(t.errors()).toEqual([]); });
test('bulk-update: deactivate renders proper HTML attributes', async ({ page }) => {
await loadPage(page, '(geography.(hypermedia.(example.bulk-update)))');
// Check first row, note its status
const firstCheckbox = page.locator('input[type="checkbox"]').first();
await firstCheckbox.check();
// Click Deactivate
await page.locator('button:has-text("Deactivate")').first().click();
await page.waitForTimeout(2000);
// The table should still have proper HTML — no raw "class" text visible
const tableText = await page.locator('table').first().textContent();
expect(tableText).not.toContain('classpx');
expect(tableText).not.toContain('classborder');
// Rows should have proper class attributes, not class as text content
const firstTd = page.locator('table tbody tr td').first();
const tdClass = await firstTd.getAttribute('class');
expect(tdClass).toBeTruthy();
expect(tdClass).toContain('px-');
});
test('delete-row: response renders with proper HTML classes', async ({ page }) => {
await loadPage(page, '(geography.(hypermedia.(example.delete-row)))');
// Table should have proper class attrs, not text
const tableText = await page.locator('table').first().textContent();
expect(tableText).not.toContain('classpx');
expect(tableText).not.toContain('classborder');
// Click delete and check response doesn't corrupt
await page.locator('button:has-text("Delete")').first().click();
await page.waitForTimeout(2000);
const afterText = await page.locator('table').first().textContent();
expect(afterText).not.toContain('classpx');
expect(afterText).not.toContain('classborder');
});
test('click-to-load: loaded rows have proper HTML', async ({ page }) => {
await loadPage(page, '(geography.(hypermedia.(example.click-to-load)))');
const rowsBefore = await page.locator('table tbody tr').count();
const loadBtn = page.locator('button:has-text("Load More")').first();
if (await loadBtn.count() > 0) {
await loadBtn.click();
await page.waitForTimeout(2000);
const rowsAfter = await page.locator('table tbody tr').count();
expect(rowsAfter).toBeGreaterThan(rowsBefore);
// New rows should have proper class attrs
const lastTd = page.locator('table tbody tr:last-child td').first();
const text = await lastTd.textContent();
expect(text).not.toContain('classpx');
}
});
test('active-search: results render as proper HTML', async ({ page }) => {
await loadPage(page, '(geography.(hypermedia.(example.active-search)))');
const input = page.locator('input[placeholder*="earch"], input[name="q"]').first();
await input.fill('python');
await page.waitForTimeout(2000);
const results = page.locator('#search-results');
const text = await results.textContent();
// Should contain search results with proper HTML, not raw class text
expect(text).not.toContain('classpx');
expect(text).not.toContain('classbg');
});
test('form-submission: response renders as HTML not SX text', async ({ page }) => {
await loadPage(page, '(geography.(hypermedia.(example.form-submission)))');
const form = page.locator('form').first();
const inputs = form.locator('input[type="text"], input:not([type])');
if (await inputs.count() > 0) {
await inputs.first().fill('test-value');
}
const submit = form.locator('button[type="submit"], button').first();
await submit.click();
await page.waitForTimeout(2000);
// Response should not have raw SX class text
const root = page.locator('#sx-root');
const text = await root.textContent();
expect(text).not.toContain('classpx');
expect(text).not.toContain('classborder');
});
test('edit-row: edited row renders with proper classes', async ({ page }) => {
await loadPage(page, '(geography.(hypermedia.(example.edit-row)))');
const editBtn = page.locator('button:has-text("Edit")').first();
if (await editBtn.count() > 0) {
await editBtn.click();
await page.waitForTimeout(1000);
// Edit form or inline edit should not show raw class text
const root = page.locator('#sx-root');
const text = await root.textContent();
expect(text).not.toContain('classpx');
}
});
test('tabs: tab content renders as proper HTML', async ({ page }) => {
await loadPage(page, '(geography.(hypermedia.(example.tabs)))');
// Click a tab
const tabs = page.locator('[sx-get*="tab"]');
if (await tabs.count() >= 2) {
await tabs.nth(1).click();
await page.waitForTimeout(1000);
const root = page.locator('#sx-root');
const text = await root.textContent();
expect(text).not.toContain('classpx');
}
});
});