code wiki / _hdl_build / nx_ecomat_trend_live_gate.nx
nx_ecomat_trend_live_gate.nx source
↩ module page · 82 lines · 4912 B
1// nx_ecomat_trend_live_gate.nx -- runs the advancement/expansion decomposition against the REAL
2// durable ledger and proves the instrument's invariants hold on live data, then prints the finding.
3//
4// The sibling nx_ecomat_trend_gate proves the logic on fixtures. This one proves it on the artifact
5// that actually exists -- a decomposition that is only ever exercised on synthetic input is exactly
6// the "gate passes on synthetic data" calibration failure already filed at sev8.
7//
8// THE LOAD-BEARING TOOTH IS T4, CONSERVATION: every level of movement in the ledger must land in
9// EXACTLY one bucket, so advance + ambiguous must equal the total change in sum_cur. If attribution
10// ever double-counts or drops a span, that identity breaks and this gate goes RED -- which is the
11// whole reason to state the invariant rather than eyeball the columns.
12// T5 is an independent cross-check: our recomputed ratio vs the ratio the ROLLUP itself recorded.
13// license_tier: ORIGINAL No hw writes (Rule 26).
14import "nx_ecomat_trend_lib.nx"
15import "nx_gate_verdict.nx"
16
17func lg_eq(a: i64, b: i64) -> i64 { if a == b { return 1 } return 0 }
18
19func main(argc: i64, argv: *i64) -> i64 {
20 var logp: *u8 = TR_LEDGER
21 if argc >= 2 { logp = argv[1] as *u8 }
22
23 let ctr: *i64 = gv_ctr()
24 gv_head("nx_ecomat_trend LIVE -- decomposition invariants over the real maturity ledger" as *u8)
25
26 let out: *i64 = sys_mmap(TR_OUT_SLOTS * TR_I64) as *i64
27 let rc: i64 = em_trend(logp, out)
28
29 gv_check("T1 the real ledger is readable and decomposed (rc=0)" as *u8, lg_eq(rc, 0), ctr)
30 if rc != 0 {
31 let bad: i64 = gv_verdict("ECOMAT-TREND-LIVE" as *u8, ctr, "live ledger unreadable" as *u8)
32 sys_exit(bad)
33 return bad
34 }
35
36 var t2: i64 = 0
37 if out[TRO_ROWS] >= 2 { t2 = 1 }
38 gv_check("T2 at least two measurable rows exist to difference" as *u8, t2, ctr)
39
40 var t3: i64 = 0
41 if out[TRO_SCANNED] > out[TRO_ROWS] { t3 = 1 }
42 gv_check("T3 cadence rows were present AND filtered (scanned > measurable)" as *u8, t3, ctr)
43
44 let moved: i64 = out[TRO_LAST_CUR] - out[TRO_FIRST_CUR]
45 let booked: i64 = out[TRO_ADVANCE] + out[TRO_AMBIG_CUR]
46 gv_check("T4 CONSERVATION advance + ambiguous == total change in levels earned" as *u8, lg_eq(booked, moved), ctr)
47
48 let szp: *i64 = sys_mmap(16) as *i64
49 let raw: *u8 = ss_readall(logp, szp)
50 var rn: i64 = szp[0]
51 if rn < 0 { rn = 0 }
52 let recorded: i64 = el_last_after(raw, rn, "overall_permil=" as *u8)
53 gv_check("T5 TRIANGULATION our recomputed ratio == the ratio the rollup itself recorded" as *u8, lg_eq(recorded, out[TRO_LAST_PERMIL]), ctr)
54
55 var t6: i64 = 0
56 if out[TRO_DECOMP_PERMIL] >= 0 { if out[TRO_DECOMP_PERMIL] <= TR_PERMIL { t6 = 1 } }
57 gv_check("T6 decomposable coverage is a real permil in 0..1000" as *u8, t6, ctr)
58
59 gv_check("T7 window is complete, not silently truncated (capped=0)" as *u8, lg_eq(out[TRO_CAPPED], 0), ctr)
60
61 var t8: i64 = 0
62 if out[TRO_STABLE_SPANS] >= 0 { if out[TRO_STABLE_SPANS] <= out[TRO_ROWS] - 1 { t8 = 1 } }
63 gv_check("T8 stable-cohort spans cannot exceed the number of transitions" as *u8, t8, ctr)
64
65 _p("\n-- LIVE READING --\n" as *u8)
66 _p(" rows measurable/scanned " as *u8); _fn(1, out[TRO_ROWS]); _p("/" as *u8); _fn(1, out[TRO_SCANNED]); _p("\n" as *u8)
67 _p(" epoch window " as *u8); _fn(1, out[TRO_FIRST_EPOCH]); _p(" -> " as *u8); _fn(1, out[TRO_LAST_EPOCH]); _p("\n" as *u8)
68 _p(" headline permil " as *u8); _fn(1, out[TRO_FIRST_PERMIL]); _p(" -> " as *u8); _fn(1, out[TRO_LAST_PERMIL]); _p("\n" as *u8)
69 _p(" levels earned " as *u8); _fn(1, out[TRO_FIRST_CUR]); _p(" -> " as *u8); _fn(1, out[TRO_LAST_CUR]); _p("\n" as *u8)
70 _p(" bar (denominator) " as *u8); _fn(1, out[TRO_FIRST_BAR]); _p(" -> " as *u8); _fn(1, out[TRO_LAST_BAR]); _p("\n" as *u8)
71 _p(" domains " as *u8); _fn(1, out[TRO_FIRST_DOM]); _p(" -> " as *u8); _fn(1, out[TRO_LAST_DOM]); _p(" (added " as *u8); _fn(1, out[TRO_ADDED_DOM]); _p(")\n" as *u8)
72 _p(" ADVANCEMENT (exact) " as *u8); _fn(1, out[TRO_ADVANCE]); _p(" levels over " as *u8); _fn(1, out[TRO_STABLE_SPANS]); _p(" stable-cohort spans\n" as *u8)
73 _p(" EXPANSION +" as *u8); _fn(1, out[TRO_EXPAND_BAR]); _p(" bar from newly declared domains\n" as *u8)
74 _p(" AMBIGUOUS " as *u8); _fn(1, out[TRO_AMBIG_CUR]); _p(" levels the aggregate ledger cannot attribute\n" as *u8)
75 _p(" decomposable " as *u8); _fn(1, out[TRO_DECOMP_PERMIL]); _p(" permil\n" as *u8)
76 let f: i64 = tr_finding(out)
77 _p(" FINDING " as *u8); _p(tr_finding_label(f)); _p("\n\n" as *u8)
78
79 let done: i64 = gv_verdict("ECOMAT-TREND-LIVE" as *u8, ctr, "invariants hold on the real ledger; FINDING above is the ecosystem state" as *u8)
80 sys_exit(done)
81 return done
82}