summaryrefslogtreecommitdiff
path: root/ocaml/test/test_solid_boot.ml
blob: 08382da9725859685506b025030524d1b0267699 (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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
(* Test Solid Pill Boot
 *
 * Try loading solid pill which contains full Arvo kernel
 *)

open Nock_lib

let test_solid_boot env =
  Printf.printf "🎯 Testing Solid Pill Boot\n\n";

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

  (* Load solid pill *)
  Printf.printf "Loading solid pill (this may take a while)...\n";
  let file_path = Eio.Path.(fs / "solid.pill") in
  let pill_bytes = Eio.Path.load file_path |> Bytes.of_string in

  Printf.printf "Pill size: %.1f MB\n"
    (float_of_int (Bytes.length pill_bytes) /. 1024.0 /. 1024.0);

  let start = Unix.gettimeofday () in
  let pill = Serial.cue pill_bytes in
  let elapsed = Unix.gettimeofday () -. start in

  Printf.printf "Cued in %.2fs\n\n" elapsed;

  (* Examine structure *)
  Printf.printf "Examining solid pill structure:\n";
  if Noun.is_cell pill then begin
    Printf.printf "  ✓ Is cell\n";

    (* Check for tag *)
    let head = Noun.head pill in
    let tail = Noun.tail pill in

    Printf.printf "  Head: %s\n" (if Noun.is_cell head then "Cell" else "Atom");
    (match head with
     | Noun.Atom z ->
         Printf.printf "    Value: %s\n" (Z.to_string z);
         Printf.printf "    Hex: 0x%s\n" (Z.format "x" z)
     | _ -> ());

    Printf.printf "  Tail: %s\n\n" (if Noun.is_cell tail then "Cell" else "Atom");

    (* Try to navigate to Arvo core at known path *)
    Printf.printf "Navigating to Arvo core at [3 3 2 3 2 3 3 2]...\n";
    let path = [3; 3; 2; 3; 2; 3; 3; 2] in
    let rec navigate noun = function
      | [] -> noun
      | slot :: rest ->
          navigate (Noun.slot (Z.of_int slot) noun) rest
    in

    try
      let arvo = navigate tail path in
      Printf.printf "  ✓ Found Arvo core\n\n";

      (* Test for slot 23 *)
      Printf.printf "Testing for slot 23 (poke interface)...\n";
      (try
        let slot_23 = Noun.slot (Z.of_int 23) arvo in
        Printf.printf "  ✓ Slot 23 exists!\n";
        Printf.printf "  Type: %s\n\n"
          (if Noun.is_cell slot_23 then "Cell (formula)" else "Atom");

        (* Try C Vere poke sequence *)
        Printf.printf "Attempting poke sequence:\n";
        Printf.printf "  1. Run slot 23 formula on Arvo core\n";

        let start = Unix.gettimeofday () in
        let poke_gate = Nock.nock_on arvo slot_23 in
        let elapsed = Unix.gettimeofday () -. start in

        Printf.printf "  ✓ Got poke gate (%.4fs)\n" elapsed;

        Printf.printf "  2. Slam poke gate with test event\n";
        let event = Noun.cell (Noun.atom 0) (Noun.atom 42) in

        (* Slam: [battery [event context]] *)
        let battery = Noun.head poke_gate in
        let context = Noun.tail (Noun.tail poke_gate) in
        let new_core = Noun.cell battery (Noun.cell event context) in
        let kick_formula = Noun.cell (Noun.atom 9)
          (Noun.cell (Noun.atom 2)
            (Noun.cell (Noun.atom 0) (Noun.atom 1))) in

        Printf.printf "  3. Call arm 2\n";
        let start = Unix.gettimeofday () in
        let result = Nock.nock_on new_core kick_formula in
        let elapsed = Unix.gettimeofday () -. start in

        Printf.printf "  ✓ Poke succeeded in %.4fs!\n" elapsed;
        Printf.printf "  Result: %s\n\n"
          (if Noun.is_cell result then "Cell (effects + new state)" else "Atom");

        Printf.printf "🎉 SOLID PILL WORKS!\n";
        Printf.printf "We have successfully poked Arvo!\n"

      with e ->
        Printf.printf "  ✗ Slot 23 test failed: %s\n" (Printexc.to_string e))

    with e ->
      Printf.printf "  ✗ Navigation failed: %s\n" (Printexc.to_string e)

  end else
    Printf.printf "  ✗ Not a cell\n"

let () =
  Printf.printf "\n";
  Printf.printf "═══════════════════════════════════════════════════════════\n";
  Printf.printf " Testing Solid Pill Boot\n";
  Printf.printf "═══════════════════════════════════════════════════════════\n";
  Printf.printf "\n";

  Eio_main.run test_solid_boot