code wiki / _hdl_build / nx_wiki_versioned_publish_live.nx

nx_wiki_versioned_publish_live.nx source

↩ module page · 122 lines · 6936 B

1// nx_wiki_versioned_publish_live.nx -- A4a LIVE PROOF (real, additive, ends restored to original). 2// 3// Treats the live web_assets/nist_stem.html (body 9450 B) as v1 and archives it, emits an ADDITIVE v2 4// (a "Last reviewed 2026-06-17" trailing comment -- nothing deleted), vpub's v2 LIVE (guarded, push=1), 5// then restore(nist_stem, 1) to re-push v1 LIVE so production ends byte-exact the original -- with BOTH 6// v1 and v2 retained as rollback points in the durable archive store. Every live write flows through the 7// A3 guard (pub_publish_ex). Prints vp_list + the assigned version#s; the operator fetch-verifies sizes. 8// 9// Run as: nx_wiki_versioned_publish_live.sov.elf (no args -- paths are baked, like the gates) 10// license_tier: ORIGINAL 11import "nx_wiki_versioned_publish.nx" 12import "nx_itoa_lib.nx" // shared MSB-first emitter (zero-alloc) 13import "nx_wiki_restore.nx" 14import "nx_syscalls.nx" 15 16func l_w(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 17// MIGRATED to the shared emitter (debt 1785563586). The old body mmapped a scratch buffer 18// per call and never freed it. At PAGE granularity that is 4096B leaked PER CALL -- the 19// defect that took 28.5GB of a 36GB host in nx_ts_lumadiff (2MB input, ~3.66M calls). 20// nxi_* is MSB-first, allocates NOTHING, and emits identical bytes including the sign. 21func l_num(v: i64) -> i64 { nxi_out(v); return 0 } 22 23// the fixed epoch already stamped into nist_stem.html (NO wall-clock call). 24const LIVE_EPOCH: i64 = 1781730256 25 26func main() -> i64 { 27 // ---- corpus set for nist_stem (the verified live link set) ---- 28 let cs_ptr: *i64 = sys_mmap(8 * 8) as *i64 29 let cs_len: *i64 = sys_mmap(8 * 8) as *i64 30 cs_ptr[0] = "start" as *u8 as i64; cs_len[0] = 5 31 cs_ptr[1] = "charter" as *u8 as i64; cs_len[1] = 7 32 cs_ptr[2] = "board" as *u8 as i64; cs_len[2] = 5 33 cs_ptr[3] = "devlog" as *u8 as i64; cs_len[3] = 6 34 cs_ptr[4] = "nist_stem" as *u8 as i64; cs_len[4] = 9 35 cs_ptr[5] = "roadmap" as *u8 as i64; cs_len[5] = 7 36 cs_ptr[6] = "search" as *u8 as i64; cs_len[6] = 6 37 let ncorpus: i64 = 7 38 39 let slug: *u8 = "nist_stem" as *u8 40 let v1_path: *u8 = "web_assets/nist_stem.html" as *u8 41 42 let res: *PubResult = sys_mmap(64) as *PubResult 43 let vout: *i64 = sys_mmap(16) as *i64 44 45 // ============================================================================================ 46 // STEP 1: vpub v1 = the ORIGINAL bytes (guarded, push LIVE). Re-publishes the exact original 47 // (additive -- live is unchanged) AND retains it as rollback point v#1. 48 // ============================================================================================ 49 l_w("=== STEP 1: vpub v1 (original nist_stem, guarded push LIVE) ===\n" as *u8) 50 let r1: i64 = vpub(slug, v1_path, cs_ptr, cs_len, ncorpus, LIVE_EPOCH, 1, res, vout) 51 let v1n: i64 = vout[0] 52 l_w(" vpub v1 rc=" as *u8); l_w(vp_status_name(r1)) 53 l_w(" version#=" as *u8); l_num(v1n) 54 l_w(" | push status=" as *u8); l_w(pub_status_name(res.status)) 55 l_w(" push_invoked=" as *u8); l_num(res.push_invoked) 56 l_w(" push_rc=" as *u8); l_num(res.push_rc) 57 l_w(" bytes=" as *u8); l_num(res.bytes); l_w("\n" as *u8) 58 59 // ============================================================================================ 60 // STEP 2: build v2 = v1 bytes + an ADDITIVE trailing footer comment (nothing deleted), stage it. 61 // ============================================================================================ 62 l_w("=== STEP 2: emit v2 (original + additive footer), vpub LIVE ===\n" as *u8) 63 let nbox: *i64 = sys_mmap(16) as *i64 64 let orig: *u8 = sys_read_file(v1_path, nbox) 65 if (orig as i64) == 0 { l_w("LIVE FATAL: cannot read v1 source\n" as *u8); sys_exit(2); return 2 } 66 let on: i64 = nbox[0] 67 let v2buf: *u8 = sys_mmap(on + 256) 68 var o: i64 = 0 69 var ci: i64 = 0 70 while ci < on { v2buf[o] = orig[ci]; o = o + 1; ci = ci + 1 } 71 // append a purely-additive HTML comment footer (keeps the epoch= freshness stamp + all links intact). 72 let foot: *u8 = "\n<!-- Last reviewed 2026-06-17 (epoch=1781730256) -->\n" as *u8 73 var fi: i64 = 0 74 while foot[fi] != (0 as u8) { v2buf[o] = foot[fi]; o = o + 1; fi = fi + 1 } 75 let v2n: i64 = o 76 let v2_path: *u8 = "/tmp/nist_stem_v2.html" as *u8 77 let fd2: i64 = sys_openat_wr(v2_path, MODE_0644) 78 if fd2 < 0 { l_w("LIVE FATAL: cannot stage v2\n" as *u8); sys_exit(2); return 2 } 79 sys_write(fd2, v2buf, v2n) 80 sys_close(fd2) 81 l_w(" v2 staged: orig_bytes=" as *u8); l_num(on); l_w(" v2_bytes=" as *u8); l_num(v2n); l_w(" (additive footer)\n" as *u8) 82 83 let r2: i64 = vpub(slug, v2_path, cs_ptr, cs_len, ncorpus, LIVE_EPOCH, 1, res, vout) 84 let v2nn: i64 = vout[0] 85 l_w(" vpub v2 rc=" as *u8); l_w(vp_status_name(r2)) 86 l_w(" version#=" as *u8); l_num(v2nn) 87 l_w(" | push status=" as *u8); l_w(pub_status_name(res.status)) 88 l_w(" push_invoked=" as *u8); l_num(res.push_invoked) 89 l_w(" push_rc=" as *u8); l_num(res.push_rc) 90 l_w(" bytes=" as *u8); l_num(res.bytes); l_w("\n" as *u8) 91 92 // ============================================================================================ 93 // STEP 3: vp_list(nist_stem) -- prove >= 2 retained rollback points. 94 // ============================================================================================ 95 l_w("=== STEP 3: vp_list(nist_stem) retained rollback points ===\n" as *u8) 96 let vers: *i64 = sys_mmap(8 * 64) as *i64 97 let cidbuf: *u8 = sys_mmap(72 * 64) 98 let nlist: i64 = vp_list(slug, vers, cidbuf, 64) 99 l_w(" retained_points=" as *u8); l_num(nlist); l_w("\n" as *u8) 100 var li: i64 = 0 101 while li < nlist { 102 l_w(" v" as *u8); l_num(vers[li]); l_w(" cid=" as *u8) 103 l_w((cidbuf as i64 + li * 72) as *u8); l_w("\n" as *u8) 104 li = li + 1 105 } 106 107 // ============================================================================================ 108 // STEP 4: restore(nist_stem, 1) -- re-push the EXACT v1 bytes LIVE so production ends at original. 109 // ============================================================================================ 110 l_w("=== STEP 4: restore(nist_stem, 1) -> re-push original v1 LIVE ===\n" as *u8) 111 let rstage: *u8 = "/tmp/nist_stem_restore.html" as *u8 112 let nout: *i64 = sys_mmap(16) as *i64 113 let rr: i64 = restore(slug, 1, rstage, cs_ptr, cs_len, ncorpus, 1, res, nout) 114 l_w(" restore(v1) rc=" as *u8); l_w(vr_status_name(rr)) 115 l_w(" restored_bytes=" as *u8); l_num(nout[0]) 116 l_w(" | push status=" as *u8); l_w(pub_status_name(res.status)) 117 l_w(" push_invoked=" as *u8); l_num(res.push_invoked) 118 l_w(" push_rc=" as *u8); l_num(res.push_rc); l_w("\n" as *u8) 119 120 l_w("=== A4a LIVE PROOF COMPLETE: production restored to v1 (original); v1 AND v2 retained ===\n" as *u8) 121 sys_exit(0); return 0 122}