Add render-to-sx eval wrapper, preload handler mocks, load forms.sx

- render-to-sx: OCaml wrapper that parses source strings then evaluates
  via aser — unblocks test-aser.sx tests that pass string arguments
- Pre-load test-handlers.sx before test scan so reset-mocks!/helper are
  available to test-examples.sx (fixes 24 reset-mocks! failures)
- forms.sx loaded — provides defpage, stream-chunk-id, normalize-binding-key
- context registered as Sx_primitives primitive (not just env binding)
- cek-call, cek-run, now-ms, regex-find-all stubs added

1578 → 1661 passing tests (+83).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-01 19:05:13 +00:00
parent cbd5ad0a52
commit 909ec6e145

View File

@@ -308,6 +308,18 @@ let make_test_env () =
| [expr] -> eval_expr expr (Env env)
| _ -> raise (Eval_error "eval-expr: expected (expr env)"));
bind "set-render-active!" (fun _args -> Nil);
(* render-to-sx wrapper: if called with a string, parse and aser it *)
bind "render-to-sx" (fun args ->
match args with
| [String src] ->
let exprs = Sx_parser.parse_all src in
let expr = match exprs with [e] -> e | es -> List (Symbol "do" :: es) in
let result = eval_expr (List [Symbol "aser"; expr; Env env]) (Env env) in
(match result with SxExpr s -> String s | String s -> String s | _ -> String (Sx_runtime.value_to_str result))
| [expr; Env e] ->
let result = eval_expr (List [Symbol "aser"; expr; Env e]) (Env e) in
(match result with SxExpr s -> String s | String s -> String s | _ -> String (Sx_runtime.value_to_str result))
| _ -> String "");
(* Scope primitives — use a local scope stacks table.
Must match the same pattern as sx_server.ml's _scope_stacks. *)
let _scope_stacks : (string, Sx_types.value list) Hashtbl.t = Hashtbl.create 8 in
@@ -1056,6 +1068,10 @@ let run_spec_tests env test_files =
(* Determine test files — scan spec/tests/, lib/tests/, web/tests/ *)
let lib_tests_dir = Filename.concat project_dir "lib/tests" in
let web_tests_dir = Filename.concat project_dir "web/tests" in
(* Pre-load test-handlers.sx so its mock definitions (reset-mocks!, helper, etc.)
are available to test-examples.sx which loads before it alphabetically *)
load_module "test-handlers.sx" web_tests_dir;
let files = if test_files = [] then begin
(* Spec tests (core language — always run) *)
let spec_entries = Sys.readdir spec_tests_dir in