code wiki / (root) / nx_brand_apply_enforced.nx

nx_brand_apply_enforced.nx source

↩ module page · 98 lines · 5927 B

1// nx_brand_apply_enforced.nx -- the "gorgeous-by-default" ENFORCEMENT gate (operationalizes nx_emitter_bench). 2// So we GET s-class-exceed instead of hoping for it: this is a reusable PASS/FAIL an emitter compile-gate 3// calls on its output HTML. It FAILS any page that isn't on the design-system adoption bar, so no emitter 4// can ship an off-SSOT / un-responsive / inaccessible page again. Composes nx_uxcx_grade's pure byte-scan 5// (uxg_has_lit) -- no reinvention. Proven here against REAL emitted pages: the tokenized site-builder 6// pipeline PASSES, a bare legacy page FAILS (neg-control), and it pinpoints each page's specific gap. 7// 8// THE BAR (the 6 "gorgeous-by-default" invariants, each an HTML-observable signal): 9// 1 canonical design tokens (var(--nx-*), the shared SSOT) 2 responsive (@media(max-width) 10// 3 accessible motion (prefers-reduced-motion) 4 keyboard a11y (:focus-visible) 11// 5 sovereign (no external http asset) 6 semantic landmarks (<header + <footer) 12// (skip-link is reported as a WARN, not gated -- it's the site-builder's one remaining a11y polish item.) 13// 100% sovereign. license_tier: ORIGINAL expect_exit: 0 14import "nx_syscalls_x86_64.nx" 15import "nx_sclass_enforce_lib.nx" 16 17func ew(s: *u8) -> i64 { var n: i64=0; while s[n]!=0 { n=n+1 } sys_write(1,s,n); return 0 } 18func en(v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m;sys_write(1,"-" as *u8,1)} let t: *u8=sys_mmap(28); var k: i64=0; if m==0{t[0]=48 as u8;k=1} while m>0{t[k]=(48+(m-(m/10)*10)) as u8;m=m/10;k=k+1} var i: i64=0; while i<k{bb[i]=t[k-1-i];i=i+1} sys_write(1,bb,k); return 0 } 19 20// count of the 6 bar-invariants a page VIOLATES -- delegates to the ONE canonical check (no dup logic). 21func violations(h: *u8, n: i64) -> i64 { return sce_violations(h, n) } 22func list_violations(h: *u8, n: i64) -> i64 { 23 if sce_tokens(h,n)==0 { ew(" canonical-tokens" as *u8) } 24 if sce_responsive(h,n)==0 { ew(" responsive" as *u8) } 25 if sce_motion(h,n)==0 { ew(" reduced-motion" as *u8) } 26 if sce_focus(h,n)==0 { ew(" focus-visible" as *u8) } 27 if sce_sovereign(h,n)==0 { ew(" sovereign" as *u8) } 28 if sce_landmarks(h,n)==0 { ew(" landmarks" as *u8) } 29 if sce_skiplink(h,n)==0 { ew(" (warn:skip-link)" as *u8) } 30 return 0 31} 32 33// read a page, print its enforce verdict, return violation count (-1 if missing). 34func audit(name: *u8, path: *u8) -> i64 { 35 let len_p: *i64 = sys_mmap(8) as *i64 36 let h: *u8 = sys_read_file_x86_64(path, len_p) 37 ew(" " as *u8); ew(name) 38 if h == (0 as *u8) { ew(": (missing)\n" as *u8); return 0-1 } 39 let n: i64 = len_p[0] 40 let v: i64 = violations(h,n) 41 ew(": " as *u8) 42 if v==0 { ew("PASS (compliant)" as *u8) } else { ew("FAIL viol=" as *u8); en(v); ew(" ->" as *u8); list_violations(h,n) } 43 ew("\n" as *u8) 44 return v 45} 46 47func tcheck(pass: i64, label: *u8, fails: *i64) -> i64 { 48 ew(" " as *u8); ew(label); ew(": " as *u8) 49 if pass==1 { ew("PASS\n" as *u8) } else { ew("FAIL\n" as *u8); fails[0]=fails[0]+1 } 50 return 0 51} 52 53func main() -> i64 { 54 let fails: *i64 = sys_mmap(16) as *i64 55 fails[0]=0 56 57 ew("=== nx_brand_apply_enforced -- gorgeous-by-default enforcement gate ===\n" as *u8) 58 ew("bar: canonical --nx- tokens + responsive + reduced-motion + focus-visible + sovereign + semantic landmarks\n" as *u8) 59 ew("-- audit real emitted pages --\n" as *u8) 60 let v_demo: i64 = audit("site_provision:demo (tokenized)" as *u8, "web_assets/site_demo/index.html" as *u8) 61 let v_law: i64 = audit("site_provision:law (tokenized)" as *u8, "web_assets/_aw_pages_gate/index.html" as *u8) 62 let v_lds: i64 = audit("nx_connect_lds_page (hand) " as *u8, "web_assets/lds_connect.html" as *u8) 63 let v_prod: i64 = audit("hub/products (legacy, bare) " as *u8, "web_assets/products.html" as *u8) 64 let v_youth: i64 = audit("youth_page (kit-composed) " as *u8, "web_assets/lds_youth.html" as *u8) 65 66 // synthetic bare page -> the enforcer must flag it heavily (non-vacuous) 67 let bare: *u8 = "<!DOCTYPE html><html><head><title>x</title></head><body><p>hi</p></body></html>" as *u8 68 var bn: i64 = 0 69 while bare[bn] != 0 { bn = bn + 1 } 70 let v_bare: i64 = violations(bare, bn) 71 72 ew("-- gate checks --\n" as *u8) 73 // T1: the tokenized site-builder pipeline PASSES the design-adoption bar (0 violations) 74 var t1: i64=0; if v_demo==0 { if v_law==0 { t1=1 } } 75 tcheck(t1, "T1 tokenized site-builder pages PASS (on the --nx- SSOT, responsive, a11y)" as *u8, fails) 76 // T2: NEG-CONTROL a bare legacy page is CAUGHT (multiple violations) 77 var t2: i64=0; if v_prod>=3 { t2=1 } 78 tcheck(t2, "T2 NEG-CONTROL bare legacy page FAILS (caught, not shipped)" as *u8, fails) 79 // T3: the enforcer discriminates -- bare > compliant 80 var t3: i64=0; if v_prod>v_demo { t3=1 } 81 tcheck(t3, "T3 enforcer discriminates (bare violations > compliant)" as *u8, fails) 82 // T4: the hand page is now COMPLIANT after adopting the --nx- SSOT (beautiful AND s-class) 83 var t4: i64=0; if v_lds==0 { t4=1 } 84 tcheck(t4, "T4 hand page now COMPLIANT after adopting the --nx- SSOT (beautiful AND s-class)" as *u8, fails) 85 // T5: non-vacuous on a synthetic bare page 86 var t5: i64=0; if v_bare>=5 { t5=1 } 87 tcheck(t5, "T5 non-vacuous: synthetic bare page flagged heavily" as *u8, fails) 88 89 // T6: a page composed from nx_sclass_kit passes by construction (reusable capability proven) 90 var t6: i64=0; if v_youth==0 { t6=1 } 91 tcheck(t6, "T6 kit-composed page PASSES by construction (nx_sclass_kit -> reusable s-class)" as *u8, fails) 92 93 ew(" fails=" as *u8); en(fails[0]); ew("\n" as *u8) 94 if fails[0]==0 { ew("VERDICT: GREEN (enforcer PASSES the tokenized pipeline, CATCHES bare pages, pinpoints each gap -> wire into emitter compile-gates)\n" as *u8); sys_exit(0) } 95 ew("VERDICT: RED\n" as *u8) 96 sys_exit(1) 97 return 1 98}