summaryrefslogtreecommitdiff
path: root/ocaml/scripts/test_pier_boot.ml
blob: f9b6a056dba6776599ce73ca740751f65be03b16 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
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"