summaryrefslogtreecommitdiff
path: root/ocaml/test/test_poke_solid_arvo.ml
blob: e81c41f3abfd27f105c27eed0791dbf0756cbc06 (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
117
118
119
120
(* Test poking the Arvo kernel from solid pill *)

open Nock_lib

let extract_arvo_from_solid () =
  Printf.printf "Extracting Arvo from solid pill...\n";

  let in_channel = open_in_bin "solid.noun" in
  let pill = (Marshal.from_channel in_channel : Noun.noun) in
  close_in in_channel;

  match pill with
  | Noun.Cell (_tag, events) ->
      (* Get event 1 which should be the initial kernel *)
      let rec nth n noun =
        match noun with
        | Noun.Atom _ -> None
        | Noun.Cell (item, rest) ->
            if n = 0 then Some item
            else nth (n - 1) rest
      in

      begin match nth 1 events with
      | Some (Noun.Cell (_wire, card)) ->
          Printf.printf "✓ Extracted Arvo from event 1\n\n";
          Some card
      | _ ->
          Printf.printf "✗ Could not extract event 1\n";
          None
      end

  | _ -> None

let test_poke _env =
  Printf.printf "🎯 Testing Arvo Poke from Solid Pill\n\n";

  match extract_arvo_from_solid () with
  | None ->
      Printf.printf "✗ Failed to extract Arvo\n"

  | Some arvo ->
      Printf.printf "Creating test event...\n";

      (* Simple test event: [wire card] *)
      let test_event = Noun.cell
        (Noun.atom 0)  (* wire *)
        (Noun.cell (Noun.atom 1) (Noun.atom 42))  (* card [1 42] *)
      in

      Printf.printf "Test event: [0 [1 42]]\n\n";

      try
        (* Get poke gate *)
        let gate = Noun.slot (Z.of_int 23) arvo in
        Printf.printf "✓ Found poke gate at slot 23\n\n";

        (* Build subject: [event gate] *)
        let subject = Noun.cell test_event gate in

        (* Call gate: [9 2 [0 2] [0 3]] *)
        let formula = Noun.cell
          (Noun.atom 9)
          (Noun.cell
            (Noun.atom 2)
            (Noun.cell
              (Noun.cell (Noun.atom 0) (Noun.atom 2))
              (Noun.cell (Noun.atom 0) (Noun.atom 3))))
        in

        Printf.printf "Calling Arvo poke gate...\n%!";
        let start = Unix.gettimeofday () in
        let result = Nock.nock_on subject formula in
        let elapsed = Unix.gettimeofday () -. start in

        Printf.printf "✓ Poke succeeded in %.4fs!\n\n" elapsed;

        (* Examine result *)
        begin match result with
        | Noun.Cell (effects, new_kernel) ->
            Printf.printf "Result structure: [effects new_kernel]\n";
            Printf.printf "  Effects: %s\n"
              (match effects with Noun.Atom _ -> "atom" | Noun.Cell _ -> "cell");
            Printf.printf "  New kernel: %s\n\n"
              (match new_kernel with Noun.Atom _ -> "atom" | Noun.Cell _ -> "cell");

            (* Check if new kernel still has poke gate *)
            begin try
              let _new_gate = Noun.slot (Z.of_int 23) new_kernel in
              Printf.printf "✓ New kernel has poke gate\n\n";
              Printf.printf "🎉 ARVO IS FULLY FUNCTIONAL!\n";
              Printf.printf "\nWe can now:\n";
              Printf.printf "  - Send events to Arvo\n";
              Printf.printf "  - Process effects\n";
              Printf.printf "  - Build a full Urbit runtime!\n"
            with _ ->
              Printf.printf "✗ New kernel missing poke gate\n"
            end

        | Noun.Atom _ ->
            Printf.printf "Result is an atom (unexpected)\n"
        end

      with
      | Noun.Exit ->
          Printf.printf "✗ Nock failed (Exit)\n";
          Printf.printf "\nThis might mean:\n";
          Printf.printf "  - Wrong gate location (not slot 23)\n";
          Printf.printf "  - Wrong formula\n";
          Printf.printf "  - Event format is incorrect\n"
      | Not_found ->
          Printf.printf "✗ No gate at slot 23\n"

let () =
  Printf.printf "\n";
  Printf.printf "═══════════════════════════════════════════════════════════\n";
  Printf.printf " Test Poking Solid Pill Arvo\n";
  Printf.printf "═══════════════════════════════════════════════════════════\n";
  Printf.printf "\n";

  Eio_main.run test_poke