From f857b3eddbba2c0a4523f66987a3edfc88f825e9 Mon Sep 17 00:00:00 2001 From: giles Date: Wed, 1 Apr 2026 19:06:39 +0000 Subject: [PATCH] Re-bind render-to-sx after module load to handle string inputs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The OCaml render-to-sx wrapper now correctly overrides the SX version loaded from adapter-sx.sx: string inputs get parsed → aser evaluated, AST inputs delegate to the SX version. Fixes ~41 aser test failures. 1661 → 1702 passing tests. Co-Authored-By: Claude Opus 4.6 (1M context) --- hosts/ocaml/bin/run_tests.ml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/hosts/ocaml/bin/run_tests.ml b/hosts/ocaml/bin/run_tests.ml index 4f9e891a..3b3ec8f4 100644 --- a/hosts/ocaml/bin/run_tests.ml +++ b/hosts/ocaml/bin/run_tests.ml @@ -1072,6 +1072,25 @@ let run_spec_tests env test_files = (* 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; + + (* Re-bind render-to-sx AFTER adapter-sx.sx has loaded, wrapping the SX version. + The SX render-to-sx handles AST inputs; we add string→parse→aser support. *) + let sx_render_to_sx = try Some (Sx_types.env_get env "render-to-sx") with _ -> None in + ignore (Sx_types.env_bind env "render-to-sx" (NativeFn ("render-to-sx", fun args -> + match args with + | [String src] -> + (* String input: parse then evaluate via aser *) + 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)) + | _ -> + (* AST input: delegate to the SX render-to-sx *) + match sx_render_to_sx with + | Some (NativeFn (_, f)) -> f args + | Some (Lambda _ as fn) -> Sx_ref.cek_call fn (List args) + | _ -> String ""))); + let files = if test_files = [] then begin (* Spec tests (core language — always run) *) let spec_entries = Sys.readdir spec_tests_dir in