(executable
 (name tuna_tests)
 (modules tuna_tests)
 (libraries tuna tuna_interp alcotest))

(executable
 (name compiler_tests)
 (modules compiler_tests)
 (libraries tuna tuna_interp tuna_compiler alcotest))

(executable
 (name prim_tests)
 (modules prim_tests)
 (libraries tuna tuna_interp tuna_compiler alcotest))

(executable
 (name demand_tests)
 (modules demand_tests tuna_test_eio)
 (libraries tuna tuna_interp tuna_compiler tuna_store tuna_server alcotest eio eio_main eio.unix))

(executable
 (name delegation_tests)
 (modules delegation_tests tuna_test_eio)
 (libraries tuna tuna_interp tuna_compiler tuna_store tuna_server alcotest eio eio_main eio.unix))

; demand-memo (borg/sharing.borg): PG-gated, own scratch db
(rule
 (alias runtest)
 (deps demand_tests.exe ../scripts/test-store.sh (source_tree ../migrations))
 (action
  (bash
   "bash %{workspace_root}/scripts/test-store.sh %{exe:demand_tests.exe} ../migrations tuna_test_demand")))

; delegation-attenuation (borg/grants.borg): PG-gated, own scratch db
(rule
 (alias runtest)
 (deps delegation_tests.exe ../scripts/test-store.sh (source_tree ../migrations))
 (action
  (bash
   "bash %{workspace_root}/scripts/test-store.sh %{exe:delegation_tests.exe} ../migrations tuna_test_delegation")))

(executable
 (name flat_tests)
 (modules flat_tests)
 (libraries tuna tuna_interp alcotest))

(rule
 (alias runtest)
 (deps flat_tests.exe (source_tree ../scripts/diff-corpus))
 (action
  (run %{exe:flat_tests.exe})))

(executable
 (name sharing_tests)
 (modules sharing_tests)
 (libraries tuna tuna_interp tuna_compiler alcotest))

(executable
 (name trace_tests)
 (modules trace_tests)
 (libraries tuna tuna_interp tuna_compiler alcotest))

(rule
 (alias runtest)
 (deps trace_tests.exe)
 (action
  (run %{exe:trace_tests.exe})))

(rule
 (alias runtest)
 (deps sharing_tests.exe)
 (action
  (run %{exe:sharing_tests.exe})))

(executable
 (name store_tests)
 (modules store_tests tuna_test_eio)
 (libraries tuna tuna_interp tuna_compiler tuna_store tuna_server pgx alcotest eio eio_main eio.unix))

(executable
 (name tree_substrate_tests)
 (modules tree_substrate_tests tuna_test_eio)
 (libraries tuna tuna_compiler tuna_store tuna_server alcotest eio eio_main eio.unix))

(executable
 (name m11_tests)
 (modules m11_tests tuna_test_eio)
 (libraries tuna tuna_compiler tuna_store tuna_server base64 digestif alcotest eio eio_main eio.unix))

(executable
 (name repl_tests)
 (modules repl_tests)
 (libraries tuna tuna_interp tuna_compiler tuna_server alcotest))

(rule
 (alias runtest)
 (deps repl_tests.exe)
 (action
  (run %{exe:repl_tests.exe})))

(rule
 (alias runtest)
 (deps tuna_tests.exe)
 (action
  (run %{exe:tuna_tests.exe})))

(rule
 (alias runtest)
 (deps prim_tests.exe)
 (action
  (run %{exe:prim_tests.exe})))

; dialect sugar + reader tests (borg/dialect.borg v0.1-v0.3).
; THE GAP THIS CLOSES: compiler_tests.exe was declared at the top of this
; file but never had a runtest rule, so `dune runtest` stayed green while
; the suite carried 4 failures -- including every `match` row, i.e. the
; whole v0.3 reader form.  A test that never runs is not a gate.  The exe
; is self-contained (no corpus on disk, unlike flat_tests), so no
; source_tree dep is needed.
(rule
 (alias runtest)
 (deps compiler_tests.exe)
 (action
  (run %{exe:compiler_tests.exe})))

; M5 store integration tests: require a live postgres (scripts/dev.sh
; start-pg); skipped silently when it is down.  The migrations tree is
; passed in so the test executable can bootstrap a fresh cluster.
(rule
 (alias runtest)
 (deps store_tests.exe ../scripts/test-store.sh (source_tree ../migrations))
 (action
  (bash
   "bash %{workspace_root}/scripts/test-store.sh %{exe:store_tests.exe} ../migrations")))

; M10 substrate integration tests: same PG gate as store_tests, but on
; its own scratch database so the two suites never share one (dune
; runs alias rules in parallel).
(rule
 (alias runtest)
 (deps tree_substrate_tests.exe ../scripts/test-store.sh (source_tree ../migrations))
 (action
  (bash
   "bash %{workspace_root}/scripts/test-store.sh %{exe:tree_substrate_tests.exe} ../migrations tuna_test_sub")))

; M11 acceptance tests (byte values, routes as paths, tree/del): same PG
; gate, its own scratch database so the three PG suites never share one.
(rule
 (alias runtest)
 (deps m11_tests.exe ../scripts/test-store.sh (source_tree ../migrations))
   (action
    (bash
     "bash %{workspace_root}/scripts/test-store.sh %{exe:m11_tests.exe} ../migrations tuna_test_m11")))

; M12 federation FED1 acceptance tests (value exchange): same PG gate, its
; own scratch database so the PG suites never share one.
 (executable
 (name fed_tests)
 (modules fed_tests tuna_test_eio)
 (libraries tuna tuna_compiler tuna_store tuna_server base64 digestif alcotest eio eio_main eio.unix))

(rule
 (alias runtest)
 (deps fed_tests.exe ../scripts/test-store.sh (source_tree ../migrations))
 (action
  (bash
   "bash %{workspace_root}/scripts/test-store.sh %{exe:fed_tests.exe} ../migrations tuna_test_fed")))

; pp-slice accounts (0013): PG-gated like the other store suites,
; own scratch db so parallel PG suites never share one.
(executable
 (name session_tests)
 (modules session_tests tuna_test_eio)
 (libraries tuna tuna_interp tuna_compiler tuna_store tuna_server pgx alcotest eio eio_main eio.unix))

(rule
 (alias runtest)
 (deps session_tests.exe ../scripts/test-store.sh (source_tree ../migrations))
 (action
  (bash
   "bash %{workspace_root}/scripts/test-store.sh %{exe:session_tests.exe} ../migrations tuna_test_sessions")))

; M3 differential harness: three engines (instrumented upstream copy,
; CL reference twin, tuna CLI) must agree on every corpus entry.
; Skipped silently when sbcl is not installed.
(rule
 (alias runtest)
 (deps
  ../scripts/verify-differential.sh
  ../reference/tree-calc.lisp
  (source_tree ../scripts/diff-corpus))
 (action
  (bash "command -v sbcl >/dev/null 2>&1 && bash %{workspace_root}/scripts/verify-differential.sh || echo 'sbcl missing: differential harness skipped'")))

(executable
 (name deriv_tests)
 (modules deriv_tests tuna_test_eio)
 (libraries tuna tuna_interp tuna_compiler tuna_store tuna_server tuna_deriv alcotest eio eio_main eio.unix))

; derivation records (borg/deriv.borg): same PG gate, own scratch db
; (tuna_test_deriv) so the PG suites never share one.
(rule
 (alias runtest)
 (deps deriv_tests.exe ../scripts/test-store.sh (source_tree ../migrations))
 (action
  (bash
   "bash %{workspace_root}/scripts/test-store.sh %{exe:deriv_tests.exe} ../migrations tuna_test_deriv")))

; math prim differential (borg/math-prims.borg acceptance 1): embed the
; stdlib transcript for the in-test reference compile (same rule shape
; as server/lib/dune's stdlib_embed)
(rule
 (target stdlib_defs_test.ml)
 (deps ../stdlib/v1/core.defs ../tools/stdprobe/embed.py)
 (action
  (with-stdout-to %{target}
   (run python3 %{workspace_root}/tools/stdprobe/embed.py
     %{workspace_root}/stdlib/v1/core.defs))))

(executable
 (name math_prim_tests)
 (modules math_prim_tests math_prim_golden stdlib_defs_test)
 (libraries tuna tuna_interp tuna_compiler tuna_server alcotest))

(rule
 (alias runtest)
 (deps math_prim_tests.exe (source_tree ../stdlib))
 (action
  (run %{exe:math_prim_tests.exe})))

; httpun error-path regression (10-04 outage class, fix 3430f9b):
; real in-process Tuna_server.Web.serve + raw socket clients; no PG.
(executable
 (name web_errorpath_tests)
 (modules web_errorpath_tests)
 (libraries tuna_server alcotest eio eio.unix eio_main unix))

(rule
 (alias runtest)
 (deps web_errorpath_tests.exe)
 (action
  (run %{exe:web_errorpath_tests.exe})))

; signup + the name-registry law (pp-slice): the pure law tests run
; WITHOUT postgres (direct rule below); the pg parts ride the same
; store-test gate, on their own scratch database.
(executable
 (name signup_garden_tests)
 (modules signup_garden_tests tuna_test_eio)
 (libraries tuna tuna_compiler tuna_store tuna_server unix alcotest eio eio_main eio.unix))

(rule
 (alias runtest)
 (deps signup_garden_tests.exe)
 (action
  (run %{exe:signup_garden_tests.exe})))

(rule
 (alias runtest)
 (deps signup_garden_tests.exe ../scripts/test-store.sh (source_tree ../migrations))
 (action
  (bash
   "bash %{workspace_root}/scripts/test-store.sh %{exe:signup_garden_tests.exe} ../migrations tuna_test_signup")))
