src/CrashPoint.bend

mylsm-lsm-store@0.3.0.0 · 31 lines · 0 definitions

1import Base
2import mylsm-lsm-store@0.3.0.0/src/Console.bend as Console
3
4# Pure checkpoint policy. Console.get_env maps an unset value to "", so the
5# non-empty guard distinguishes disabled injection from an exact empty match.
6def nonempty(value: String) -> Bool:
7  match value:
8    case SNil{}: False{}
9    case SCon{_, _}: True{}
10
11def enabled(+configured: String, requested: String) -> Bool:
12  Bool.and(nonempty(configured), String.eq(configured, requested))
13
14# Irreducible host boundary: emit an unbuffered marker and stop this process.
15def stop(name: String) -> IO(Result<&1, &1, U32 & String, Unit>):
16  import "./effs/crash_point.c"
17  import "./effs/crash_point.js"
18
19def hit_decision(active: Bool, name: String) -> IO(Result<&1, &1, U32 & String, Unit>):
20  match active:
21    case True{}:
22      stop(name)
23    case False{}:
24      IO.pure(Result<&1, &1, U32 & String, Unit>, Done{Unit{}})
25
26# Test-only checkpoint. Environment lookup and activation policy stay in Bend;
27# only marker emission and SIGSTOP remain in the host twins.
28def hit(+name: String) -> IO(Result<&1, &1, U32 & String, Unit>):
29  do IO<Result<&1, &1, U32 & String, Unit>>:
30    configured : String <- IO.try(String, Console.get_env("MYLSM_CRASH_POINT"))
31    hit_decision(enabled(configured, name), name)