code wiki / _hdl_build / nx_office_snapshot.nx

nx_office_snapshot.nx source

↩ module page · 56 lines · 3622 B

1// nx_office_snapshot.nx -- deterministic page snapshots of the Nishi Office surface for the UI judge fleet 2// (feedback-ui-quality-is-not-presence: every family surface is MEASURED by nx_ui_judge/nx_uxcx_grade/ 3// nx_ui_contrast via ui_ship.conf rows, BEFORE any SOTA claim). No sockets: drives the pure core of_handle 4// against a throwaway /tmp root with the SAME sample content as the gate (doc with table + sheet with a real 5// formula + deck), then writes the response BODIES to web_assets/office_home_snap.html + office_doc_snap.html. 6// The driver copies them to *_before/*_after around a retrofit so the improvement is a NUMBER. 7// Must run from the nxc2 root (forks _offc format elfs). license_tier: ORIGINAL expect_exit: 0 8import "nx_office_serve.nx" 9const K_MAGIC_1048576: i64 = 1048576 10const K_MAGIC_131072: i64 = 131072 11const K_MAGIC_262144: i64 = 262144 12 13// POST one /save through of_handle (body first, then exact Content-Length), like the gate does. 14func sn_save(root: *u8, base: *u8, bod: *u8, req: *u8, out: *u8, body: *u8) -> i64 { 15 var bo: i64 = of_cat(bod, 0, body) 16 bod[bo] = 0 as u8 // of_cat does NOT NUL-terminate; a reused buffer leaks the previous longer body's tail 17 var ro: i64 = of_cat(req, 0, "POST /save HTTP/1.1\r\nHost: office.local\r\nContent-Length: " as *u8) 18 ro = of_catn(req, ro, bo) 19 ro = of_cat(req, ro, "\r\n\r\n" as *u8) 20 ro = of_cat(req, ro, bod) 21 let n: i64 = of_handle(root, base, req, ro, out, K_MAGIC_1048576) 22 if of_memhas(out, n, "303" as *u8) == 0 { return 0 - 1 } 23 return 0 24} 25// write the response BODY (after CRLFCRLF) to path 26func sn_dump(out: *u8, n: i64, path: *u8) -> i64 { 27 var bs: i64 = 0 - 1 28 var i: i64 = 0 29 while i + 3 < n { 30 if out[i] == (13 as u8) { if out[i+1] == (10 as u8) { if out[i+2] == (13 as u8) { if out[i+3] == (10 as u8) { bs = i + 4; i = n } } } } 31 i = i + 1 32 } 33 if bs < 0 { return 0 - 1 } 34 return of_write_file(path, (out as i64 + bs) as *u8, n - bs) 35} 36func main() -> i64 { 37 let root: *u8 = sys_mmap(128) 38 var o: i64 = of_cat(root, 0, "/tmp/officesnap_" as *u8) 39 o = of_catn(root, o, sys_now_us()) 40 root[o] = 0 as u8 41 let base: *u8 = sys_mmap(4) 42 base[0] = 0 as u8 43 let bod: *u8 = sys_mmap(K_MAGIC_131072) 44 let req: *u8 = sys_mmap(K_MAGIC_262144) 45 let out: *u8 = sys_mmap(K_MAGIC_1048576) 46 if sn_save(root, base, bod, req, out, "name=family-letter&kind=doc&spec=H+Family+Letter%0AB+Dear+family%0AP+We+love+each+other.%0AT+Who%7CBrings%0AT+Alice%7CSalad" as *u8) != 0 { p("SNAP doc save FAILED\n" as *u8); sys_exit(1) } 47 if sn_save(root, base, bod, req, out, "name=family-budget&kind=sheet&spec=Item%09Cost%0AApples%0910%0APears%0920%0ATotal%09=SUM(B2:B3)" as *u8) != 0 { p("SNAP sheet save FAILED\n" as *u8); sys_exit(1) } 48 if sn_save(root, base, bod, req, out, "name=reunion-deck&kind=deck&spec=S+Reunion+2026%0AB+Where:+the+lake%0AB+Friday:+burgers" as *u8) != 0 { p("SNAP deck save FAILED\n" as *u8); sys_exit(1) } 49 var n: i64 = of_handle(root, base, "GET / HTTP/1.1\r\nHost: office.local\r\n\r\n" as *u8, 38, out, K_MAGIC_1048576) 50 if sn_dump(out, n, "web_assets/office_home_snap.html" as *u8) != 0 { p("SNAP home dump FAILED\n" as *u8); sys_exit(1) } 51 n = of_handle(root, base, "GET /doc/family-letter HTTP/1.1\r\nHost: office.local\r\n\r\n" as *u8, 56, out, K_MAGIC_1048576) 52 if sn_dump(out, n, "web_assets/office_doc_snap.html" as *u8) != 0 { p("SNAP doc dump FAILED\n" as *u8); sys_exit(1) } 53 p("NX-OFFICE-SNAPSHOT GREEN -> web_assets/office_home_snap.html + office_doc_snap.html\n" as *u8) 54 sys_exit(0) 55 return 0 56}