Add macros, declarative handlers (defhandler), and convert all fragment routes to sx
Some checks failed
Build and Deploy / build-and-deploy (push) Has been cancelled

Phase 1 — Macros: defmacro + quasiquote syntax (`, ,, ,@) in parser,
evaluator, HTML renderer, and JS mirror. Macro type, expansion, and
round-trip serialization.

Phase 2 — Expanded primitives: app-url, url-for, asset-url, config,
format-date, parse-int (pure); service, request-arg, request-path,
nav-tree, get-children (I/O); jinja-global, relations-from (pure).
Updated _io_service to accept (service "registry-name" "method" :kwargs)
with auto kebab→snake conversion. DTO-to-dict now expands datetime fields
into year/month/day convenience keys. Tuple returns converted to lists.

Phase 3 — Declarative handlers: HandlerDef type, defhandler special form,
handler registry (service → name → HandlerDef), async evaluator+renderer
(async_eval.py) that awaits I/O primitives inline within control flow.
Handler loading from .sx files, execute_handler, blueprint factory.

Phase 4 — Convert all fragment routes: 13 Python fragment handlers across
8 services replaced with declarative .sx handler files. All routes.py
simplified to uniform sx dispatch pattern. Two Jinja HTML handlers
(events/container-cards, events/account-page) kept as Python.

New files: shared/sx/async_eval.py, shared/sx/handlers.py,
shared/sx/tests/test_handlers.py, plus 13 handler .sx files under
{service}/sx/handlers/. MarketService.product_by_slug() added.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-03 00:22:18 +00:00
parent 13bcf755f6
commit ab75e505a8
48 changed files with 2538 additions and 638 deletions

View File

@@ -123,6 +123,52 @@ class TestParseAll:
assert parse_all(" ; only comments\n") == []
# ---------------------------------------------------------------------------
# Quasiquote
# ---------------------------------------------------------------------------
class TestQuasiquote:
def test_quasiquote_symbol(self):
result = parse("`x")
assert result == [Symbol("quasiquote"), Symbol("x")]
def test_quasiquote_list(self):
result = parse("`(a b c)")
assert result == [Symbol("quasiquote"), [Symbol("a"), Symbol("b"), Symbol("c")]]
def test_unquote(self):
result = parse(",x")
assert result == [Symbol("unquote"), Symbol("x")]
def test_splice_unquote(self):
result = parse(",@xs")
assert result == [Symbol("splice-unquote"), Symbol("xs")]
def test_quasiquote_with_unquote(self):
result = parse("`(a ,x b)")
assert result == [Symbol("quasiquote"), [
Symbol("a"),
[Symbol("unquote"), Symbol("x")],
Symbol("b"),
]]
def test_quasiquote_with_splice(self):
result = parse("`(a ,@rest)")
assert result == [Symbol("quasiquote"), [
Symbol("a"),
[Symbol("splice-unquote"), Symbol("rest")],
]]
def test_roundtrip_quasiquote(self):
assert serialize(parse("`(a ,x ,@rest)")) == "`(a ,x ,@rest)"
def test_roundtrip_unquote(self):
assert serialize(parse(",x")) == ",x"
def test_roundtrip_splice_unquote(self):
assert serialize(parse(",@xs")) == ",@xs"
# ---------------------------------------------------------------------------
# Errors
# ---------------------------------------------------------------------------