summaryrefslogtreecommitdiff
path: root/ocaml/test/test_life_on_bot.ml
blob: 1625a536be096adc08ad9b21efde65f64416cb4f (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
(* Test u3v_life() on JUST the bot events from solid pill *)

open Nock_lib

let rec to_list acc noun =
  match noun with
  | Noun.Atom _ -> List.rev acc
  | Noun.Cell (item, rest) -> to_list (item :: acc) rest

let test env =
  Printf.printf "═══════════════════════════════════════\n";
  Printf.printf " Testing u3v_life on Bot Events\n";
  Printf.printf "═══════════════════════════════════════\n\n";

  Eio.Switch.run @@ fun _sw ->
  let fs = Eio.Stdenv.fs env in

  (* Cue the solid pill *)
  Printf.printf "Cuing solid.pill...\n%!";
  let pill_bytes = Eio.Path.load (Eio.Path.(fs / "solid.pill")) |> Bytes.of_string in
  let pill = Serial.cue pill_bytes in
  Printf.printf "✓ Pill cued\n\n";

  (* Parse structure *)
  match pill with
  | Noun.Cell (_tag, rest) ->
      begin match rest with
      | Noun.Cell (_typ, rest2) ->
          begin match rest2 with
          | Noun.Cell (bot, _rest3) ->
              Printf.printf "Extracted bot events\n\n";

              (* Bot should be a list of lifecycle events *)
              Printf.printf "Testing u3v_life([2 [0 3] [0 2]]) on bot...\n%!";

              (* Build lifecycle formula *)
              let lyf = Noun.cell (Noun.atom 2)
                (Noun.cell
                  (Noun.cell (Noun.atom 0) (Noun.atom 3))
                  (Noun.cell (Noun.atom 0) (Noun.atom 2))) in

              begin try
                let start = Unix.gettimeofday () in
                let gat = Nock.nock_on bot lyf in
                let elapsed = Unix.gettimeofday () -. start in

                Printf.printf "✓ Formula completed in %.4fs!\n\n" elapsed;

                (* Extract slot 7 to get kernel *)
                let kernel = Noun.slot (Z.of_int 7) gat in
                Printf.printf "✓ Extracted kernel from slot 7\n\n";

                (* Verify kernel has poke at slot 23 *)
                begin try
                  let _poke = Noun.slot (Z.of_int 23) kernel in
                  Printf.printf "✓ Kernel has poke at slot 23!\n\n";

                  Printf.printf "═══════════════════════════════════════\n";
                  Printf.printf " 🎉 SUCCESS! We have a kernel! 🎉\n";
                  Printf.printf "═══════════════════════════════════════\n\n";

                  Printf.printf "The functional BIOS worked on bot events!\n"

                with _ ->
                  Printf.printf "✗ No slot 23 in kernel\n"
                end

              with
              | Noun.Exit ->
                  Printf.printf "✗ Formula failed (Nock Exit)\n";

                  (* Debug: what's in bot? *)
                  Printf.printf "\nDebugging bot structure:\n";
                  let bot_list = to_list [] bot in
                  Printf.printf "  Bot has %d items\n" (List.length bot_list);
                  List.iteri (fun i item ->
                    let desc = match item with
                      | Noun.Atom a -> Printf.sprintf "Atom(%s)" (Z.to_string a)
                      | Noun.Cell _ -> "Cell"
                    in
                    Printf.printf "    Item %d: %s\n" i desc
                  ) bot_list

              | e ->
                  Printf.printf "✗ Error: %s\n" (Printexc.to_string e)
              end

          | Noun.Atom _ ->
              Printf.printf "rest2 is atom\n"
          end
      | Noun.Atom _ ->
          Printf.printf "rest is atom\n"
      end
  | Noun.Atom _ ->
      Printf.printf "Pill is atom\n"

let () =
  Eio_main.run test