Split make_server_env, eliminate all runtime sx_ref imports, fix auth-menu tests

make_server_env split into 7 focused setup functions:
- setup_browser_stubs (22 DOM no-ops)
- setup_scope_env (18 scope primitives from sx_scope.ml)
- setup_evaluator_bridge (CEK eval-expr, trampoline, expand-macro, etc.)
- setup_introspection (type predicates, component/lambda accessors)
- setup_type_operations (string/env/dict/equality/parser helpers)
- setup_html_tags (~100 HTML tag functions)
- setup_io_env (query, action, helper IO bridge)

Eliminate ALL runtime sx_ref.py imports:
- sx/sxc/pages/helpers.py: 24 imports → _ocaml_helpers.py bridge
- sx/sxc/pages/sx_router.py: remove SX_USE_REF fallback
- shared/sx/query_registry.py: use register_components instead of eval

Unify JIT compilation: pre-compile list derived from allowlist
(no manual duplication), only compiler internals pre-compiled.

Fix test_components auth-menu: ~auth-menu → ~shared:fragments/auth-menu

Tests: 1114 OCaml, 29/29 components, 35/35 regression, 6/6 Playwright

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-24 17:23:09 +00:00
parent 6ef9688bd2
commit 3df8c41ca1
6 changed files with 439 additions and 445 deletions

View File

@@ -45,7 +45,7 @@ def _component_source(name: str) -> str:
from shared.sx.jinja_bridge import get_component_env
from shared.sx.parser import serialize
from shared.sx.types import Component, Island
from shared.sx.ref.sx_ref import build_component_source
from ._ocaml_helpers import build_component_source
comp = get_component_env().get(name)
if isinstance(comp, Island):
@@ -109,7 +109,7 @@ def _special_forms_data() -> dict:
"""Parse special-forms.sx and return categorized form data."""
import os
from shared.sx.parser import parse_all
from shared.sx.ref.sx_ref import categorize_special_forms
from ._ocaml_helpers import categorize_special_forms
ref_dir = _ref_dir()
spec_path = os.path.join(ref_dir, "special-forms.sx")
@@ -125,7 +125,7 @@ def _reference_data(slug: str) -> dict:
REQUEST_HEADERS, RESPONSE_HEADERS,
EVENTS, JS_API, ATTR_DETAILS, HEADER_DETAILS,
)
from shared.sx.ref.sx_ref import build_reference_data
from ._ocaml_helpers import build_reference_data
# Build raw data dict and detail keys based on slug
if slug == "attributes":
@@ -202,7 +202,7 @@ def _js_translate_define(expr: list, name: str) -> str | None:
if _JS_SX_ENV is None:
from shared.sx.ref.run_js_sx import load_js_sx
_JS_SX_ENV = load_js_sx()
from shared.sx.ref.sx_ref import evaluate
from ._ocaml_helpers import evaluate
from shared.sx.types import Symbol
env = dict(_JS_SX_ENV)
env["_defines"] = [[name, expr]]
@@ -756,7 +756,7 @@ def _self_hosting_data(ref_dir: str) -> dict:
import os
from shared.sx.parser import parse_all
from shared.sx.types import Symbol
from shared.sx.ref.sx_ref import evaluate, make_env
from ._ocaml_helpers import evaluate, make_env
from shared.sx.ref.bootstrap_py import extract_defines, compile_ref_to_py, PyEmitter
try:
@@ -829,7 +829,7 @@ def _js_self_hosting_data(ref_dir: str) -> dict:
"""Run js.sx live: load into evaluator, translate all spec defines."""
import os
from shared.sx.types import Symbol
from shared.sx.ref.sx_ref import evaluate
from ._ocaml_helpers import evaluate
from shared.sx.ref.run_js_sx import load_js_sx
from shared.sx.ref.platform_js import extract_defines
@@ -881,7 +881,7 @@ def _bundle_analyzer_data() -> dict:
from shared.sx.deps import components_needed, scan_components_from_sx
from shared.sx.parser import serialize
from shared.sx.types import Component, Macro
from shared.sx.ref.sx_ref import build_bundle_analysis
from ._ocaml_helpers import build_bundle_analysis
env = get_component_env()
total_components = sum(1 for v in env.values() if isinstance(v, Component))
@@ -937,7 +937,7 @@ def _routing_analyzer_data() -> dict:
from shared.sx.pages import get_all_pages
from shared.sx.parser import serialize as sx_serialize
from shared.sx.helpers import _sx_literal
from shared.sx.ref.sx_ref import build_routing_analysis
from ._ocaml_helpers import build_routing_analysis
# I/O edge: extract page data from page registry
pages_raw = []
@@ -989,7 +989,7 @@ def _attr_detail_data(slug: str) -> dict:
"""Return attribute detail data for a specific attribute slug."""
from content.pages import ATTR_DETAILS
from shared.sx.helpers import sx_call
from shared.sx.ref.sx_ref import build_attr_detail
from ._ocaml_helpers import build_attr_detail
detail = ATTR_DETAILS.get(slug)
result = build_attr_detail(slug, detail)
@@ -1004,7 +1004,7 @@ def _header_detail_data(slug: str) -> dict:
"""Return header detail data for a specific header slug."""
from content.pages import HEADER_DETAILS
from shared.sx.helpers import sx_call
from shared.sx.ref.sx_ref import build_header_detail
from ._ocaml_helpers import build_header_detail
result = build_header_detail(slug, HEADER_DETAILS.get(slug))
demo_name = result.get("header-demo")
@@ -1017,7 +1017,7 @@ def _event_detail_data(slug: str) -> dict:
"""Return event detail data for a specific event slug."""
from content.pages import EVENT_DETAILS
from shared.sx.helpers import sx_call
from shared.sx.ref.sx_ref import build_event_detail
from ._ocaml_helpers import build_event_detail
result = build_event_detail(slug, EVENT_DETAILS.get(slug))
demo_name = result.get("event-demo")
@@ -1031,7 +1031,7 @@ def _run_spec_tests() -> dict:
import os
import time
from shared.sx.parser import parse_all
from shared.sx.ref.sx_ref import eval_expr as _eval, trampoline as _trampoline
from ._ocaml_helpers import eval_expr as _eval, trampoline as _trampoline
ref_dir = os.path.join(os.path.dirname(__file__), "..", "..", "shared", "sx", "ref")
if not os.path.isdir(ref_dir):
@@ -1105,7 +1105,7 @@ def _run_modular_tests(spec_name: str) -> dict:
import os
import time
from shared.sx.parser import parse_all
from shared.sx.ref.sx_ref import eval_expr as _eval, trampoline as _trampoline
from ._ocaml_helpers import eval_expr as _eval, trampoline as _trampoline
from shared.sx.types import Symbol, Keyword, Lambda, NIL
ref_dir = os.path.join(os.path.dirname(__file__), "..", "..", "shared", "sx", "ref")
@@ -1175,7 +1175,7 @@ def _run_modular_tests(spec_name: str) -> dict:
def render_html(sx_source):
try:
from shared.sx.ref.sx_ref import render_to_html as _render_to_html
from ._ocaml_helpers import render_to_html as _render_to_html
except ImportError:
return "<!-- render-to-html not available -->"
exprs = parse_all(sx_source)
@@ -1187,7 +1187,7 @@ def _run_modular_tests(spec_name: str) -> dict:
def _call_sx(fn, args, caller_env):
if isinstance(fn, Lambda):
from shared.sx.ref.sx_ref import call_lambda as _call_lambda
from ._ocaml_helpers import call_lambda as _call_lambda
return _trampoline(_call_lambda(fn, list(args), caller_env))
return fn(*args)
@@ -1259,7 +1259,7 @@ def _run_modular_tests(spec_name: str) -> dict:
# Load module functions from bootstrap
if sn == "router":
try:
from shared.sx.ref.sx_ref import (
from ._ocaml_helpers import (
split_path_segments,
parse_route_pattern,
match_route_segments,
@@ -1277,7 +1277,7 @@ def _run_modular_tests(spec_name: str) -> dict:
eval_file("router.sx")
elif sn == "deps":
try:
from shared.sx.ref.sx_ref import (
from ._ocaml_helpers import (
scan_refs, scan_components_from_source,
transitive_deps, compute_all_deps,
components_needed, page_component_bundle,
@@ -1302,7 +1302,7 @@ def _run_modular_tests(spec_name: str) -> dict:
env["test-env"] = lambda: env
elif sn == "engine":
try:
from shared.sx.ref.sx_ref import (
from ._ocaml_helpers import (
parse_time, parse_trigger_spec, default_trigger,
parse_swap_spec, parse_retry_spec, filter_params,
)
@@ -1345,7 +1345,7 @@ def _run_modular_tests(spec_name: str) -> dict:
env[stub] = _noop
# Load engine (orchestration depends on it)
try:
from shared.sx.ref.sx_ref import (
from ._ocaml_helpers import (
parse_time, parse_trigger_spec, default_trigger,
parse_swap_spec, parse_retry_spec, filter_params,
)
@@ -1459,7 +1459,7 @@ def _affinity_demo_data() -> dict:
from shared.sx.jinja_bridge import get_component_env
from shared.sx.types import Component
from shared.sx.pages import get_all_pages
from shared.sx.ref.sx_ref import build_affinity_analysis
from ._ocaml_helpers import build_affinity_analysis
# I/O edge: extract component data and page render plans
env = get_component_env()
@@ -1530,9 +1530,9 @@ def _prove_data() -> dict:
"""
import time
from shared.sx.parser import parse_all
from shared.sx.ref.sx_ref import evaluate
from ._ocaml_helpers import evaluate
from shared.sx.primitives import all_primitives
from shared.sx.ref.sx_ref import trampoline as _trampoline, call_lambda as _call_lambda
from ._ocaml_helpers import trampoline as _trampoline, call_lambda as _call_lambda
env = all_primitives()
@@ -1643,7 +1643,7 @@ def _page_helpers_demo_data() -> dict:
import os
import time
from shared.sx.parser import parse_all
from shared.sx.ref.sx_ref import (
from ._ocaml_helpers import (
categorize_special_forms, build_reference_data,
build_attr_detail, build_component_source,
build_routing_analysis,