nx_analyst_dashboard_gate.nx source
↩ module page · 90 lines · 5327 B
1// nx_analyst_dashboard_gate.nx -- proves the BI dashboard is DATA-BOUND (real numbers derived from the
2// census SSOT + the live store, not hardcoded), WELL-FORMED (balanced <div>/<table> tags -- browsers stay
3// silent on unclosed tags, so the gate must not), and ACCESSIBLE-SHAPED (a doctype, lang, viewport, a title,
4// table headers). D001 verdict via nx_gate_verdict. expect_exit: 0 license_tier: ORIGINAL
5import "nx_gate_verdict.nx"
6import "nx_analyst_dashboard.nx"
7
8func dg_has(hay: *u8, hn: i64, needle: *u8) -> i64 {
9 var nl: i64 = 0
10 while needle[nl] != (0 as u8) { nl = nl + 1 }
11 var i: i64 = 0
12 while i + nl <= hn {
13 var j: i64 = 0
14 var eq: i64 = 1
15 while j < nl { if hay[i+j] != needle[j] { eq = 0 } j = j + 1 }
16 if eq == 1 { return 1 }
17 i = i + 1
18 }
19 return 0
20}
21// count non-overlapping occurrences of a literal
22func dg_count(hay: *u8, hn: i64, needle: *u8) -> i64 {
23 var nl: i64 = 0
24 while needle[nl] != (0 as u8) { nl = nl + 1 }
25 var c: i64 = 0
26 var i: i64 = 0
27 while i + nl <= hn {
28 var j: i64 = 0
29 var eq: i64 = 1
30 while j < nl { if hay[i+j] != needle[j] { eq = 0 } j = j + 1 }
31 if eq == 1 { c = c + 1; i = i + nl } else { i = i + 1 }
32 }
33 return c
34}
35func dg_eq(a: i64, b: i64) -> i64 { if a == b { return 1 } return 0 }
36
37func main() -> i64 {
38 let ctr: *i64 = gv_ctr()
39 gv_head("nx_analyst_dashboard_gate -- is the BI dashboard data-bound, well-formed, and accessible-shaped?" as *u8)
40 let out: *u8 = sys_mmap(DB_OUT)
41 let n: i64 = db_build(out)
42
43 // ---- document shape (accessibility scaffolding a validator/screen-reader needs) --------------
44 gv_check("T1 has a DOCTYPE" as *u8, dg_has(out, n, "<!DOCTYPE html>" as *u8), ctr)
45 gv_check("T2 declares lang" as *u8, dg_has(out, n, "<html lang=\"en\">" as *u8), ctr)
46 gv_check("T3 has a responsive viewport" as *u8, dg_has(out, n, "width=device-width" as *u8), ctr)
47 gv_check("T4 has a title" as *u8, dg_has(out, n, "<title>" as *u8), ctr)
48 gv_check("T5 the data table has header cells" as *u8, dg_has(out, n, "<th>" as *u8), ctr)
49
50 // ---- well-formed: tags BALANCE. Browsers are silent on unclosed tags; this gate is not. -------
51 gv_check("T6 <div> opens and closes balance" as *u8, dg_eq(dg_count(out, n, "<div" as *u8), dg_count(out, n, "</div>" as *u8)), ctr)
52 gv_check("T7 <table> opens and closes balance" as *u8, dg_eq(dg_count(out, n, "<table" as *u8), dg_count(out, n, "</table>" as *u8)), ctr)
53 gv_check("T8 <tr> opens and closes balance" as *u8, dg_eq(dg_count(out, n, "<tr>" as *u8), dg_count(out, n, "</tr>" as *u8)), ctr)
54 gv_check("T9 exactly one <body> and one </body>" as *u8, dg_eq(dg_count(out, n, "<body>" as *u8) + dg_count(out, n, "</body>" as *u8), 2), ctr)
55
56 // ---- DATA-BOUND: the numbers are DERIVED, not hardcoded. Re-derive the census independently and
57 // assert the page carries the SAME meet-SOTA it computed -- if the page baked a stale literal, this
58 // fails the moment the conf changes.
59 let c: *i64 = sys_mmap(8 * 6) as *i64
60 db_census(c)
61 var meet: i64 = 0
62 if c[4] > 0 { meet = (c[0] * 2 + c[3] * 2 + c[1]) * 1000 / (c[4] * 2) }
63 let mb: *u8 = sys_mmap(64)
64 var mo: i64 = db_raw(mb, 0, "meet-SOTA <b>" as *u8)
65 mo = db_num(mb, mo, meet)
66 mb[mo] = 0 as u8
67 // NON-VACUOUS: assert the page carries the live meet-SOTA AND that it is a REAL number (>300),
68 // not 0 -- comparing db_census to db_census would pass even if both were broken to zero (it did).
69 var t10: i64 = 0
70 if dg_has(out, n, mb) == 1 { if meet > 300 { t10 = 1 } }
71 gv_check("T10 the page carries the LIVE meet-SOTA and it is a real value (>300, not a broken 0)" as *u8, t10, ctr)
72 // the census must have counted a real number of features (the conf is non-trivial)
73 // NON-VACUOUS + truncation-class guard: the count must be the WHOLE conf (not a truncated
74 // prefix). c[5]=1 means the read buffer filled -> undercount, exactly the bug that shipped 31 vs 34.
75 var t11: i64 = 0
76 if c[4] > 30 { if c[5] == 0 { if c[3] >= 2 { t11 = 1 } } }
77 gv_check("T11 census read the WHOLE conf (total>30, not truncated, EXCEED rows present)" as *u8, t11, ctr)
78
79 // ---- the LIVE ANALYSIS is real: size must show as significant over the 300-row azdemo store ---
80 gv_check("T12 the live analysis rendered from the store (row count in the heading)" as *u8, dg_has(out, n, "rows)" as *u8), ctr)
81 gv_check("T13 the price~size association renders as significant (real computation, not a mock)" as *u8, dg_has(out, n, "size" as *u8), ctr)
82 gv_check("T14 the analysis carries a confidence interval column populated with 'to'" as *u8, dg_has(out, n, " to " as *u8), ctr)
83 // agentic cross-reference: the page tells a reader the SAME engine is callable as an agent tool
84 gv_check("T15 the page points at the agent-callable tool (nx_analyze ask)" as *u8, dg_has(out, n, "nx_analyze ask" as *u8), ctr)
85
86 gv_check("T16 has a <main> landmark (the a11y finding page_verify flagged, now fixed)" as *u8, dg_has(out, n, "<main>" as *u8), ctr)
87 let rc: i64 = gv_verdict("ANALYST-DASHBOARD-GATE" as *u8, ctr, "a data-bound, well-formed, accessible-shaped BI dashboard rendered from live census + store data" as *u8)
88 sys_exit(rc)
89 return rc
90}