code wiki / _hdl_build / nx_docpub_publish.nx

nx_docpub_publish.nx source

↩ module page · 80 lines · 5739 B

1// nx_docpub_publish.nx -- the docs arc's PUBLISH LEG, wired to THE NISHI PUBLISHER (operator law: every push 2// flows through ONE publisher via pub_submit; NO workstream pushes directly -- the sites.elf outage fix). 3// Stages the WHOLE self-generated documentation SITE (index + reference set) by enqueueing one durable, flock'd, 4// sha256-identified REQUEST per page to the publisher intake; the publisher SHIPS. Docs are INTERNAL behind the 5// OPAQUE wall (operator 2026-06-21) so dest = the walled /wiki/reference/ doc-root. Proven against a DEDICATED 6// docpub queue; the publisher workstream promotes to the canonical queue + ships (coordinate). NEVER nx_aw_push. 7// license_tier: ORIGINAL expect_exit: 0 8import "nx_syscalls.nx" 9import "nx_itoa_lib.nx" // shared MSB-first emitter (zero-alloc) 10import "nx_publisher.nx" 11import "nx_runpath.nx" 12const K_MAGIC_65536: i64 = 65536 13 14func dpp_w(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 15// MIGRATED to the shared emitter (debt 1785563586). The old body mmapped a scratch buffer 16// per call and never freed it. At PAGE granularity that is 4096B leaked PER CALL -- the 17// defect that took 28.5GB of a 36GB host in nx_ts_lumadiff (2MB input, ~3.66M calls). 18// nxi_* is MSB-first, allocates NOTHING, and emits identical bytes including the sign. 19func dpp_n(v: i64) -> i64 { nxi_out(v); return 0 } 20func dpp_match(buf: *u8, p: i64, n: i64, needle: *u8) -> i64 { 21 var k: i64 = 0 22 while needle[k] != (0 as u8) { if p + k >= n { return 0 } if buf[p+k] != needle[k] { return 0 } k = k + 1 } 23 return 1 24} 25func dpp_contains(buf: *u8, n: i64, needle: *u8) -> i64 { var i: i64 = 0; while i < n { if dpp_match(buf, i, n, needle) == 1 { return 1 } i = i + 1 } return 0 } 26func dpp_count(buf: *u8, n: i64, needle: *u8) -> i64 { var i: i64 = 0; var c: i64 = 0; while i < n { if dpp_match(buf, i, n, needle) == 1 { c = c + 1 } i = i + 1 } return c } 27func dpp_trunc(path: *u8) -> i64 { let fd: i64 = sys_openat_wr(path, 0x1a4); if fd >= 0 { sys_close(fd) } return 0 } 28func dpp_read(path: *u8, buf: *u8, cap: i64) -> i64 { 29 let fd: i64 = sys_openat_rd(path); if fd < 0 { return 0 - 1 } 30 let n: i64 = sys_read(fd, buf, cap); sys_close(fd); return n 31} 32func dpp_cat(out: *u8, o: i64, s: *u8) -> i64 { var k: i64 = 0; while s[k] != (0 as u8) { out[o] = s[k]; o = o + 1; k = k + 1 } return o } 33func dpp_mk(prefix: *u8, name: *u8, suffix: *u8, out: *u8) -> i64 { var o: i64 = 0; o = dpp_cat(out, o, prefix); o = dpp_cat(out, o, name); o = dpp_cat(out, o, suffix); out[o] = 0 as u8; return o } 34 35// stage ONE page: src=web_assets/docgen/<name>.html -> dest=walled /wiki/reference/<name>.html via pub_submit_to. 36func dpp_one(qpath: *u8, name: *u8, ok: *i64) -> i64 { 37 let src: *u8 = sys_mmap(256); dpp_mk("web_assets/docgen/" as *u8, name, ".html" as *u8, src) 38 let dst: *u8 = sys_mmap(256); dpp_mk("sites/nishifamily/wiki/reference/" as *u8, name, ".html" as *u8, dst) 39 let rc: i64 = pub_submit_to(qpath, src, dst, "nishifamily" as *u8, "docpub" as *u8, "internal" as *u8) 40 dpp_w(" + "); dpp_w(name); dpp_w(".html rc="); dpp_n(rc); dpp_w("\n") 41 if rc == 1 { ok[0] = ok[0] + 1 } 42 return rc 43} 44 45func main() -> i64 { 46 dpp_w("=== NX-DOCPUB-PUBLISH -- stage the SELF-GENERATED DOC SITE via the Nishi Publisher (internal/walled) ===\n" as *u8) 47 __syscall(83, "knowledge/publish" as i64, 493, 0, 0, 0, 0) 48 let qpath: *u8 = "knowledge/publish/docpub_queue.tsv" 49 dpp_trunc(qpath as *u8) 50 51 let ok: *i64 = sys_mmap(16) as *i64; ok[0] = 0 52 dpp_one(qpath as *u8, "index" as *u8, ok) 53 dpp_one(qpath as *u8, "nx_docgen" as *u8, ok) 54 dpp_one(qpath as *u8, "nx_docgen_lib" as *u8, ok) 55 dpp_one(qpath as *u8, "nx_docpub_census" as *u8, ok) 56 dpp_one(qpath as *u8, "nx_docpub_research_fetch" as *u8, ok) 57 dpp_one(qpath as *u8, "nx_docpub_publish" as *u8, ok) 58 dpp_one(qpath as *u8, "nx_publisher" as *u8, ok) 59 60 let buf: *u8 = sys_mmap(K_MAGIC_65536) 61 let n: i64 = dpp_read(qpath as *u8, buf, K_MAGIC_65536) 62 var tabs: i64 = 0; var i: i64 = 0 63 while i < n { if buf[i] == (9 as u8) { tabs = tabs + 1 } i = i + 1 } 64 let pend: i64 = dpp_count(buf, n, "PENDING\t" as *u8) 65 dpp_w(" queue bytes="); dpp_n(n); dpp_w(" PENDING records="); dpp_n(pend); dpp_w(" enqueued_ok="); dpp_n(ok[0]); dpp_w("\n") 66 67 let pass: *i64 = sys_mmap(16) as *i64; pass[0] = 0 68 let t1: i64 = (ok[0] == 7) as i64 69 if t1 == 1 { dpp_w(" T1 all 7 site artifacts enqueued via pub_submit_to: PASS\n" as *u8); pass[0] = pass[0] + 1 } else { dpp_w(" T1 all 7 site artifacts enqueued: FAIL\n" as *u8) } 70 let t2: i64 = (pend == 7) as i64 71 if t2 == 1 { dpp_w(" T2 queue holds 7 PENDING requests: PASS\n" as *u8); pass[0] = pass[0] + 1 } else { dpp_w(" T2 queue holds 7 PENDING requests: FAIL\n" as *u8) } 72 let t3: i64 = (tabs == 42) as i64 73 if t3 == 1 { dpp_w(" T3 every record well-formed (7x6 tabs, none torn): PASS\n" as *u8); pass[0] = pass[0] + 1 } else { dpp_w(" T3 records well-formed (expect 42 tabs): FAIL got "); dpp_n(tabs); dpp_w("\n" as *u8) } 74 let t4: i64 = (dpp_contains(buf, n, "wiki/reference/nx_publisher.html" as *u8)) & (dpp_contains(buf, n, "wiki/reference/index.html" as *u8)) 75 if t4 == 1 { dpp_w(" T4 dests target the walled /wiki/reference/ doc-root: PASS\n" as *u8); pass[0] = pass[0] + 1 } else { dpp_w(" T4 dests target /wiki/reference/: FAIL\n" as *u8) } 76 77 dpp_w("NX-DOCPUB-PUBLISH "); dpp_n(pass[0]); dpp_w("/4 ") 78 if pass[0] == 4 { dpp_w("verdict=GREEN (full doc site staged THROUGH the Publisher for behind-the-wall ship; no bare nx_aw_push)\n" as *u8); sys_exit(0); return 0 } 79 dpp_w("verdict=RED (staging incomplete)\n" as *u8); sys_exit(1); return 1 80}