summaryrefslogtreecommitdiff
path: root/ocaml/scripts/test_pier_boot.ml
diff options
context:
space:
mode:
Diffstat (limited to 'ocaml/scripts/test_pier_boot.ml')
-rw-r--r--ocaml/scripts/test_pier_boot.ml99
1 files changed, 99 insertions, 0 deletions
diff --git a/ocaml/scripts/test_pier_boot.ml b/ocaml/scripts/test_pier_boot.ml
new file mode 100644
index 0000000..f9b6a05
--- /dev/null
+++ b/ocaml/scripts/test_pier_boot.ml
@@ -0,0 +1,99 @@
+open Nock_lib
+
+let rec find_project_root dir =
+ let pills_dir = Filename.concat dir "pills" in
+ if Sys.file_exists pills_dir && Sys.is_directory pills_dir then dir
+ else
+ let parent = Filename.dirname dir in
+ if String.equal parent dir then failwith "unable to locate project root containing pills/"
+ else find_project_root parent
+
+let project_root =
+ match Sys.getenv_opt "NEOVERE_ROOT" with
+ | Some root -> root
+ | None ->
+ let exe_dir = Filename.dirname Sys.executable_name in
+ find_project_root exe_dir
+
+let () =
+ Printf.printf "\n╔═══════════════════════════════════════════════════════╗\n";
+ Printf.printf "║ Pier Boot Test with Event Persistence ║\n";
+ Printf.printf "╚═══════════════════════════════════════════════════════╝\n\n";
+
+ (* Create pier directory for test *)
+ let pier_path = Filename.concat project_root "test-pier" in
+ Printf.printf "Creating test pier at: %s\n%!" pier_path;
+
+ (* Clean up old pier if it exists *)
+ if Sys.file_exists pier_path then begin
+ Printf.printf "Removing old test pier...\n%!";
+ let _ = Sys.command (Printf.sprintf "rm -rf '%s'" pier_path) in
+ ()
+ end;
+
+ (* Create pier directory *)
+ Unix.mkdir pier_path 0o755;
+
+ (* Create state WITH event logging enabled *)
+ Printf.printf "\n[1] Creating state with event logging enabled...\n%!";
+ let state = State.create ~pier_path () in
+
+ (* Step 1: Boot ivory pill *)
+ Printf.printf "\n[2] Booting ivory.pill...\n%!";
+ let ivory_path = Filename.concat project_root "pills/ivory.pill" in
+ begin match Boot.boot_ivory state ivory_path with
+ | Error (Boot.Invalid_pill msg) ->
+ Printf.printf "✗ Ivory boot failed: %s\n%!" msg;
+ exit 1
+ | Error (Boot.Unsupported msg) ->
+ Printf.printf "✗ Unsupported: %s\n%!" msg;
+ exit 1
+ | Ok () ->
+ Printf.printf "✓ Ivory kernel loaded\n\n%!";
+ end;
+
+ (* Step 2: Boot solid pill events WITH persistence *)
+ Printf.printf "[3] Loading solid.pill events with persistence...\n%!";
+ let solid_path = Filename.concat project_root "pills/solid.pill" in
+
+ (* For testing, let's limit to first 10 events to test persistence *)
+ begin match Boot.boot_solid ~limit:10 state solid_path with
+ | Error (Boot.Invalid_pill msg) ->
+ Printf.printf "✗ Solid boot failed: %s\n%!" msg;
+ exit 1
+ | Error (Boot.Unsupported msg) ->
+ Printf.printf "✗ Unsupported: %s\n%!" msg;
+ exit 1
+ | Ok () ->
+ let eve = State.event_number state in
+ Printf.printf "✓ Solid boot completed (limited)!\n%!";
+ Printf.printf " Events in state: %Ld\n\n%!" eve;
+ end;
+
+ (* Close the LMDB eventlog properly *)
+ Printf.printf "[4] Closing event log...\n%!";
+ State.close_eventlog state;
+ Printf.printf "✓ Event log closed\n\n%!";
+
+ (* Step 3: Check that LMDB files were created *)
+ Printf.printf "[5] Verifying LMDB files were created...\n%!";
+ let log_dir = Filename.concat (Filename.concat pier_path ".urb") "log" in
+ let event_files = Sys.readdir log_dir |> Array.to_list in
+ Printf.printf " Found %d files in %s\n%!" (List.length event_files) log_dir;
+
+ if List.length event_files > 0 then begin
+ Printf.printf " Sample files:\n";
+ List.iter (fun f -> Printf.printf " - %s\n%!" f) (List.filteri (fun i _ -> i < 5) event_files);
+ Printf.printf " ...\n%!";
+ end;
+
+ Printf.printf "\n╔═══════════════════════════════════════════════════════╗\n";
+ Printf.printf "║ Event Persistence Test SUCCESS! 🎉 ║\n";
+ Printf.printf "╚═══════════════════════════════════════════════════════╝\n\n";
+
+ Printf.printf "Test pier created at: %s\n" pier_path;
+ Printf.printf "Event log at: %s\n" log_dir;
+ Printf.printf "\nNext steps:\n";
+ Printf.printf " 1. Verify event log files exist\n";
+ Printf.printf " 2. Test event replay on restart\n";
+ Printf.printf " 3. Compare event mugs with Vere\n\n"