code wiki / _hdl_build / nx_connect_ui_gate.nx

nx_connect_ui_gate.nx source

↩ module page · 191 lines · 9756 B

1// nx_connect_ui_gate.nx -- the gate for the CONNECT app-tier UI emitter (nx_connect_ui). 2// Every tooth asserts on the ACTUAL EMITTED BYTES, and the accessibility/safety teeth carry negative 3// controls so a passing verdict cannot be vacuous. license_tier: ORIGINAL expect_exit: 0 4import "nx_syscalls.nx" 5import "nx_connect_ui.nx" 6 7const G_BUF: i64 = 262144 8 9func g_p(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 10func g_pn(v: i64) -> i64 { 11 let t: *u8 = sys_mmap(32) 12 var o: i64 = cu_putn(t, 0, v) 13 t[o] = 0 as u8 14 g_p(t) 15 return 0 16} 17// count non-overlapping occurrences of needle in buf[0..n) 18func g_count(buf: *u8, n: i64, needle: *u8) -> i64 { 19 let m: i64 = cu_slen(needle) 20 var hits: i64 = 0 21 var i: i64 = 0 22 if m <= 0 { return 0 } 23 while i + m <= n { 24 var k: i64 = 0 25 var ok: i64 = 1 26 while k < m { if buf[i + k] != needle[k] { ok = 0; k = m } else { k = k + 1 } } 27 if ok == 1 { hits = hits + 1; i = i + m } else { i = i + 1 } 28 } 29 return hits 30} 31func g_has(buf: *u8, n: i64, needle: *u8) -> i64 { if g_count(buf, n, needle) > 0 { return 1 } return 0 } 32 33func g_tooth(name: *u8, pass: i64, fails: *i64) -> i64 { 34 g_p(" " as *u8); g_p(name); g_p(": " as *u8) 35 if pass == 1 { g_p("PASS\n" as *u8) } else { g_p("FAIL\n" as *u8); fails[0] = fails[0] + 1 } 36 return 0 37} 38 39func main() -> i64 { 40 let b: *u8 = sys_mmap(G_BUF) 41 let fails: *i64 = (sys_mmap(8)) as *i64 42 fails[0] = 0 43 g_p("=== nx_connect_ui_gate -- the CONNECT app-tier UI emitter, asserted on emitted bytes ===\n" as *u8) 44 45 // ---- T1: document shell carries the nishi_ds token SSOT + the ADA landmarks ---- 46 var n: i64 = cu_head(b, 0, "Connect" as *u8) 47 n = cu_bar_open(b, n, "Connect" as *u8, "/connect" as *u8) 48 n = cu_tab(b, n, "Home" as *u8, "/connect" as *u8, 1) 49 n = cu_tab(b, n, "Chat" as *u8, "/connect/chat" as *u8, 0) 50 n = cu_tab(b, n, "Events" as *u8, "/connect/events" as *u8, 0) 51 n = cu_bar_close(b, n) 52 n = cu_h1(b, n, "Connect" as *u8, "lede" as *u8) 53 n = cu_foot(b, n, "footer" as *u8) 54 var t1: i64 = 1 55 if g_has(b, n, "<!DOCTYPE html>" as *u8) == 0 { t1 = 0 } 56 if g_has(b, n, "<html lang=\"en\">" as *u8) == 0 { t1 = 0 } 57 if g_has(b, n, "width=device-width" as *u8) == 0 { t1 = 0 } 58 if g_has(b, n, "class=\"skip\" href=\"#main\"" as *u8) == 0 { t1 = 0 } 59 if g_has(b, n, "<main id=\"main\">" as *u8) == 0 { t1 = 0 } 60 if g_has(b, n, "<footer class=\"nx\">" as *u8) == 0 { t1 = 0 } 61 // the canonical design-system tokens -- proves we inherited nishi_ds instead of inventing a palette 62 if g_has(b, n, "--accent:#7aa2ff" as *u8) == 0 { t1 = 0 } 63 if g_has(b, n, "--surface:#141a29" as *u8) == 0 { t1 = 0 } 64 if g_has(b, n, "prefers-color-scheme:light" as *u8) == 0 { t1 = 0 } 65 if g_has(b, n, "prefers-reduced-motion:reduce" as *u8) == 0 { t1 = 0 } 66 if g_has(b, n, ":focus-visible" as *u8) == 0 { t1 = 0 } 67 g_tooth("T1 shell: doctype/lang/viewport/skip-link/main/footer + nishi_ds tokens + dual-theme + reduced-motion" as *u8, t1, fails) 68 69 // ---- T2: ZERO JavaScript and ZERO external assets, by construction ---- 70 var t2: i64 = 1 71 if g_has(b, n, "<script" as *u8) == 1 { t2 = 0 } 72 if g_has(b, n, "http://" as *u8) == 1 { t2 = 0 } 73 if g_has(b, n, "https://" as *u8) == 1 { t2 = 0 } 74 if g_has(b, n, "onclick" as *u8) == 1 { t2 = 0 } 75 g_tooth("T2 sovereign surface: no <script>, no remote asset, no inline handler (renders offline)" as *u8, t2, fails) 76 77 // ---- T3: exactly ONE tab is aria-current=page ---- 78 var t3: i64 = 1 79 if g_count(b, n, "aria-current=\"page\"" as *u8) != 1 { t3 = 0 } 80 if g_count(b, n, "<a href=\"/connect/chat\">" as *u8) != 1 { t3 = 0 } 81 g_tooth("T3 nav: exactly one tab marked aria-current=page; inactive tabs unmarked" as *u8, t3, fails) 82 83 // ---- T4: cu_putn is allocation-free and correct ---- 84 var t4: i64 = 1 85 var pn: i64 = cu_putn(b, 0, 0) 86 pn = cu_putn(b, pn, 7) 87 pn = cu_putn(b, pn, 42) 88 pn = cu_putn(b, pn, 857) 89 pn = cu_putn(b, pn, 1000) 90 b[pn] = 0 as u8 91 if pn != 11 { t4 = 0 } // "0"+"7"+"42"+"857"+"1000" = 1+1+2+3+4 bytes 92 if g_has(b, pn, "07428571000" as *u8) == 0 { t4 = 0 } 93 g_tooth("T4 cu_putn: 0/7/42/857/1000 render exactly, no scratch buffer, no syscall" as *u8, t4, fails) 94 95 // ---- T5: escaping, with the XSS negative control ---- 96 let hostile: *u8 = "<script>alert(\"x\")</script> & done" as *u8 97 var en: i64 = cu_esc(b, 0, hostile) 98 b[en] = 0 as u8 99 var t5: i64 = 1 100 if g_has(b, en, "<script>" as *u8) == 1 { t5 = 0 } 101 if g_has(b, en, "&lt;script&gt;" as *u8) == 0 { t5 = 0 } 102 if g_has(b, en, "&quot;" as *u8) == 0 { t5 = 0 } 103 if g_has(b, en, "&amp; done" as *u8) == 0 { t5 = 0 } 104 // NEG-CONTROL: the same bytes emitted RAW would carry the live tag -> proves the escaper is load-bearing 105 var rn: i64 = cu_puts(b, en + 1, hostile) 106 var neg: i64 = 0 107 if g_count(b, rn, "<script>" as *u8) == 1 { neg = 1 } 108 if neg == 0 { t5 = 0 } 109 g_tooth("T5 cu_esc escapes &<>\" (NEG-CONTROL: the same bytes raw DO carry a live <script>)" as *u8, t5, fails) 110 111 // ---- T6: a chat bubble keeps the ORIGINAL beside the translation, and escapes user text ---- 112 var m: i64 = cu_thread_open(b, 0) 113 m = cu_bubble_open(b, m, "Vera" as *u8, 0, "<b>привет</b> друг" as *u8) 114 m = cu_bubble_tr(b, m, "hello friend" as *u8) 115 m = cu_bubble_corr(b, m, "привет, друг" as *u8) 116 m = cu_bubble_close(b, m) 117 m = cu_thread_close(b, m) 118 var t6: i64 = 1 119 if g_has(b, m, "&lt;b&gt;привет&lt;/b&gt; друг" as *u8) == 0 { t6 = 0 } // original preserved, escaped 120 if g_has(b, m, "hello friend" as *u8) == 0 { t6 = 0 } // translation present 121 if g_has(b, m, "class=\"co\">corrected:" as *u8) == 0 { t6 = 0 } // correction attached 122 if g_has(b, m, "<b>привет</b>" as *u8) == 1 { t6 = 0 } // no raw markup survived 123 g_tooth("T6 bubble: translation renders BESIDE the escaped original, correction attaches (learning loop intact)" as *u8, t6, fails) 124 125 // ---- T7: label[for] is paired with control[id] BY CONSTRUCTION ---- 126 var f: i64 = cu_form_open(b, 0, "/connect/say" as *u8) 127 f = cu_input(b, f, "text" as *u8, "Message" as *u8, "Write something" as *u8, 100) 128 f = cu_select_open(b, f, "speaker" as *u8, "Speaking as" as *u8) 129 f = cu_option(b, f, "vera" as *u8, "Vera" as *u8) 130 f = cu_select_close(b, f) 131 f = cu_submit(b, f, "Send" as *u8) 132 f = cu_form_close(b, f) 133 var t7: i64 = 1 134 if g_has(b, f, "<label for=\"text\">" as *u8) == 0 { t7 = 0 } 135 if g_has(b, f, "<input id=\"text\" name=\"text\"" as *u8) == 0 { t7 = 0 } 136 if g_has(b, f, "<label for=\"speaker\">" as *u8) == 0 { t7 = 0 } 137 if g_has(b, f, "<select id=\"speaker\" name=\"speaker\">" as *u8) == 0 { t7 = 0 } 138 if g_has(b, f, "maxlength=\"100\"" as *u8) == 0 { t7 = 0 } 139 g_tooth("T7 forms: every control carries a matching label[for]/id pair + maxlength (unlabelled field impossible)" as *u8, t7, fails) 140 141 // ---- T8: the meter is integer-only and CLAMPS ---- 142 var q: i64 = cu_meter(b, 0, "Library" as *u8, 3, 4) // 75% 143 q = cu_meter(b, q, "Overflow" as *u8, 9, 4) // clamps to 100% 144 q = cu_meter(b, q, "NoDenom" as *u8, 5, 0) // divide-by-zero guarded -> 0% 145 var t8: i64 = 1 146 if g_has(b, q, "width:75%" as *u8) == 0 { t8 = 0 } 147 if g_has(b, q, "width:100%" as *u8) == 0 { t8 = 0 } 148 if g_has(b, q, "width:0%" as *u8) == 0 { t8 = 0 } 149 g_tooth("T8 meter: 3/4 -> 75%, over-max clamps to 100%, max=0 guarded to 0% (integer math, no float)" as *u8, t8, fails) 150 151 // ---- T9: avatars are deterministic and collision-aware, with no external image ---- 152 var a1: i64 = cu_avatar(b, 0, "Vera" as *u8, 0) 153 b[a1] = 0 as u8 154 let s1: *u8 = sys_mmap(1024) 155 var c: i64 = 0 156 while c < a1 { s1[c] = b[c]; c = c + 1 } 157 s1[a1] = 0 as u8 158 var a2: i64 = cu_avatar(b, 0, "Vera" as *u8, 0) 159 var t9: i64 = 1 160 if a2 != a1 { t9 = 0 } 161 var same: i64 = 1 162 c = 0 163 while c < a1 { if b[c] != s1[c] { same = 0 } c = c + 1 } 164 if same == 0 { t9 = 0 } // deterministic: same name -> same bytes 165 var a3: i64 = cu_avatar(b, 0, "Piotr" as *u8, 0) 166 b[a3] = 0 as u8 167 var diff: i64 = 0 168 c = 0 169 while c < a3 { if c < a1 { if b[c] != s1[c] { diff = 1 } } c = c + 1 } 170 if diff == 0 { t9 = 0 } // distinct names -> distinct gradient 171 if g_has(b, a3, "<img" as *u8) == 1 { t9 = 0 } // never an external image 172 if g_has(b, a3, "P</span>" as *u8) == 0 { t9 = 0 } // initial rendered, uppercased 173 g_tooth("T9 avatar: deterministic per name, distinct across names, initial uppercased, zero <img>" as *u8, t9, fails) 174 175 // ---- T10: banners announce to assistive tech and carry the right severity ---- 176 var v: i64 = cu_banner(b, 0, 2, "RSVP refused" as *u8, "two adults required" as *u8) 177 v = cu_banner(b, v, 1, "Saved" as *u8, "ok" as *u8) 178 var t10: i64 = 1 179 if g_has(b, v, "role=\"status\"" as *u8) == 0 { t10 = 0 } 180 if g_has(b, v, "ban-bad" as *u8) == 0 { t10 = 0 } 181 if g_has(b, v, "ban-good" as *u8) == 0 { t10 = 0 } 182 g_tooth("T10 banner: role=status announced, severity class matches the outcome" as *u8, t10, fails) 183 184 g_p(" fails=" as *u8); g_pn(fails[0]); g_p("\n" as *u8) 185 if fails[0] == 0 { 186 g_p("VERDICT: verdict=GREEN (app-tier UI emitter: nishi_ds tokens, ADA by construction, escaped, 0-JS)\n" as *u8) 187 return 0 188 } 189 g_p("VERDICT: verdict=RED\n" as *u8) 190 return 1 191}