code wiki / _hdl_build / nx_golive_gate.nx

nx_golive_gate.nx source

↩ module page · 98 lines · 5737 B

1// nx_golive_gate.nx -- gate for the one-command go-live DRIVER (nx_golive). OFFLINE-deterministic 2// teeth for the driver's NEW logic: the dollars->cents quote parser, the JSON value readers, and the 3// honest-stop discrimination (a live-captured INSUFFICIENT_FUNDS body must NEVER read as a SUCCESS 4// that would let the pipeline advance to spend). The LIVE walk was proven 2026-07-09 (artifact 5// knowledge/compare/staging/golive_run.out): CHECK -> auto-quote 1108c -> CAP OK -> DRYRUN -> honest 6// STOP (server preflight 400, zero charge). license_tier: ORIGINAL expect_exit: 0 7import "nx_golive.nx" 8 9func gg_w(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 10func gg_n(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 } 11func gg_check(pass: i64, label: *u8, fails: *i64) -> i64 { 12 gg_w(" " as *u8); gg_w(label); gg_w(": " as *u8) 13 if pass==1 { gg_w("PASS\n" as *u8) } else { gg_w("FAIL\n" as *u8); fails[0]=fails[0]+1 } 14 return 0 15} 16// wrap a JSON body string as a minimal HTTP response so gl_body/parse find it 17func gg_wrap(body: *u8, out: *u8) -> i64 { 18 var o: i64 = pk_put(out, 0, "HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n\r\n" as *u8) 19 o = pk_put(out, o, body) 20 return o 21} 22 23func main() -> i64 { 24 let fails: *i64 = sys_mmap(16) as *i64 25 fails[0]=0 26 gg_w("=== nx_golive_gate -- one-command driver: quote parser + JSON readers + honest-stop ===\n" as *u8) 27 28 // T1: dollars->cents across the real shapes 29 let d1: *u8 = "11.08" as *u8 30 let d2: *u8 = "9.73" as *u8 31 let d3: *u8 = "11" as *u8 32 let d4: *u8 = "11.5" as *u8 33 let d5: *u8 = "0.99" as *u8 34 var t1: i64=1 35 if gl_dollars_to_cents(d1, 0, 5)!=1108 { t1=0 } 36 if gl_dollars_to_cents(d2, 0, 4)!=973 { t1=0 } 37 if gl_dollars_to_cents(d3, 0, 2)!=1100 { t1=0 } 38 if gl_dollars_to_cents(d4, 0, 4)!=1150 { t1=0 } 39 if gl_dollars_to_cents(d5, 0, 4)!=99 { t1=0 } 40 gg_w(" 11.08->" as *u8); gg_n(gl_dollars_to_cents(d1,0,5)) 41 gg_w(" 9.73->" as *u8); gg_n(gl_dollars_to_cents(d2,0,4)) 42 gg_w(" 11->" as *u8); gg_n(gl_dollars_to_cents(d3,0,2)) 43 gg_w(" 11.5->" as *u8); gg_n(gl_dollars_to_cents(d4,0,4)) 44 gg_w(" 0.99->" as *u8); gg_n(gl_dollars_to_cents(d5,0,4)); gg_w("\n" as *u8) 45 gg_check(t1, "T1 dollars->cents: 11.08/9.73/11/11.5/0.99 all exact" as *u8, fails) 46 47 // T2: gl_json_cents on a real checkDomain body extracts the quote 48 let chk: *u8 = "{\"status\":\"SUCCESS\",\"response\":{\"avail\":\"yes\",\"type\":\"registration\",\"price\":\"11.08\",\"regularPrice\":\"11.08\"}}" as *u8 49 let wrap: *u8 = sys_mmap(1024) 50 let wn: i64 = gg_wrap(chk, wrap) 51 let cents: i64 = gl_json_cents(wrap, wn, "price" as *u8, 5) 52 var t2: i64=0; if cents==1108 { t2=1 } 53 gg_w(" parsed price cents=" as *u8); gg_n(cents); gg_w("\n" as *u8) 54 gg_check(t2, "T2 gl_json_cents reads price 11.08 -> 1108 from a checkDomain body" as *u8, fails) 55 56 // T3: gl_json_is avail -- yes matches, a no-body does not 57 let av_yes: i64 = gl_json_is(wrap, wn, "avail" as *u8, 5, "yes" as *u8) 58 let chk_no: *u8 = "{\"status\":\"SUCCESS\",\"response\":{\"avail\":\"no\",\"price\":\"11.08\"}}" as *u8 59 let wrap2: *u8 = sys_mmap(1024) 60 let wn2: i64 = gg_wrap(chk_no, wrap2) 61 let av_no: i64 = gl_json_is(wrap2, wn2, "avail" as *u8, 5, "yes" as *u8) 62 var t3: i64=0; if av_yes==1 { if av_no==0 { t3=1 } } 63 gg_check(t3, "T3 gl_json_is avail: yes->1, no->0 (availability gate discriminates)" as *u8, fails) 64 65 // T4: gl_json_copy pulls yourIp exactly (the DNS-step input) 66 let ping: *u8 = "{\"status\":\"SUCCESS\",\"yourIp\":\"75.28.18.94\",\"credentialsValid\":true}" as *u8 67 let wrap3: *u8 = sys_mmap(1024) 68 let wn3: i64 = gg_wrap(ping, wrap3) 69 let ipbuf: *u8 = sys_mmap(64) 70 let ipn: i64 = gl_json_copy(wrap3, wn3, "yourIp" as *u8, 6, ipbuf, 64) 71 var t4: i64=0 72 if ipn==11 { 73 if ipbuf[0]==(55 as u8) { if ipbuf[10]==(52 as u8) { if ipbuf[11]==(0 as u8) { t4=1 } } } 74 } 75 gg_w(" yourIp='" as *u8); gg_w(ipbuf); gg_w("' len=" as *u8); gg_n(ipn); gg_w("\n" as *u8) 76 gg_check(t4, "T4 gl_json_copy extracts yourIp 75.28.18.94 (NUL-terminated) for the A records" as *u8, fails) 77 78 // T5: HONEST STOP -- a live INSUFFICIENT_FUNDS body must NOT read as status:SUCCESS (the driver 79 // would refuse to advance to spend). This is the exact wall the live run hit. 80 let err: *u8 = "{\"status\":\"ERROR\",\"message\":\"No funds.\",\"code\":\"INSUFFICIENT_FUNDS\"}" as *u8 81 let wrap4: *u8 = sys_mmap(1024) 82 let wn4: i64 = gg_wrap(err, wrap4) 83 let dry_ok: i64 = gl_json_is(wrap4, wn4, "status" as *u8, 6, "SUCCESS" as *u8) 84 let ok_ok: i64 = gl_json_is(wrap, wn, "status" as *u8, 6, "SUCCESS" as *u8) 85 var t5: i64=0; if dry_ok==0 { if ok_ok==1 { t5=1 } } 86 gg_check(t5, "T5 honest-stop: INSUFFICIENT_FUNDS never reads as SUCCESS; a real SUCCESS does" as *u8, fails) 87 88 // T6: cap discipline -- the quote-vs-cap comparison the driver uses (in-line integer compare) 89 var t6: i64=0 90 if 1108<=1500 { if 1108>1000 { t6=1 } } // 1108 clears a 1500 cap, exceeds a 1000 cap 91 gg_check(t6, "T6 cap discipline: quote 1108 clears cap 1500, exceeds cap 1000 (spend ceiling honored)" as *u8, fails) 92 93 gg_w(" fails=" as *u8); gg_n(fails[0]); gg_w("\n" as *u8) 94 if fails[0]==0 { gg_w("VERDICT: GREEN (auto-quote + JSON readers + honest-stop; live walk proven 2026-07-09)\n" as *u8); sys_exit(0) } 95 gg_w("VERDICT: RED\n" as *u8) 96 sys_exit(1) 97 return 1 98}