Commit Graph

341 Commits

Author SHA1 Message Date
2da80c69ed Phase 7b: page render plans — per-page boundary optimizer
Add page-render-plan to deps.sx: given page source + env + IO names,
computes a dict mapping each needed component to "server" or "client",
with server/client lists and IO dep collection. 5 new spec tests.

Integration:
- PageDef.render_plan field caches the plan at registration
- compute_page_render_plans() called from auto_mount_pages()
- Client page registry includes :render-plan per page
- Affinity demo page shows per-page render plans

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 00:02:53 +00:00
a70ff2b153 Phase 7a: affinity annotations + fix parser escape sequences
Add :affinity :client/:server/:auto annotations to defcomp, with
render-target function combining affinity + IO analysis. Includes
spec (eval.sx, deps.sx), tests, Python evaluator, and demo page.

Fix critical bug: Python SX parser _ESCAPE_MAP was missing \r and \0,
causing bootstrapped JS parser to treat 'r' as whitespace — breaking
all client-side SX parsing. Also add \0 to JS string emitter and
fix serializer round-tripping for \r and \0.

Reserved word escaping: bootstrappers now auto-append _ to identifiers
colliding with JS/Python reserved words (e.g. default → default_,
final → final_), so the spec never needs to avoid host language keywords.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-07 23:53:33 +00:00
81d8e55fb0 Fix sx-browser.js cache bust: use correct path for hash computation
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 5m4s
_script_hash used relative Path("static") which resolved to /app/static/
inside the container, but the file is at /app/shared/static/. Use
Path(__file__).parent.parent to resolve from shared/ correctly.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-07 22:38:49 +00:00
179631130c Fix parser escape ordering and prim_get for non-dict objects
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 3m37s
Parser: chained .replace() calls processed \n before \\, causing \\n
to become a real newline. Replaced with character-by-character
_unescape_string. Fixes 2 parser spec test failures.

Primitives: prim_get only handled dict and list. Objects with .get()
methods (like PageDef) returned None. Added hasattr fallback.
Fixes 9 defpage spec test failures.

All 259 spec tests now pass (was 244/259).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-07 22:17:38 +00:00
5a68046bd8 Restore stashed WIP: live streaming plan, forms, CI pipeline, streaming demo
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-07 22:07:59 +00:00
f5e47678d5 Fix streaming page: SX NIL namespace broke CSS matching on DOM elements
domCreateElement treated SX NIL (a truthy JS object) as a real namespace,
calling createElementNS("nil", tag) instead of createElement(tag). All
elements created by resolveSuspense ended up in the "nil" XML namespace
where CSS class selectors don't match.

Also fix ~suspense fallback: empty &rest list is truthy in SX, so
fallback content never rendered.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-07 20:24:29 +00:00
6596fac758 Merge branch 'worktree-iso-phase-4' into macros 2026-03-07 19:37:18 +00:00
299de98ea8 Fix resolveSuspense: iterate parsed exprs instead of passing array
parse() returns a list of expressions. resolveSuspense was passing the
entire array to renderToDom, which interpreted [(<> ...)] as a call
expression ((<> ...)) — causing "Not callable: {}". Now iterates
each expression individually, matching the public render() API.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-07 19:37:15 +00:00
e7a511d40a Merge branch 'worktree-iso-phase-4' into macros 2026-03-07 19:34:40 +00:00
aeac3c0b13 Debug: log head and args on evalCall "Not callable" error
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-07 19:34:36 +00:00
25edc7d64a Merge branch 'worktree-iso-phase-4' into macros 2026-03-07 19:23:32 +00:00
5cca22ae6d Revert make-raw-html wrapping from eval.sx spec
The make-raw-html wrapper in eval-list was host-specific: it fixed
server-side HTML escaping but broke the client DOM adapter (render-expr
returns DOM nodes, not strings). The raw-html wrapping belongs in the
host (async_eval_ref.py line 94-101), not the spec.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-07 19:23:27 +00:00
260475a4da Merge branch 'worktree-iso-phase-4' into macros 2026-03-07 19:20:57 +00:00
2c9d7c95a2 resolve-suspense: process new SX scripts before resolving
Streaming resolve scripts arrive after boot, so any extra component
defs sent as <script type="text/sx"> tags weren't being loaded.
Fix in the spec (boot.sx): call (process-sx-scripts nil) at the
start of resolve-suspense so late-arriving component defs are
available in componentEnv before rendering.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-07 19:20:54 +00:00
fd03eeb0fe Merge branch 'worktree-iso-phase-4' into macros 2026-03-07 19:08:35 +00:00
47448a6d37 Stream extra component defs with resolve scripts
Resolved SX content may reference components not in the initial shell
scan (e.g. ~cart-mini from IO-generated headers). Diff the needed
components against what the shell already sent and prepend any extra
defcomps as a <script type="text/sx"> block before the resolve script.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-07 19:08:32 +00:00
cdd775c999 Merge branch 'worktree-iso-phase-4' into macros 2026-03-07 19:02:31 +00:00
7294f07f5b Include layout + content component deps in streaming page scan
The streaming page's component scan only covered the suspense
placeholders, missing transitive deps from layout headers (e.g.
~cart-mini, ~auth-menu). Add layout.component_names to Layout class
and include them plus page content_expr in the scan source.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-07 19:02:29 +00:00
dd774efc18 Merge branch 'worktree-iso-phase-4' into macros 2026-03-07 18:58:48 +00:00
668a46bec0 Fix render-expr in eval position: wrap result in raw-html
The spec's eval-list calls render-expr for HTML tags/components in eval
position but returned a plain string. When that string was later passed
through _arender (e.g. as a component keyword arg), it got HTML-escaped.

Fix in eval.sx: wrap render-expr result in make-raw-html so the value
carries the raw-html type through any evaluator boundary. Also add
is_render_expr check in async_eval_ref.py as belt-and-suspenders for
the same issue in the async wrapper.

This fixes the streaming demo where suspense placeholder divs were
displayed as escaped text instead of real DOM elements.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-07 18:58:42 +00:00
9d70599416 Merge branch 'worktree-iso-phase-4' into macros 2026-03-07 18:34:24 +00:00
309579aec7 Fix streaming: render initial shell as HTML, not SX wire format
The streaming shell now uses render_to_html so [data-suspense] elements
are real DOM elements immediately when the browser parses the HTML.
Previously the shell used SX wire format in a <script data-mount> tag,
requiring sx-browser.js to boot and render before suspense elements
existed — creating a race condition where resolution scripts fired
before the elements were in the DOM.

Now: server renders HTML with suspense placeholders → browser has real
DOM elements → resolution scripts find and replace them reliably.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-07 18:34:24 +00:00
ca0ea69ca1 Merge branch 'worktree-iso-phase-4' into macros 2026-03-07 18:24:38 +00:00
44095c0a04 Fix streaming: split setup (needs context) from generator (just yields)
Async generator bodies don't execute until __anext__(), by which time
the request context is gone. Restructure execute_page_streaming as a
regular async function that does all context-dependent work (g, request,
current_app access, layout resolution, task creation) while the context
is live, then returns an inner async generator that only yields strings
and awaits pre-created tasks.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-07 18:24:38 +00:00
5991a5b397 Merge branch 'worktree-iso-phase-4' into macros 2026-03-07 18:20:59 +00:00
b9b315c86f Fix stream_with_context usage: it's a decorator, not a wrapper
stream_with_context decorates a generator function, not a generator
instance. Wrap execute_page_streaming in a decorated inner function.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-07 18:20:59 +00:00
ccf9a155ad Merge branch 'worktree-iso-phase-4' into macros 2026-03-07 18:18:32 +00:00
fa70c5f297 Fix streaming demo: preserve app context across async generator yields
Quart's ASGI layer doesn't propagate request/app context into async
generator iterations. Wrap execute_page_streaming with stream_with_context
so current_app and request remain accessible after each yield.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-07 18:18:28 +00:00
3574f7e163 Restructure boundary specs: move app-specific I/O out of language contract
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 2m42s
boundary.sx now contains only generic web-platform I/O primitives that
any SX host would provide (current-user, request-arg, url-for, etc.).

Moved to boundary-app.sx (deployment-specific):
- Inter-service: frag, query, action, service
- Framework: htmx-request?, g, jinja-global
- Domain: nav-tree, get-children, relations-from

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-07 18:04:53 +00:00
6312eb66a2 Merge branch 'worktree-iso-phase-4' into macros
# Conflicts:
#	shared/static/scripts/sx-browser.js
2026-03-07 18:01:56 +00:00
917a487195 Add deps and engine test specs, bootstrap engine to Python
New test specs (test-deps.sx: 33 tests, test-engine.sx: 37 tests) covering
component dependency analysis and engine pure functions. All 6 spec modules
now have formal SX tests: eval (81), parser (39), router (18), render (23),
deps (33), engine (37) = 231 total.

- Add engine as spec module in bootstrap_py.py (alongside deps)
- Add primitive aliases (trim, replace, parse_int, upper) for engine functions
- Fix parse-int to match JS parseInt semantics (strip trailing non-digits)
- Regenerate sx_ref.py with --spec-modules deps,engine
- Update all three test runners (run.js, run.py, sx-test-runner.js)
- Add Dependencies and Engine nav items and testing page entries
- Wire deps-source/engine-source through testing overview UI

Node.js: 231/231 pass. Python: 226/231 (5 pre-existing parser/router gaps).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-07 18:01:33 +00:00
605aafa2eb Fix client routing: fall through to server on layout/section change
Client-side routing was only swapping #main-panel content without
updating OOB headers (nav rows, sub-rows). Now each page entry in the
registry includes a layout identity (e.g. "sx-section:Testing") and
try-client-route falls through to server when layout changes, so OOB
header updates are applied correctly.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-07 17:46:01 +00:00
a05d642461 Phase 6: Streaming & Suspense — chunked HTML with suspense resolution
Server streams HTML shell with ~suspense placeholders immediately,
then sends resolution <script> chunks as async IO completes. Browser
renders loading skeletons instantly, replacing them with real content
as data arrives via __sxResolve().

- defpage :stream true opts pages into streaming response
- ~suspense component renders fallback with data-suspense attr
- resolve-suspense in boot.sx (spec) + bootstrapped to sx-browser.js
- __sxPending queue handles resolution before sx-browser.js loads
- execute_page_streaming() async generator with concurrent IO tasks
- Streaming demo page at /isomorphism/streaming with 1.5s simulated delay

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-07 17:34:10 +00:00
3119b8e310 Add Testing as top-level docs section with per-module specs
New /testing/ section with 6 pages: overview (all specs), evaluator,
parser, router, renderer, and runners. Each page runs tests server-side
(Python) and offers a browser "Run tests" button (JS). Modular browser
runner (sxRunModularTests) loads framework + per-spec sources from DOM.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-07 12:37:30 +00:00
aab1f3e966 Modular test architecture: per-module test specs for SX
Split monolithic test.sx into composable test specs:
- test-framework.sx: deftest/defsuite macros + assertion helpers
- test-eval.sx: core evaluator + primitives (81 tests)
- test-parser.sx: parser + serializer + round-trips (39 tests)
- test-router.sx: route matching from router.sx (18 tests)
- test-render.sx: HTML adapter rendering (23 tests)

Runners auto-discover specs and test whatever bootstrapped code
is available. Usage: `run.js eval parser router` or just `run.js`.
Legacy mode (`--legacy`) still runs monolithic test.sx.

Router tests use bootstrapped functions (sx_ref.py / sx-browser.js)
because the hand-written evaluator's flat-dict env model doesn't
support set! mutation across lambda closure boundaries.

JS: 161/161. Python: 159/161 (2 parser escape bugs found).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-07 12:17:13 +00:00
3a12368c9d Merge branch 'worktree-iso-phase-4' into macros 2026-03-07 11:03:48 +00:00
bec881acb3 Fix asset-url: use Jinja global instead of nonexistent urls.asset_url
The IO handler and bridge both imported asset_url from
shared.infrastructure.urls, but it doesn't exist there — it's a Jinja
global defined in jinja_setup.py. Use current_app.jinja_env.globals.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-07 11:03:46 +00:00
e89c496dc8 Merge branch 'worktree-iso-phase-4' into macros 2026-03-07 11:00:51 +00:00
7eb158c79f Add live browser test runner to /specs/testing page
sx-browser.js evaluates test.sx directly in the browser — click
"Run 81 tests" to see SX test itself. Uses the same Sx global that
rendered the page.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-07 11:00:37 +00:00
e9d86d628b Make test.sx self-executing: evaluators run it directly, no codegen
test.sx now defines deftest/defsuite as macros. Any host that provides
5 platform functions (try-call, report-pass, report-fail, push-suite,
pop-suite) can evaluate the file directly — no bootstrap compilation
step needed for JS.

- Added defmacro for deftest (wraps body in thunk, catches via try-call)
- Added defmacro for defsuite (push/pop suite context stack)
- Created run.js: sx-browser.js evaluates test.sx directly (81/81 pass)
- Created run.py: Python evaluator evaluates test.sx directly (81/81 pass)
- Deleted bootstrap_test_js.py and generated test_sx_spec.js
- Updated testing docs page to reflect self-executing architecture

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-07 10:50:28 +00:00
754e7557f5 Add self-hosting SX test spec: 81 tests bootstrap to Python + JS
The test framework is written in SX and tests SX — the language proves
its own correctness. test.sx defines assertion helpers (assert-equal,
assert-true, assert-type, etc.) and 15 test suites covering literals,
arithmetic, comparison, strings, lists, dicts, predicates, special forms,
lambdas, higher-order forms, components, macros, threading, truthiness,
and edge cases.

Two bootstrap compilers emit native tests from the same spec:
- bootstrap_test.py → pytest (81/81 pass)
- bootstrap_test_js.py → Node.js TAP using sx-browser.js (81/81 pass)

Also adds missing primitives to spec and Python evaluator: boolean?,
string-length, substring, string-contains?, upcase, downcase, reverse,
flatten, has-key?. Fixes number? to exclude booleans, append to
concatenate lists.

Includes testing docs page in SX app at /specs/testing.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-07 10:41:53 +00:00
f674a5edcc Merge branch 'worktree-iso-phase-4' into macros 2026-03-07 10:06:00 +00:00
e09bc3b601 Fix test_sx_js: temp file for large scripts, globalThis for Node file mode
sx-browser.js grew past OS arg length limit for node -e. Write to
temp file instead. Also fix Sx global scope: Node file mode sets
`this` to module.exports, not globalThis, so the IIFE wrapper needs
.call(globalThis) to make Sx accessible to sx-test.js.

855 passed (2 pre-existing empty .sx file failures).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-07 10:06:00 +00:00
43f2547de8 Merge branch 'worktree-iso-phase-4' into macros 2026-03-07 10:01:35 +00:00
8366088ee1 Add Phase 5 unit tests: IO proxy, io-deps registry, SxExpr roundtrip
22 tests covering:
- io-deps page registry field (pure, IO, transitive, serialization)
- Dynamic IO allowlist construction from component io_refs
- SxExpr serialize→parse roundtrip (unquoted, fragments, nil, in-dict)
- IO proxy arg parsing (GET query string vs POST JSON body)
- Orchestration routing logic (io-deps truthiness, parsed entries)
- IO cache key determinism

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-07 10:01:35 +00:00
fd20811afa Merge branch 'worktree-iso-phase-4' into macros 2026-03-07 09:51:51 +00:00
84ea5d4c16 IO proxy: client-side cache with 5min TTL, server Cache-Control
Client caches IO results by (name + args) in memory. In-flight
promises are cached too (dedup concurrent calls for same args).
Server adds Cache-Control: public, max-age=300 for HTTP caching.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-07 09:51:51 +00:00
51990d9445 Merge branch 'worktree-iso-phase-4' into macros 2026-03-07 09:50:23 +00:00
0d6b959045 Mark IO proxy endpoint as CSRF-exempt (read-only, no state mutation)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-07 09:50:23 +00:00
847d5d1f31 Merge branch 'worktree-iso-phase-4' into macros 2026-03-07 09:40:24 +00:00