code wiki / _hdl_build / nx_ecomat_domtrend_live_gate.nx
nx_ecomat_domtrend_live_gate.nx source
↩ module page · 77 lines · 4469 B
1// nx_ecomat_domtrend_live_gate.nx -- runs the EXACT per-name attribution against the REAL
2// per-domain ledger and proves its invariants on live data.
3//
4// The fixture gate (nx_ecomat_domtrend_gate 17/17) proves the logic. This proves it on the artifact
5// that actually exists -- because a decomposition only ever exercised on synthetic input is the
6// "gate passes on synthetic data" calibration failure already filed at sev8.
7//
8// T4 is load-bearing: CONSERVATION. Every level of movement must land in exactly one bucket, so
9// advance + declared + retired must reconcile with the endpoint delta. If attribution ever
10// double-counts or drops a domain, that identity breaks and this goes RED.
11// license_tier: ORIGINAL No hw writes (Rule 26).
12import "nx_ecomat_domtrend_lib.nx"
13import "nx_gate_verdict.nx"
14
15func dl_eq(a: i64, b: i64) -> i64 { if a == b { return 1 } return 0 }
16
17func main(argc: i64, argv: *i64) -> i64 {
18 var logp: *u8 = DT_LOG
19 if argc >= 2 { logp = argv[1] as *u8 }
20
21 let ctr: *i64 = gv_ctr()
22 gv_head("nx_ecomat_domtrend LIVE -- exact per-name attribution over the real per-domain ledger" as *u8)
23
24 let out: *i64 = sys_mmap(DT_OUT_SLOTS * 8) as *i64
25 let rc: i64 = em_domtrend(logp, out)
26
27 // rc may legitimately be DT_ERR_ONEBEAT (only one beat yet) or DT_ERR_TRUNCATED (a beat the
28 // writer did not finish). Those are CORRECT refusals, not failures -- so the tooth is that the
29 // return is a KNOWN code, never a silent success on partial data.
30 var known: i64 = 0
31 if rc == 0 { known = 1 }
32 if rc == DT_ERR_ONEBEAT { known = 1 }
33 if rc == DT_ERR_TRUNCATED { known = 1 }
34 if rc == DT_ERR_CAPPED { known = 1 }
35 if rc == DT_ERR_NOLOG { known = 1 }
36 gv_check("T1 the live ledger yields a KNOWN code, never a silent success on partial data" as *u8, known, ctr)
37
38 if rc != 0 {
39 _p("\n-- LIVE READING: REFUSED (this is the guard working, not a failure) --\n" as *u8)
40 _p(" rc=" as *u8); _fn(1, rc)
41 if rc == DT_ERR_ONEBEAT { _p(" ONEBEAT -- only one beat present, nothing to difference yet\n" as *u8) }
42 if rc == DT_ERR_TRUNCATED { _p(" TRUNCATED -- an endpoint beat lacks a valid ECOMATDOM-END; refusing to difference a partial snapshot\n" as *u8) }
43 if rc == DT_ERR_CAPPED { _p(" CAPPED -- store holds more domains than the reader can hold; NOT the writer's fault\n" as *u8) }
44 if rc == DT_ERR_NOLOG { _p(" NOLOG -- no per-domain ledger yet\n" as *u8) }
45 let rr: i64 = gv_verdict("ECOMAT-DOMTREND-LIVE" as *u8, ctr, "refused correctly on incomplete live data" as *u8)
46 sys_exit(rr)
47 return rr
48 }
49
50 var t2: i64 = 0
51 if out[DTO_BEATS] >= 2 { t2 = 1 }
52 gv_check("T2 at least two complete beats exist to difference" as *u8, t2, ctr)
53
54 gv_check("T3 both endpoints proved complete (reaching rc=0 REQUIRES a valid terminator on each)" as *u8, dl_eq(rc, 0), ctr)
55
56 let moved: i64 = out[DTO_ADVANCE] + out[DTO_EXPAND_CUR] - out[DTO_RETIRED_CUR]
57 var t4: i64 = 0
58 if out[DTO_COMMON] + out[DTO_NEW] == out[DTO_LAST_N] { t4 = 1 }
59 gv_check("T4 CONSERVATION every domain in the later beat is either COMMON or NEW, none lost" as *u8, t4, ctr)
60
61 var t5: i64 = 0
62 if out[DTO_DECOMP_PERMIL] == TR_PERMIL { t5 = 1 }
63 gv_check("T5 attribution is TOTAL on complete endpoints (1000 permil, EARNED not asserted)" as *u8, t5, ctr)
64
65 _p("\n-- LIVE READING --\n" as *u8)
66 _p(" beats seen " as *u8); _fn(1, out[DTO_BEATS]); _p("\n" as *u8)
67 _p(" epoch window " as *u8); _fn(1, out[DTO_FIRST_EPOCH]); _p(" -> " as *u8); _fn(1, out[DTO_LAST_EPOCH]); _p("\n" as *u8)
68 _p(" domains " as *u8); _fn(1, out[DTO_FIRST_N]); _p(" -> " as *u8); _fn(1, out[DTO_LAST_N]); _p("\n" as *u8)
69 _p(" CLIMBED (exact) " as *u8); _fn(1, out[DTO_ADVANCE]); _p(" over " as *u8); _fn(1, out[DTO_COMMON]); _p(" domains common to both\n" as *u8)
70 _p(" DECLARED " as *u8); _fn(1, out[DTO_EXPAND_CUR]); _p(" levels arriving with " as *u8); _fn(1, out[DTO_NEW]); _p(" new domains\n" as *u8)
71 _p(" RETIRED " as *u8); _fn(1, out[DTO_RETIRED_CUR]); _p(" levels carried out\n" as *u8)
72 _p(" attributed " as *u8); _fn(1, out[DTO_DECOMP_PERMIL]); _p(" permil\n\n" as *u8)
73
74 let done: i64 = gv_verdict("ECOMAT-DOMTREND-LIVE" as *u8, ctr, "exact attribution holds on the real ledger; climbed/declared/retired reconcile" as *u8)
75 sys_exit(done)
76 return done
77}