Something went wrong. Try again.
Git-native issue tracker
Something went wrong. Try again.
3.0 kB · 100 lines
OCaml
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101module C = Tracker.Coremodule A = Tracker.Anchormodule P = Tracker_view.Pointermodule V = Tracker_view.View
let source path text : A.source = { path; blob = Cas.Hash.(to_hex (sha256 text)); text }
let captured index line = match A.capture index ~path:"lib/original.ml" ~line with | Some anchor -> anchor | None -> Alcotest.fail "fixture definition missing"
let has body needle = let size = String.length needle in let rec scan i = i + size <= String.length body && (String.sub body i size = needle || scan (i + 1)) in scan 0
let resolved_pointer_pages () = let old_source = source "lib/original.ml" "let stay x = x + 1\nlet move x = x * 2\nlet gone x = x - 1\n" in let old_index = A.index ~cache:(A.cache ()) [ old_source ] in let stay = captured old_index 1 in let moved = captured old_index 2 in let gone = captured old_index 3 in let row = C.Row.v ~id:"space-1" ~title:"Anchored row" ~kind:"task" ~priority:2 ~checks:[] ~anchors:[ stay; moved; gone ] ~triage:C.Row.Ready ~filed:"2026-09-28T00:00:00Z" () in let sources = [ source "lib/original.ml" "let stay x = x + 1\n"; source "lib/other.ml" "\n\nlet move x = x * 2\n"; ] in let inputs = List.map (fun anchor -> P.{ row = "space-1"; package = "tracker"; anchor }) [ stay; moved; gone ] in let pointers = P.resolve ~cache:(A.cache ()) ~sources inputs in let summary : Tracker.Sqlite_index.summary = { id = "space-1"; title = "Anchored row"; kind = "task"; status = C.Open; priority = 2; triage = C.Row.Ready; disclosure = None; filed = "2026-09-28T00:00:00Z"; holder = None; } in let snapshot = V.v ~tree:"source-tree" ~visible:[ summary ] ~rows:[ row ] ~fields:[] ~pointers () in let routes = Tracker_view.Serve.routes ~addr:(`Unix "tk.sock") ~snapshot:(fun ~path:_ ~query:_ -> Ok snapshot) ~current_tree:(fun () -> Ok "source-tree") ~sleep:(fun _ -> ()) () in let served path = let response = Respond.dispatch ~propagate:Respond_eio.cancelled ~routes ~meth:"GET" ~url:path ~headers:Http.Headers.empty ~body:"" in Alcotest.(check int) (path ^ " status") 200 response.Respond.Response.status; response.Respond.Response.body in let detail = served "/rows/space-1" in let pointers_page = served "/pointers" in let contains page needle = Alcotest.(check bool) needle true (has page needle) in contains detail "exact"; contains detail "lib/original.ml:1"; contains detail "moved"; contains detail "lib/other.ml:3"; contains detail "gone"; contains pointers_page "lib/other.ml:3"; contains pointers_page "/rows/space-1"; Alcotest.(check bool) "unchanged omitted from findings" false (has pointers_page "lib/original.ml:1")
let suite = ( "pointer", [ Alcotest.test_case "resolved pointer pages" `Quick resolved_pointer_pages; ] )