code wiki / (root) / nx_intake_form_gate.nx

nx_intake_form_gate.nx source

↩ module page · 65 lines · 3249 B

1// nx_intake_form_gate.nx -- proves the intake form is a sovereign zero-JS native-POST form whose field names 2// match nx_intake_handler, framed for accommodation. Exits 0 iff ALL pass. license_tier: ORIGINAL 3import "nx_syscalls.nx" 4import "nx_intake_form.nx" 5 6func g_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 7func g_putn(v: i64) -> i64 { 8 if v == 0 { sys_write(1, "0" as *u8, 1); return 0 } 9 var m: i64 = v; if m < 0 { sys_write(1, "-" as *u8, 1); m = 0 - m } 10 let d: *u8 = sys_mmap(24); var k: i64 = 0 11 while m > 0 { d[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 12 var j: i64 = k - 1 13 while j >= 0 { sys_write(1, ((d as i64)+j) as *u8, 1); j = j - 1 } 14 return 0 15} 16func chk(name: *u8, got: i64, want: i64, st: *i64) -> i64 { 17 if got == want { st[0] = st[0] + 1; g_puts(" PASS "); g_puts(name); g_puts("\n") } 18 else { st[1] = st[1] + 1; g_puts(" FAIL "); g_puts(name); g_puts(" got="); g_putn(got); g_puts(" want="); g_putn(want); g_puts("\n") } 19 return 0 20} 21func gfind(hay: *u8, n: i64, needle: *u8) -> i64 { 22 var nl: i64 = 0; while needle[nl] != (0 as u8) { nl = nl + 1 } 23 if nl == 0 { return 0 } 24 var i: i64 = 0 25 while i + nl <= n { 26 var j: i64 = 0; var ok: i64 = 1 27 while j < nl { if hay[i + j] != needle[j] { ok = 0; j = nl } else { j = j + 1 } } 28 if ok == 1 { return i } 29 i = i + 1 30 } 31 return 0 - 1 32} 33func has(hay: *u8, n: i64, needle: *u8) -> i64 { if gfind(hay, n, needle) >= 0 { return 1 } return 0 } 34 35func main() -> i64 { 36 let st: *i64 = sys_mmap(16) as *i64 37 st[0] = 0; st[1] = 0 38 let buf: *u8 = sys_mmap(65536) 39 let n: i64 = if_render(buf) 40 g_puts(" [info] intake form bytes="); g_putn(n); g_puts("\n") 41 42 var nojs: i64 = 0 43 if gfind(buf, n, "<script\x00" as *u8) < 0 { nojs = 1 } 44 chk("zero <script (sovereign zero-JS form)", nojs, 1, st) 45 chk("native POST to the handler route", has(buf, n, "method=\"post\" action=\"/finance/intake\"\x00" as *u8), 1, st) 46 chk("field name=income_monthly", has(buf, n, "name=\"income_monthly\"\x00" as *u8), 1, st) 47 chk("field name=debt_balance", has(buf, n, "name=\"debt_balance\"\x00" as *u8), 1, st) 48 chk("field name=hourly_wage", has(buf, n, "name=\"hourly_wage\"\x00" as *u8), 1, st) 49 chk("field name=has_adhd", has(buf, n, "name=\"has_adhd\"\x00" as *u8), 1, st) 50 chk("field name=low_energy", has(buf, n, "name=\"low_energy\"\x00" as *u8), 1, st) 51 chk("submit button present", has(buf, n, "Save my situation\x00" as *u8), 1, st) 52 chk("ADHD accommodation framing (one thing at a time)", has(buf, n, "one thing at a time\x00" as *u8), 1, st) 53 chk("plain-language reassurance (nothing is shared)", has(buf, n, "nothing is shared\x00" as *u8), 1, st) 54 var lok: i64 = 0 55 if n > 1200 { lok = 1 } 56 chk("complete form (> 1200 bytes)", lok, 1, st) 57 var term: i64 = 0 58 if buf[n] == (0 as u8) { term = 1 } 59 chk("NUL-terminated", term, 1, st) 60 61 g_puts("nx_intake_form_gate: PASS="); g_putn(st[0]); g_puts(" FAIL="); g_putn(st[1]); g_puts("\n") 62 if st[1] == 0 { g_puts("SITUATION R6 nx_intake_form: GREEN\n"); return 0 } 63 g_puts("SITUATION R6 nx_intake_form: RED\n") 64 return 1 65}