code wiki / _hdl_build / nx_publish_account_admin.nx
nx_publish_account_admin.nx source
↩ module page · 80 lines · 6309 B
1// nx_publish_account_admin.nx -- the SOVEREIGN deploy SUBMISSION for this workstream, through THE NISHI PUBLISHER
2// (the operator's law: workstreams REQUEST, the publisher SHIPS -- no direct pushes). It enqueues the two staged HR
3// stores as publish requests; the publisher later verifies + (for an outward site) HOLDS them for operator approval
4// (its R6) and atomically promotes. This organ NEVER touches the live site -- it only appends a framed request.
5//
6// Self-verifying: (1) NEG CONTROL -- a missing source fails closed (-9); (2) a test-queue submit produces ONE framed
7// PENDING line carrying site/requester/dest/sha; (3) the REAL submit is IDEMPOTENT (#10) -- it skips an artifact
8// whose (sha+dest) is already queued, so re-runs don't pile up duplicates; (4) readback confirms both dests are queued.
9// The daemon BINARIES are NOT submitted here -- they are owner-rebuilt-from-source at promote (source = SSOT); this
10// submits the deployable DATA (the HR roster stores the daemons hot-read). license_tier: ORIGINAL
11import "nx_publisher.nx" // pub_submit / pub_submit_to / pub_sha_file / pub_queue_default
12import "nx_runpath.nx" // rp_wsid / rp_ensure / rp_path (per-wsid TEST queue)
13import "nx_syscalls.nx"
14
15func g_w(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
16func g_n(v: i64) -> i64 { var m: i64=v; if m<0{g_w("-" as *u8);m=0-m} let t:*u8=sys_mmap(24); 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; let o:*u8=sys_mmap(24); while i<k{o[i]=t[k-1-i];i=i+1} sys_write(1,o,k); return 0 }
17func g_row(id: *u8, ok: i64, pass: *i64) -> i64 { g_w(" " as *u8); g_w(id); g_w(": " as *u8); if ok==1 { g_w("OK\n" as *u8); pass[0]=pass[0]+1 } else { g_w("FAIL\n" as *u8) } return 0 }
18func gtrunc(path: *u8) -> i64 { let fd: i64 = sys_openat_wr(path, 0x1a4); if fd>=0 { sys_close(fd) } return 0 }
19func paa_count(buf: *u8, n: i64, needle: *u8) -> i64 { var nl: i64=0; while needle[nl]!=(0 as u8){nl=nl+1} if nl==0 {return 0} var c: i64=0; var i: i64=0; while i+nl<=n { var j: i64=0; var ok: i64=1; while j<nl { if buf[i+j]!=needle[j]{ok=0;j=nl} else {j=j+1} } if ok==1 {c=c+1;i=i+nl} else {i=i+1} } return c }
20func paa_has(buf: *u8, n: i64, needle: *u8) -> i64 { if paa_count(buf,n,needle)>0 {return 1} return 0 }
21// read a file into a fresh buffer; returns the buffer (0 if missing) and writes the length to lenp[0].
22func paa_read(path: *u8, lenp: *i64) -> *u8 { lenp[0]=0; return sys_read_file(path, lenp) }
23// 1 iff a request for (sha of src + dest) is already in the queue text (idempotency guard).
24func paa_already(qbuf: *u8, qn: i64, src: *u8, dest: *u8) -> i64 {
25 if qn <= 0 { return 0 }
26 let hx: *u8 = sys_mmap(72)
27 if pub_sha_file(src, hx) == 0 { return 0 }
28 if paa_has(qbuf, qn, hx) == 1 { if paa_has(qbuf, qn, dest) == 1 { return 1 } }
29 return 0
30}
31
32const PAA_SITE: *u8 = "nishifamily.com" as *u8
33const PAA_REQ: *u8 = "acct-cleanup-32992a14" as *u8
34const PAA_POLICY: *u8 = "outward-data:hotreload" as *u8 // outward -> the publisher HOLDS for operator approval (R6)
35const PAA_SRC1: *u8 = "knowledge/publish/staging/nishi_hr.log" as *u8
36const PAA_DST1: *u8 = "/volume1/homes/elderwesto/nishihost/nishi_hr.log" as *u8
37const PAA_SRC2: *u8 = "knowledge/publish/staging/andelinwest_hr.log" as *u8
38const PAA_DST2: *u8 = "/volume1/homes/elderwesto/nishihost/andelinwest_hr.log" as *u8
39
40func main() -> i64 {
41 let pass: *i64 = sys_mmap(8) as *i64; pass[0]=0
42 g_w("=== NISHI PUBLISHER -- account-admin deploy submission (workstream REQUESTS, publisher SHIPS) ===\n" as *u8)
43
44 // ---- PROOF on a per-wsid TEST queue (no real-queue pollution) ----
45 let wsid: *u8 = sys_mmap(64); rp_wsid(wsid); rp_ensure(wsid)
46 let tq: *u8 = sys_mmap(512); rp_path(wsid, "paa_test_q.tsv" as *u8, tq)
47 gtrunc(tq)
48 let neg: i64 = pub_submit_to(tq, "knowledge/publish/staging/__nonexistent__.log" as *u8, PAA_DST1, PAA_SITE, PAA_REQ, PAA_POLICY)
49 g_row("NEG CONTROL: missing source fails closed (-9, nothing queued)" as *u8, (neg == (0-9)) as i64, pass)
50 let r1: i64 = pub_submit_to(tq, PAA_SRC1, PAA_DST1, PAA_SITE, PAA_REQ, PAA_POLICY)
51 g_row("test submit nishi_hr.log -> durable append (1)" as *u8, (r1 == 1) as i64, pass)
52 let tlen: *i64 = sys_mmap(8) as *i64
53 let tbuf: *u8 = paa_read(tq, tlen)
54 g_row("ONE framed PENDING line (no tear)" as *u8, ((paa_count(tbuf, tlen[0], "PENDING\t" as *u8)==1) as i64) & ((paa_count(tbuf, tlen[0], "\n" as *u8)==1) as i64), pass)
55 g_row("the request carries requester + dest + a 64-hex sha" as *u8, ((paa_has(tbuf,tlen[0],PAA_REQ)==1) as i64) & ((paa_has(tbuf,tlen[0],PAA_DST1)==1) as i64), pass)
56
57 // ---- REAL submit to the canonical publisher queue (IDEMPOTENT) ----
58 let q: *u8 = pub_queue_default()
59 let qlen: *i64 = sys_mmap(8) as *i64
60 let qbuf: *u8 = paa_read(q, qlen) // may be 0/empty
61 var submitted: i64 = 0
62 if paa_already(qbuf, qlen[0], PAA_SRC1, PAA_DST1) == 0 { if pub_submit(PAA_SRC1, PAA_DST1, PAA_SITE, PAA_REQ, PAA_POLICY)==1 { submitted=submitted+1 } }
63 let qbuf2: *u8 = paa_read(q, qlen)
64 if paa_already(qbuf2, qlen[0], PAA_SRC2, PAA_DST2) == 0 { if pub_submit(PAA_SRC2, PAA_DST2, PAA_SITE, PAA_REQ, PAA_POLICY)==1 { submitted=submitted+1 } }
65
66 // ---- readback the real queue: both dests are now queued ----
67 let q3len: *i64 = sys_mmap(8) as *i64
68 let q3: *u8 = paa_read(q, q3len)
69 g_row("nishifamily HR store queued for the publisher" as *u8, paa_has(q3, q3len[0], PAA_DST1), pass)
70 g_row("andelinwest HR store queued for the publisher" as *u8, paa_has(q3, q3len[0], PAA_DST2), pass)
71 g_w(" submitted "); g_n(submitted); g_w(" new request(s) this run (idempotent: an already-queued sha+dest is skipped).\n" as *u8)
72 g_w(" NOTE: outward requests are HELD by the publisher for operator approval (R6); nothing is live yet.\n" as *u8)
73
74 g_w("PUBLISH-ACCOUNT-ADMIN rows=6 pass="); g_n(pass[0])
75 if pass[0]==6 { g_w(" verdict=GREEN\n" as *u8)
76 let lg: i64=sys_openat_append("knowledge/status/publish_account_admin.log" as *u8, 0x1a4)
77 if lg>=0 { sys_write(lg, "PUBLISH-ACCOUNT-ADMIN pass=6/6 verdict=GREEN\n" as *u8, 44); sys_close(lg) }
78 sys_exit(0); return 0 }
79 g_w(" verdict=RED\n" as *u8); sys_exit(1); return 1
80}