Fix import resolution: correct library paths + hook type mismatch

Root causes of server [http-load] errors:
1. _import_hook passed pre-computed string key to library_loaded_p
   which calls library_name_key(string) → sx_to_list(string) → crash.
   Fix: pass original list spec, not the string key.
2. resolve_library_path didn't check web/lib/ for (sx dom), (sx browser),
   (web boot-helpers). These libraries use namespace prefixes that don't
   match their file locations.

Server startup errors: 190 → 0.
2683/2684 tests pass (1 known: define-library import clause — spec gap).
New test file: spec/tests/test-import-bind.sx

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-04 23:44:22 +00:00
parent 191981a22b
commit 6e216038ba
3 changed files with 95 additions and 10 deletions

View File

@@ -495,8 +495,7 @@ and cek_run state =
let op = match request with Dict d -> (match Hashtbl.find_opt d "op" with Some (String s) -> s | _ -> "") | _ -> "" in
if op = "import" then
let lib_spec = match request with Dict d -> (match Hashtbl.find_opt d "library" with Some v -> v | _ -> Nil) | _ -> Nil in
let key = library_name_key lib_spec in
let resolved = sx_truthy (library_loaded_p key) ||
let resolved = sx_truthy (library_loaded_p lib_spec) ||
(match !_import_hook with Some hook -> hook lib_spec | None -> false) in
if resolved then run (cek_resume final Nil)
else raise (Eval_error "IO suspension in non-IO context")
@@ -834,8 +833,7 @@ let cek_run_iterative state =
let op = match request with Dict d -> (match Hashtbl.find_opt d "op" with Some (String s) -> s | _ -> "") | _ -> "" in
if op = "import" then begin
let lib_spec = match request with Dict d -> (match Hashtbl.find_opt d "library" with Some v -> v | _ -> Nil) | _ -> Nil in
let key = library_name_key lib_spec in
let resolved = sx_truthy (library_loaded_p key) ||
let resolved = sx_truthy (library_loaded_p lib_spec) ||
(match !_import_hook with Some hook -> hook lib_spec | None -> false) in
if resolved then begin
s := cek_resume !s Nil;