code wiki / _hdl_build / nx_wiki_versioned_publish_live.nx
nx_wiki_versioned_publish_live.nx source
↩ module page · 123 lines · 6975 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
25const LIVE_MODE_0644: i64 = 0x1a4
26
27func main() -> i64 {
28 // ---- corpus set for nist_stem (the verified live link set) ----
29 let cs_ptr: *i64 = sys_mmap(8 * 8) as *i64
30 let cs_len: *i64 = sys_mmap(8 * 8) as *i64
31 cs_ptr[0] = "start" as *u8 as i64; cs_len[0] = 5
32 cs_ptr[1] = "charter" as *u8 as i64; cs_len[1] = 7
33 cs_ptr[2] = "board" as *u8 as i64; cs_len[2] = 5
34 cs_ptr[3] = "devlog" as *u8 as i64; cs_len[3] = 6
35 cs_ptr[4] = "nist_stem" as *u8 as i64; cs_len[4] = 9
36 cs_ptr[5] = "roadmap" as *u8 as i64; cs_len[5] = 7
37 cs_ptr[6] = "search" as *u8 as i64; cs_len[6] = 6
38 let ncorpus: i64 = 7
39
40 let slug: *u8 = "nist_stem" as *u8
41 let v1_path: *u8 = "web_assets/nist_stem.html" as *u8
42
43 let res: *PubResult = sys_mmap(64) as *PubResult
44 let vout: *i64 = sys_mmap(16) as *i64
45
46 // ============================================================================================
47 // STEP 1: vpub v1 = the ORIGINAL bytes (guarded, push LIVE). Re-publishes the exact original
48 // (additive -- live is unchanged) AND retains it as rollback point v#1.
49 // ============================================================================================
50 l_w("=== STEP 1: vpub v1 (original nist_stem, guarded push LIVE) ===\n" as *u8)
51 let r1: i64 = vpub(slug, v1_path, cs_ptr, cs_len, ncorpus, LIVE_EPOCH, 1, res, vout)
52 let v1n: i64 = vout[0]
53 l_w(" vpub v1 rc=" as *u8); l_w(vp_status_name(r1))
54 l_w(" version#=" as *u8); l_num(v1n)
55 l_w(" | push status=" as *u8); l_w(pub_status_name(res.status))
56 l_w(" push_invoked=" as *u8); l_num(res.push_invoked)
57 l_w(" push_rc=" as *u8); l_num(res.push_rc)
58 l_w(" bytes=" as *u8); l_num(res.bytes); l_w("\n" as *u8)
59
60 // ============================================================================================
61 // STEP 2: build v2 = v1 bytes + an ADDITIVE trailing footer comment (nothing deleted), stage it.
62 // ============================================================================================
63 l_w("=== STEP 2: emit v2 (original + additive footer), vpub LIVE ===\n" as *u8)
64 let nbox: *i64 = sys_mmap(16) as *i64
65 let orig: *u8 = sys_read_file(v1_path, nbox)
66 if (orig as i64) == 0 { l_w("LIVE FATAL: cannot read v1 source\n" as *u8); sys_exit(2); return 2 }
67 let on: i64 = nbox[0]
68 let v2buf: *u8 = sys_mmap(on + 256)
69 var o: i64 = 0
70 var ci: i64 = 0
71 while ci < on { v2buf[o] = orig[ci]; o = o + 1; ci = ci + 1 }
72 // append a purely-additive HTML comment footer (keeps the epoch= freshness stamp + all links intact).
73 let foot: *u8 = "\n<!-- Last reviewed 2026-06-17 (epoch=1781730256) -->\n" as *u8
74 var fi: i64 = 0
75 while foot[fi] != (0 as u8) { v2buf[o] = foot[fi]; o = o + 1; fi = fi + 1 }
76 let v2n: i64 = o
77 let v2_path: *u8 = "/tmp/nist_stem_v2.html" as *u8
78 let fd2: i64 = sys_openat_wr(v2_path, LIVE_MODE_0644)
79 if fd2 < 0 { l_w("LIVE FATAL: cannot stage v2\n" as *u8); sys_exit(2); return 2 }
80 sys_write(fd2, v2buf, v2n)
81 sys_close(fd2)
82 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)
83
84 let r2: i64 = vpub(slug, v2_path, cs_ptr, cs_len, ncorpus, LIVE_EPOCH, 1, res, vout)
85 let v2nn: i64 = vout[0]
86 l_w(" vpub v2 rc=" as *u8); l_w(vp_status_name(r2))
87 l_w(" version#=" as *u8); l_num(v2nn)
88 l_w(" | push status=" as *u8); l_w(pub_status_name(res.status))
89 l_w(" push_invoked=" as *u8); l_num(res.push_invoked)
90 l_w(" push_rc=" as *u8); l_num(res.push_rc)
91 l_w(" bytes=" as *u8); l_num(res.bytes); l_w("\n" as *u8)
92
93 // ============================================================================================
94 // STEP 3: vp_list(nist_stem) -- prove >= 2 retained rollback points.
95 // ============================================================================================
96 l_w("=== STEP 3: vp_list(nist_stem) retained rollback points ===\n" as *u8)
97 let vers: *i64 = sys_mmap(8 * 64) as *i64
98 let cidbuf: *u8 = sys_mmap(72 * 64)
99 let nlist: i64 = vp_list(slug, vers, cidbuf, 64)
100 l_w(" retained_points=" as *u8); l_num(nlist); l_w("\n" as *u8)
101 var li: i64 = 0
102 while li < nlist {
103 l_w(" v" as *u8); l_num(vers[li]); l_w(" cid=" as *u8)
104 l_w((cidbuf as i64 + li * 72) as *u8); l_w("\n" as *u8)
105 li = li + 1
106 }
107
108 // ============================================================================================
109 // STEP 4: restore(nist_stem, 1) -- re-push the EXACT v1 bytes LIVE so production ends at original.
110 // ============================================================================================
111 l_w("=== STEP 4: restore(nist_stem, 1) -> re-push original v1 LIVE ===\n" as *u8)
112 let rstage: *u8 = "/tmp/nist_stem_restore.html" as *u8
113 let nout: *i64 = sys_mmap(16) as *i64
114 let rr: i64 = restore(slug, 1, rstage, cs_ptr, cs_len, ncorpus, 1, res, nout)
115 l_w(" restore(v1) rc=" as *u8); l_w(vr_status_name(rr))
116 l_w(" restored_bytes=" as *u8); l_num(nout[0])
117 l_w(" | push status=" as *u8); l_w(pub_status_name(res.status))
118 l_w(" push_invoked=" as *u8); l_num(res.push_invoked)
119 l_w(" push_rc=" as *u8); l_num(res.push_rc); l_w("\n" as *u8)
120
121 l_w("=== A4a LIVE PROOF COMPLETE: production restored to v1 (original); v1 AND v2 retained ===\n" as *u8)
122 sys_exit(0); return 0
123}