code wiki / _hdl_build / nx_galx_shell_jslint_gate.nx

nx_galx_shell_jslint_gate.nx source

↩ module page · 68 lines · 4068 B

1// nx_galx_shell_jslint_gate.nx -- proves the sovereign JS guard (1) CATCHES the exact bug that broke the gallery, 2// (2) does NOT false-positive on the gallery's real tricky JS (regex / concatenation / ?: comparisons), and 3// (3) the CURRENTLY-DEPLOYED shell (shell_root.html) is clean. GREEN iff all five checks agree. 4// license_tier: ORIGINAL 5import "nx_syscalls.nx" 6import "nx_g_puts_lib.nx" 7import "nx_galx_shell_jslint.nx" 8 9func g_num(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%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 } 10func lint_lit(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return jslint_scan_script(s, n) } 11 12func main() -> i64 { 13 g_puts("=== GALX SHELL JS-LINT GATE: catches the broken-string bug, clean on real shell ===\n" as *u8) 14 15 // T1: the EXACT bug class -- a single-quoted HTML attr inside a single-quoted JS string -> must be CAUGHT. 16 let b1: i64 = lint_lit("var s='<a id=pdl href='#' download>x</a>';" as *u8) 17 g_puts(" T1 broken href-in-string caught at offset "); g_num(b1); g_puts(" (expect >=0)\n" as *u8) 18 19 // T2: the FIX (unquoted href=#) -> must be CLEAN. 20 let b2: i64 = lint_lit("var s='<a id=pdl href=# download>x</a>';" as *u8) 21 g_puts(" T2 fixed (href=# unquoted) result "); g_num(b2); g_puts(" (expect -1)\n" as *u8) 22 23 // T3: the gallery's REAL tricky JS (regex + string concatenation + ?: with quoted strings) -> must be CLEAN. 24 let b3: i64 = lint_lit("x.replace(/[<&>]/g,function(c){return c=='<'?'&lt;':c=='>'?'&gt;':'&amp;'});var u='o='+off+'&n='+N;" as *u8) 25 g_puts(" T3 real-shell-pattern (regex+concat+ternary) result "); g_num(b3); g_puts(" (expect -1)\n" as *u8) 26 27 // T4: a plainly unterminated string -> must be CAUGHT. 28 let b4: i64 = lint_lit("var x='abc;" as *u8) 29 g_puts(" T4 unterminated string caught at offset "); g_num(b4); g_puts("\n" as *u8) 30 31 // T5: the CURRENTLY-DEPLOYED shell -> extract <script> + lint -> must be CLEAN. 32 let szp: *i64 = sys_mmap(16) as *i64 33 let html: *u8 = sys_read_file("shell_root.html" as *u8, szp) 34 var b5: i64 = 0 - 2 35 var slen: i64 = 0 - 1 36 if (html as i64) != 0 { 37 let ss: *i64 = sys_mmap(16) as *i64 38 slen = jslint_find_script(html, szp[0], ss) 39 if slen >= 0 { b5 = jslint_scan_script(((html as i64) + ss[0]) as *u8, slen) } 40 } 41 g_puts(" T5 deployed shell: script_len="); g_num(slen); g_puts(" lint="); g_num(b5); g_puts(" (expect script found + -1)\n" as *u8) 42 43 // T6: deployed shell is COMPLETE (doctype..</html>) -> 1. T7: a truncated page -> 0. 44 var c6: i64 = 0 45 if (html as i64) != 0 { c6 = shell_complete(html, szp[0]) } 46 let c7: i64 = shell_complete("<!doctype html><body>oops" as *u8, 25) 47 g_puts(" T6 deployed shell complete="); g_num(c6); g_puts(" (expect 1) T7 truncated="); g_num(c7); g_puts(" (expect 0)\n" as *u8) 48 49 // T8: deployed shell CSS braces balanced -> 1. T9: unbalanced -> 0. 50 var c8: i64 = 0 51 if (html as i64) != 0 { c8 = shell_style_balanced(html, szp[0]) } 52 let c9: i64 = shell_style_balanced("<style>a{b:c</style>" as *u8, 20) 53 g_puts(" T8 deployed shell CSS balanced="); g_num(c8); g_puts(" (expect 1) T9 unbalanced CSS="); g_num(c9); g_puts(" (expect 0)\n" as *u8) 54 55 g_puts("----\n" as *u8) 56 var pass: i64 = 0 57 if b1 >= 0 { pass = pass + 1 } 58 if b2 == 0 - 1 { pass = pass + 1 } 59 if b3 == 0 - 1 { pass = pass + 1 } 60 if b4 >= 0 { pass = pass + 1 } 61 if slen >= 0 { if b5 == 0 - 1 { pass = pass + 1 } } 62 if c6 == 1 { pass = pass + 1 } 63 if c7 == 0 { pass = pass + 1 } 64 if c8 == 1 { pass = pass + 1 } 65 if c9 == 0 { pass = pass + 1 } 66 if pass == 9 { g_puts("GALXSHELLHEALTH GREEN (JS bug caught + real JS clean + shell complete + CSS balanced)\n" as *u8); sys_exit(0); return 0 } 67 g_puts("GALXSHELLHEALTH RED (pass="); g_num(pass); g_puts("/9)\n" as *u8); sys_exit(1); return 1 68}