code wiki / _hdl_build / nx_wiki_structure_regen_run.nx
nx_wiki_structure_regen_run.nx source
↩ module page · 103 lines · 4490 B
1// nx_wiki_structure_regen_run.nx -- LIVE DRY-RUN driver for the A4b re-publish-on-pulse engine.
2//
3// Runs regen(apply_flag=0) against the REAL knowledge/registry/wiki_pages.tsv + the REAL web_assets corpus
4// and prints the full PLAN -- exactly what each ARMED pulse WOULD do, but PUSHES NOTHING (apply_flag=0 =>
5// vpub is never reached; the only network write path is gated behind apply_flag==1). This is the read-only
6// proof surface for the cron-armed engine. A fixed epoch is passed so the (would-be) version stamp is
7// deterministic. At the end it asserts the push witness is 0 across the whole plan and exits non-zero if any
8// push was somehow invoked (it must not be). license_tier: ORIGINAL
9import "nx_wiki_structure_regen.nx"
10import "nx_syscalls.nx"
11
12func w(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
13func wn(v: i64) -> i64 {
14 var m: i64 = v
15 if m < 0 { w("-" as *u8); m = 0 - m }
16 let t: *u8 = sys_mmap(28); var k: i64 = 0
17 if m == 0 { t[0] = 48 as u8; k = 1 }
18 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 }
19 let bb: *u8 = sys_mmap(28); var i: i64 = 0
20 while i < k { bb[i] = t[k - 1 - i]; i = i + 1 }
21 sys_write(1, bb, k); return 0
22}
23// left-pad a NUL string to width cols (for a tidy table).
24func wpad(s: *u8, width: i64) -> i64 {
25 var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 }
26 w(s)
27 var p: i64 = n
28 while p < width { sys_write(1, " " as *u8, 1); p = p + 1 }
29 return 0
30}
31
32// FIXED deterministic epoch for the version record (NO wall-clock in the plan).
33const RUN_EPOCH: i64 = 1750000000
34
35func main() -> i64 {
36 w("=== nx_wiki_structure_regen LIVE DRY-RUN (apply_flag=0; PUSHES NOTHING) ===\n" as *u8)
37 w("registry=knowledge/registry/wiki_pages.tsv corpus=web_assets/ epoch=" as *u8); wn(RUN_EPOCH); w("\n\n" as *u8)
38
39 let reg: *RegRegistry = sys_mmap(128) as *RegRegistry
40 let plan: *RegPlan = sys_mmap(128) as *RegPlan
41 let rc: i64 = regen(0, RUN_EPOCH, reg, plan)
42 if rc != REG_OK {
43 w("REGEN FAILED rc=" as *u8); wn(rc); w("\n" as *u8)
44 sys_exit(2); return 2
45 }
46
47 w("PLAN (per managed page):\n" as *u8)
48 w(" slug emitter emitted orphan_check guard would_publish\n" as *u8)
49 w(" ----------- --------------------- ------- ----------------- -------------------- -------------\n" as *u8)
50
51 var npub: i64 = 0
52 var nrefuse: i64 = 0
53 var nmanual: i64 = 0
54 var nfail: i64 = 0
55 var pushed_total: i64 = 0
56
57 var i: i64 = 0
58 while i < plan.n {
59 if i >= REG_MAX_PAGES { i = plan.n }
60 if i < plan.n {
61 w(" " as *u8)
62 wpad(reg.slug_p[i] as *u8, 13)
63 wpad(reg.emit_p[i] as *u8, 23)
64 // emitted bytes
65 let eb: *u8 = sys_mmap(28); var m: i64 = plan.emitted[i]; var k: i64 = 0
66 if m == 0 { eb[0] = 48 as u8; k = 1 }
67 while m > 0 { eb[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 }
68 let eo: *u8 = sys_mmap(28); var z: i64 = 0
69 while z < k { eo[z] = eb[k - 1 - z]; z = z + 1 }
70 eo[k] = 0 as u8
71 wpad(eo, 9)
72 wpad(rc_name(plan.orphan_chk[i]), 19)
73 wpad(guard_name(plan.guard[i]), 22)
74 if plan.would_pub[i] == WP_YES { w("YES" as *u8) } else { w("no" as *u8) }
75 if plan.pushed[i] == 1 { w(" [PUSHED!]" as *u8) }
76 w("\n" as *u8)
77
78 if plan.would_pub[i] == WP_YES { npub = npub + 1 }
79 if plan.orphan_chk[i] == RC_REFUSE_ORPHAN { nrefuse = nrefuse + 1 }
80 if plan.orphan_chk[i] == RC_DEAD_LINK { nrefuse = nrefuse + 1 }
81 if plan.orphan_chk[i] == RC_MANUAL_ONLY { nmanual = nmanual + 1 }
82 if plan.orphan_chk[i] == RC_NOT_RUN { nfail = nfail + 1 }
83 pushed_total = pushed_total + plan.pushed[i]
84 }
85 i = i + 1
86 }
87
88 w("\nSUMMARY: pages=" as *u8); wn(plan.n)
89 w(" would_publish=" as *u8); wn(npub)
90 w(" refused(orphan/deadlink)=" as *u8); wn(nrefuse)
91 w(" manual_only(no emitter)=" as *u8); wn(nmanual)
92 w(" emit_failed=" as *u8); wn(nfail)
93 w(" pushes_invoked=" as *u8); wn(pushed_total)
94 w("\n" as *u8)
95
96 if pushed_total == 0 {
97 w("OK: DRY-RUN confirmed read-only (0 pushes invoked).\n" as *u8)
98 sys_exit(0)
99 }
100 w("ERROR: a push was invoked during a dry-run -- this MUST NOT happen.\n" as *u8)
101 sys_exit(3)
102 return 3
103}