code wiki / _hdl_build / nx_treatment_gate.nx

nx_treatment_gate.nx source

↩ module page · 122 lines · 8946 B

1// nx_treatment_gate.nx -- GATE for the treatment ruler (nx_treatment_lib), driven IN-PROCESS on planted rows: a row 2// whose five fields all verify against planted allowlist, clock and roster text plus caller answers (COMPLETE), a row 3// with a dash (MISSING named), a row naming an allowlist row that is not GREEN (ABSENT named), an agent found on the 4// roster and not the clock, a row with a wrong key (FIELDS), a short row (FIELDS), a rung with no treat row 5// (UNDECLARED, labeled never refused), a board with no treat rows (NO-TREATMENT), the partition summing, and the 6// missing-list naming each field with its state. Every fixture asserts its own condition first. 7// license_tier: ORIGINAL No hw writes (Rule 26). 8import "nx_syscalls.nx" 9import "nx_treatment_lib.nx" 10import "nx_gate_verdict.nx" 11 12const G_I64: i64 = 8 13const G_PLAN: *u8 = "rung|R1|one|s1|d|Organ|1|-\nrung|R2|two|s2|d|Organ|1|-\nrung|R3|three|s3|d|Organ|1|-\nrung|R4|four|s4|d|Organ|1|-\nrung|R5|five|s5|d|Organ|1|-\nrung|R6|six|s6|d|Organ|1|-\ntreat|R1|mcp=nx_costcal|api=/api/tools/call name=nx_costcal|prim=nx_costest_lib|wf=costcal|agent=costcal\ntreat|R2|mcp=nx_costcal|api=-|prim=nx_costest_lib|wf=costcal|agent=costcal\ntreat|R3|mcp=nx_ghost|api=/api/tools/call name=nx_ghost|prim=nx_costest_lib|wf=costcal|agent=costcal\ntreat|R4|mcp=nx_costcal|api=/api/tools/call name=nx_costcal|prim=nx_costest_lib|wf=costcal|agent=nx_assets_gate\ntreat|R5|mcp=nx_costcal|apx=/api/tools/call|prim=nx_costest_lib|wf=costcal|agent=costcal\ntreat|R6|mcp=nx_costcal\n" 14const G_ALLOW: *u8 = "# allowlist\nnx_costcal\t/volume1/x/nx_costcal.elf\tGREEN\nnx_ghost\t/volume1/x/nx_ghost.elf\tRED\nnx_other\t/volume1/x/nx_other.elf\tGREEN\n" 15const G_CLOCK: *u8 = "costcal\t86400\tnx_costcal.elf\nother\t60\tnx_other.elf\n" 16const G_ROSTER: *u8 = "; roster\nnx_assets_gate\nnx_other_gate\n" 17const G_NOTREAT: *u8 = "rung|R1|one|s1|d|Organ|1|-\n" 18const G_ROWS: i64 = 6 19const G_RUNGS: i64 = 6 20const G_ROW_R1: i64 = 0 21const G_ROW_R2: i64 = 1 22const G_ROW_R3: i64 = 2 23const G_ROW_R4: i64 = 3 24const G_ROW_R5: i64 = 4 25const G_ROW_R6: i64 = 5 26const G_MISSCAP: i64 = 256 27 28func g_lit(s: *u8, dst: *u8) -> i64 { 29 let n: i64 = trt_slen(s) 30 var i: i64 = 0 31 while i < n { dst[i] = s[i]; i = i + 1 } 32 dst[n] = 0 as u8 33 return n 34} 35func g_streq(a: *u8, b: *u8) -> i64 { 36 let n: i64 = trt_slen(a) 37 if n != trt_slen(b) { return 0 } 38 var i: i64 = 0 39 while i < n { if a[i] != b[i] { return 0 } i = i + 1 } 40 return 1 41} 42 43func main(argc: i64, argv: *i64) -> i64 { 44 let c: *i64 = gv_ctr() 45 gv_head("nx_treatment_gate -- the three-step treatment ruler: mcp, api, primitive, workflow and agent per rung, judged on planted evidence" as *u8) 46 let plan: *u8 = sys_mmap(trt_slen(G_PLAN) + 1) 47 let pn: i64 = g_lit(G_PLAN, plan) 48 let allow: *u8 = sys_mmap(trt_slen(G_ALLOW) + 1) 49 let an: i64 = g_lit(G_ALLOW, allow) 50 let clock: *u8 = sys_mmap(trt_slen(G_CLOCK) + 1) 51 let cn: i64 = g_lit(G_CLOCK, clock) 52 let roster: *u8 = sys_mmap(trt_slen(G_ROSTER) + 1) 53 let rn: i64 = g_lit(G_ROSTER, roster) 54 let cap: i64 = trt_cap(pn) 55 gv_check("fixture-reached-the-condition: the derived capacity holds the six treat rows" as *u8, (cap >= G_ROWS) as i64, c) 56 let tab: *i64 = sys_mmap(cap * TRT_STRIDE * G_I64) as *i64 57 let rows: i64 = trt_scan(plan, pn, tab, cap) 58 gv_check_eq("treat-rows-parsed-six" as *u8, rows, G_ROWS, c) 59 // judge: R1..R4 with prim and wf found; R5 and R6 are malformed before any judgement 60 var r: i64 = 0 61 while r < rows { trt_judge_row(tab, r, plan, allow, an, roster, rn, clock, cn, 1, 1); r = r + 1 } 62 gv_check_eq("R1-complete-all-five-present" as *u8, tab[G_ROW_R1 * TRT_STRIDE + TRT_VERDICT], TRT_V_COMPLETE, c) 63 gv_check_eq("R1-mcp-present-from-the-allowlist" as *u8, tab[G_ROW_R1 * TRT_STRIDE + TRT_ST_MCP], TRT_F_PRESENT, c) 64 gv_check_eq("R1-agent-present-from-the-clock-plane" as *u8, tab[G_ROW_R1 * TRT_STRIDE + TRT_ST_AGENT], TRT_F_PRESENT, c) 65 gv_check_eq("R2-partial-api-dash-is-MISSING" as *u8, tab[G_ROW_R2 * TRT_STRIDE + TRT_ST_API], TRT_F_MISSING, c) 66 gv_check_eq("R2-verdict-partial" as *u8, tab[G_ROW_R2 * TRT_STRIDE + TRT_VERDICT], TRT_V_PARTIAL, c) 67 gv_check_eq("R3-mcp-row-not-GREEN-is-ABSENT" as *u8, tab[G_ROW_R3 * TRT_STRIDE + TRT_ST_MCP], TRT_F_ABSENT, c) 68 gv_check_eq("R3-api-follows-its-mcp-row-ABSENT" as *u8, tab[G_ROW_R3 * TRT_STRIDE + TRT_ST_API], TRT_F_ABSENT, c) 69 gv_check_eq("R4-agent-found-on-the-roster-not-the-clock" as *u8, tab[G_ROW_R4 * TRT_STRIDE + TRT_ST_AGENT], TRT_F_PRESENT, c) 70 gv_check_eq("R4-complete" as *u8, tab[G_ROW_R4 * TRT_STRIDE + TRT_VERDICT], TRT_V_COMPLETE, c) 71 gv_check_eq("R5-wrong-key-is-FIELDS" as *u8, tab[G_ROW_R5 * TRT_STRIDE + TRT_VERDICT], TRT_V_FIELDS, c) 72 gv_check_eq("R6-short-row-is-FIELDS" as *u8, tab[G_ROW_R6 * TRT_STRIDE + TRT_VERDICT], TRT_V_FIELDS, c) 73 // the missing list names each field with its state 74 let mb: *u8 = sys_mmap(G_MISSCAP) 75 trt_missing(tab, G_ROW_R2, mb, 0) 76 gv_check("R2-missing-list-names-api-as-missing" as *u8, g_streq(mb, "api:missing" as *u8), c) 77 trt_missing(tab, G_ROW_R3, mb, 0) 78 gv_check("R3-missing-list-names-mcp-and-api-as-absent" as *u8, g_streq(mb, "mcp:absent,api:absent" as *u8), c) 79 // no evidence keeps a declared field DECLARED (never acquitted, never convicted) 80 let tab2: *i64 = sys_mmap(cap * TRT_STRIDE * G_I64) as *i64 81 trt_scan(plan, pn, tab2, cap) 82 trt_judge_row(tab2, G_ROW_R1, plan, 0 as *u8, 0, 0 as *u8, 0, 0 as *u8, 0, 0 - 1, 0 - 1) 83 gv_check_eq("neg-control-no-evidence-leaves-mcp-DECLARED" as *u8, tab2[G_ROW_R1 * TRT_STRIDE + TRT_ST_MCP], TRT_F_DECLARED, c) 84 gv_check_eq("neg-control-no-evidence-is-PARTIAL-not-COMPLETE" as *u8, tab2[G_ROW_R1 * TRT_STRIDE + TRT_VERDICT], TRT_V_PARTIAL, c) 85 // prim and wf answered NOT FOUND convict 86 let tab3: *i64 = sys_mmap(cap * TRT_STRIDE * G_I64) as *i64 87 trt_scan(plan, pn, tab3, cap) 88 trt_judge_row(tab3, G_ROW_R1, plan, allow, an, roster, rn, clock, cn, 0, 0) 89 gv_check_eq("prim-not-found-is-ABSENT" as *u8, tab3[G_ROW_R1 * TRT_STRIDE + TRT_ST_PRIM], TRT_F_ABSENT, c) 90 gv_check_eq("wf-not-found-is-ABSENT" as *u8, tab3[G_ROW_R1 * TRT_STRIDE + TRT_ST_WF], TRT_F_ABSENT, c) 91 // the census and the board verdict 92 let cen: *i64 = sys_mmap(TRT_C_SLOTS * G_I64) as *i64 93 trt_census(tab, rows, plan, pn, cen) 94 gv_check_eq("census-rows" as *u8, cen[TRT_C_ROWS], G_ROWS, c) 95 gv_check_eq("census-complete-two" as *u8, cen[TRT_C_COMPLETE], 2, c) 96 gv_check_eq("census-partial-two" as *u8, cen[TRT_C_PARTIAL], 2, c) 97 gv_check_eq("census-fields-two" as *u8, cen[TRT_C_FIELDS], 2, c) 98 gv_check_eq("census-partition-sums-to-rows" as *u8, trt_partition_sum(cen), rows, c) 99 gv_check_eq("census-rungs-six" as *u8, cen[TRT_C_RUNGS], G_RUNGS, c) 100 gv_check_eq("census-undeclared-zero (every rung has a treat row)" as *u8, cen[TRT_C_UNDECLARED], 0, c) 101 gv_check_eq("board-verdict-PARTIAL (a declared row unmet is the hard fail)" as *u8, trt_verdict(cen), TRT_EXIT_PARTIAL, c) 102 gv_check("find-R4-by-id" as *u8, (trt_find(tab, rows, plan, "R4" as *u8) == G_ROW_R4) as i64, c) 103 gv_check("neg-control-find-unknown-rung-is-minus-one" as *u8, (trt_find(tab, rows, plan, "R9" as *u8) < 0) as i64, c) 104 // a board with no treat rows: NO-TREATMENT, labeled, its rung UNDECLARED 105 let np: *u8 = sys_mmap(trt_slen(G_NOTREAT) + 1) 106 let npn: i64 = g_lit(G_NOTREAT, np) 107 let ntab: *i64 = sys_mmap(trt_cap(npn) * TRT_STRIDE * G_I64) as *i64 108 let nrows: i64 = trt_scan(np, npn, ntab, trt_cap(npn)) 109 let ncen: *i64 = sys_mmap(TRT_C_SLOTS * G_I64) as *i64 110 trt_census(ntab, nrows, np, npn, ncen) 111 gv_check_eq("neg-control-no-treat-rows-parse-zero" as *u8, nrows, 0, c) 112 gv_check_eq("neg-control-no-treat-rows-is-NO-TREATMENT" as *u8, trt_verdict(ncen), TRT_EXIT_NONE, c) 113 gv_check_eq("neg-control-its-one-rung-is-UNDECLARED" as *u8, ncen[TRT_C_UNDECLARED], 1, c) 114 gv_values_head() 115 gv_kv("rows" as *u8, rows) 116 gv_kv("complete" as *u8, cen[TRT_C_COMPLETE]) 117 gv_kv("partial" as *u8, cen[TRT_C_PARTIAL]) 118 gv_kv("fields" as *u8, cen[TRT_C_FIELDS]) 119 gv_kv("rungs" as *u8, cen[TRT_C_RUNGS]) 120 gv_kv("undeclared" as *u8, cen[TRT_C_UNDECLARED]) 121 return gv_verdict("nx_treatment_gate" as *u8, c, "the treatment ruler proven on planted rows: five fields verified against planted allowlist, clock and roster text and caller answers, a dash reads MISSING, a non-GREEN allowlist row reads ABSENT and its api follows, an agent is found on either the clock plane or the roster, a wrong key or a short row is FIELDS, no evidence leaves a field DECLARED and the row PARTIAL (never acquitted), a not-found primitive or workflow is ABSENT, the census partition sums, a declared-and-unmet row is the hard fail, a board with no rows is NO-TREATMENT with its rungs UNDECLARED, and the missing list names each field with its state" as *u8) 122}