nx_claim_binding_gate.nx source
↩ module page · 107 lines · 6407 B
1// nx_claim_binding_gate.nx -- CE4: does a board effectiveness claim get re-read against the LIVE artifact?
2//
3// IN-PROCESS: imports nx_symdecl_lib.nx and calls cb_classify / cb_serve_state_at directly, so it
4// exercises the SAME rule the emitter will, with no NOT-DEPLOYED failure mode.
5//
6// THE CLAIM RE-READ IS THE ONE THE McCABE ROW FAILED: a "shipped" claim over an organ whose binary is
7// SOURCE-ONLY must read STALE-UNDER (the verdict contradicts it), and over an absent organ must REFUSE
8// (the verdict denies it). Every expected class below was decided from the CE4 ACCEPT rule before the run.
9//
10// The classify teeth are PURE (no filesystem). The serve-state teeth plant a THREE-STATE fixture tree
11// under /tmp/cb_gate/ -- unlinked before creation, sharing nothing with any beat -- so a served binary, a
12// source-only organ and an absent one are three distinct fixtures and no delete happens mid-run.
13// license_tier: ORIGINAL expect_exit: 0
14import "nx_symdecl_lib.nx"
15import "nx_gate_verdict.nx"
16
17const CBG_DIR: *u8 = "/tmp/cb_gate\x00"
18const CBG_SERVE: *u8 = "/tmp/cb_gate/serving\x00"
19const CBG_BUILD: *u8 = "/tmp/cb_gate/build\x00"
20const CBG_BUILDRT: *u8 = "/tmp/cb_gate/build/runtime\x00"
21const CBG_MODE644: i64 = 420
22const CBG_MODE755: i64 = 493
23
24func cbg_put(path: *u8, data: *u8) -> i64 {
25 sys_unlinkat(path)
26 let fd: i64 = sys_openat_wr(path, CBG_MODE644)
27 if fd < 0 { return 0 - 1 }
28 var n: i64 = 0
29 while data[n] != (0 as u8) { n = n + 1 }
30 if n > 0 { sys_write(fd, data, n) }
31 sys_close(fd)
32 return n
33}
34
35func main(argc: i64, argv: *i64) -> i64 {
36 gv_head("=== NX-CLAIM-BINDING-GATE -- is a board claim re-read against the live served artifact? ===" as *u8)
37 let ctr: *i64 = gv_ctr()
38
39 // ---------- the classifier, pure: every expected class decided from CE4's ACCEPT rule ----------
40 let c_served: i64 = cb_classify(1, CB_SERVED)
41 let c_srconly: i64 = cb_classify(1, CB_SOURCE_ONLY)
42 let c_absent: i64 = cb_classify(1, CB_ABSENT)
43 let c_no: i64 = cb_classify(0, CB_ABSENT)
44 gv_check_eq("a-shipped-claim-over-a-SERVED-organ-is-CONSISTENT" as *u8, c_served, CB_CLASS_CONSISTENT, ctr)
45 gv_check_eq("a-shipped-claim-over-a-SOURCE-ONLY-organ-is-STALE-UNDER-the-McCabe-defect" as *u8, c_srconly, CB_CLASS_STALE_UNDER, ctr)
46 gv_check_eq("a-shipped-claim-over-an-ABSENT-organ-REFUSES-the-liar-kill-class" as *u8, c_absent, CB_CLASS_REFUSE, ctr)
47 gv_check_eq("neg-control-a-No-claim-needs-no-backing-and-is-CONSISTENT-over-nothing" as *u8, c_no, CB_CLASS_CONSISTENT, ctr)
48
49 // BITE PAIRS: both signals at once. The detector is "does classify convict a broken claim". The BAD
50 // input must fire, the GOOD input must stay silent -- a classifier that blesses everything dies here.
51 var fires_absent: i64 = 0
52 if c_absent == CB_CLASS_REFUSE { fires_absent = 1 }
53 var fires_served_refuse: i64 = 0
54 if c_served == CB_CLASS_REFUSE { fires_served_refuse = 1 }
55 gv_bite("REFUSES-a-claim-over-an-absent-organ-and-does-NOT-refuse-a-served-one" as *u8, fires_absent, fires_served_refuse, ctr)
56 var withholds_srconly: i64 = 0
57 if c_srconly != CB_CLASS_CONSISTENT { withholds_srconly = 1 }
58 var withholds_served: i64 = 0
59 if c_served != CB_CLASS_CONSISTENT { withholds_served = 1 }
60 gv_bite("does-NOT-bless-a-source-only-claim-but-DOES-bless-a-served-one" as *u8, withholds_srconly, withholds_served, ctr)
61
62 // ---------- the served-state reader, on a THREE-STATE fixture tree ----------
63 sys_mkdir(CBG_DIR as *u8, CBG_MODE755)
64 sys_mkdir(CBG_SERVE as *u8, CBG_MODE755)
65 sys_mkdir(CBG_BUILD as *u8, CBG_MODE755)
66 sys_mkdir(CBG_BUILDRT as *u8, CBG_MODE755)
67 // SERVED: a served binary AND a source both present
68 cbg_put("/tmp/cb_gate/serving/cbserved.elf\x00" as *u8, "ELF-STUB\n" as *u8)
69 cbg_put("/tmp/cb_gate/build/runtime/cbserved.nx\x00" as *u8, "func t() -> i64 { return 0 }\n" as *u8)
70 // SOURCE-ONLY: a source with no served binary
71 cbg_put("/tmp/cb_gate/build/runtime/cbsrconly.nx\x00" as *u8, "func t() -> i64 { return 0 }\n" as *u8)
72 sys_unlinkat("/tmp/cb_gate/serving/cbsrconly.elf\x00" as *u8)
73 // ABSENT: neither -- unlink any leftover so the gate is idempotent
74 sys_unlinkat("/tmp/cb_gate/serving/cbabsent.elf\x00" as *u8)
75 sys_unlinkat("/tmp/cb_gate/build/runtime/cbabsent.nx\x00" as *u8)
76
77 let s_served: i64 = cb_serve_state_at(CBG_SERVE, CBG_BUILD, "runtime/cbserved.nx" as *u8)
78 let s_srconly: i64 = cb_serve_state_at(CBG_SERVE, CBG_BUILD, "runtime/cbsrconly.nx" as *u8)
79 let s_absent: i64 = cb_serve_state_at(CBG_SERVE, CBG_BUILD, "runtime/cbabsent.nx" as *u8)
80 gv_check_eq("served-fixture-with-a-binary-reads-SERVED" as *u8, s_served, CB_SERVED, ctr)
81 gv_check_eq("source-only-fixture-reads-SOURCE-ONLY-the-defect-symbol-presence-cannot-see" as *u8, s_srconly, CB_SOURCE_ONLY, ctr)
82 gv_check_eq("a-fixture-with-neither-reads-ABSENT" as *u8, s_absent, CB_ABSENT, ctr)
83 var reads_served_present: i64 = 0
84 if s_served == CB_SERVED { reads_served_present = 1 }
85 var reads_served_srconly: i64 = 0
86 if s_srconly == CB_SERVED { reads_served_srconly = 1 }
87 gv_bite("reads-SERVED-only-when-a-binary-is-present-and-is-silent-for-a-source-only-organ" as *u8, reads_served_present, reads_served_srconly, ctr)
88
89 // idempotence
90 let s_again: i64 = cb_serve_state_at(CBG_SERVE, CBG_BUILD, "runtime/cbserved.nx" as *u8)
91 var okid: i64 = 0
92 if s_again == s_served { okid = 1 }
93 gv_check("idempotent-a-second-read-of-the-served-fixture-returns-the-same-state" as *u8, okid, ctr)
94
95 // end-to-end: the McCabe shape -- a shipped claim over a source-only organ classifies STALE-UNDER
96 let e2e: i64 = cb_classify(1, s_srconly)
97 gv_check_eq("end-to-end-a-shipped-claim-bound-to-a-source-only-organ-publishes-STALE-UNDER" as *u8, e2e, CB_CLASS_STALE_UNDER, ctr)
98
99 gv_kv("classify_served" as *u8, c_served)
100 gv_kv("classify_source_only" as *u8, c_srconly)
101 gv_kv("classify_absent" as *u8, c_absent)
102 gv_kv("serve_state_served" as *u8, s_served)
103 gv_kv("serve_state_source_only" as *u8, s_srconly)
104 gv_kv("serve_state_absent" as *u8, s_absent)
105
106 return gv_verdict("claim_binding" as *u8, ctr, "every expected class was decided from CE4 ACCEPT before the run; the served-state fixtures are three distinct runtime-planted /tmp trees, unlinked before creation" as *u8)
107}