code wiki / _hdl_build / nx_metric_ledger_gate.nx
nx_metric_ledger_gate.nx source
↩ module page · 39 lines · 3227 B
1// nx_metric_ledger_gate.nx -- proves the return-and-report primitive's trend mechanics. After the first
2// report of a metric (whose verdict depends on ledger history and is NOT asserted -- idempotent, rule #10),
3// every subsequent assert is deterministic: lower-is-better metrics report BETTER on decrease / WORSE on
4// increase / FLAT on equal, higher-is-better the mirror -- and the ledger row round-trips (ml_prev reads
5// back exactly what ml_report appended). RED on any wrong verdict = the feedback loop itself is broken.
6// expect_exit: 0 license_tier: ORIGINAL
7import "nx_metric_ledger.nx"
8import "nx_gate_verdict.nx"
9
10func main() -> i64 {
11 ml_w("=== nx_metric_ledger_gate: return-and-report trend mechanics ===\n" as *u8)
12 var bad: i64 = 0
13 // lower-is-better lane (latency-class)
14 ml_report("mlgate_lat" as *u8, 100, 0 - 1, "us" as *u8, "gate" as *u8) // history-dependent; not asserted
15 if ml_report("mlgate_lat" as *u8, 50, 0 - 1, "us" as *u8, "gate" as *u8) != 2 { bad = bad + 1; ml_w(" FAIL: 100->50 lower-better should be BETTER\n" as *u8) }
16 if ml_report("mlgate_lat" as *u8, 50, 0 - 1, "us" as *u8, "gate" as *u8) != 1 { bad = bad + 1; ml_w(" FAIL: 50->50 should be FLAT\n" as *u8) }
17 if ml_report("mlgate_lat" as *u8, 80, 0 - 1, "us" as *u8, "gate" as *u8) != (0 - 1) { bad = bad + 1; ml_w(" FAIL: 50->80 lower-better should be WORSE\n" as *u8) }
18 // higher-is-better lane (fps-class)
19 ml_report("mlgate_fps" as *u8, 10, 1, "fps" as *u8, "gate" as *u8) // history-dependent; not asserted
20 if ml_report("mlgate_fps" as *u8, 20, 1, "fps" as *u8, "gate" as *u8) != 2 { bad = bad + 1; ml_w(" FAIL: 10->20 higher-better should be BETTER\n" as *u8) }
21 if ml_report("mlgate_fps" as *u8, 5, 1, "fps" as *u8, "gate" as *u8) != (0 - 1) { bad = bad + 1; ml_w(" FAIL: 20->5 higher-better should be WORSE\n" as *u8) }
22 // negative-value round-trip (parse sign path)
23 ml_report("mlgate_neg" as *u8, 0 - 7, 1, "d" as *u8, "gate" as *u8)
24 if ml_report("mlgate_neg" as *u8, 0 - 3, 1, "d" as *u8, "gate" as *u8) != 2 { bad = bad + 1; ml_w(" FAIL: -7->-3 higher-better should be BETTER\n" as *u8) }
25 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, ENRICHMENT form). This gate
26 // enumerated NO checks -- it printed one summary line -- and the base class REFUSES to emit
27 // GREEN with zero checks (gv_verdict requires ctr[1] > 0), which is right: a gate that checked
28 // nothing must not read GREEN. So the only expressible migration enumerates the gate's OWN
29 // GREEN condition as exactly ONE check -- the guard below is copied verbatim, not rewritten.
30 // The PASS/FAIL vector therefore goes 0 -> 1. That is an ENRICHMENT, not a divergence, and
31 // nx_gate_migrate accepts it only because exit code and judge verdict are both preserved.
32 var t1__dry: i64 = 0
33 if bad == 0 { t1__dry = 1 }
34 let ctr__dry: *i64 = gv_ctr()
35 gv_check("original GREEN condition (enumerated by nx_gate_dry_apply; the gate itself counted nothing)" as *u8, t1__dry, ctr__dry)
36 let rc__dry: i64 = gv_verdict("METRIC-LEDGER-GATE" as *u8, ctr__dry, "the feedback loop mechanics are proven" as *u8)
37 sys_exit(rc__dry)
38 return rc__dry
39}