code wiki / _hdl_build / nx_wiki_publish_guard_sanity.nx
nx_wiki_publish_guard_sanity.nx source
↩ module page · 52 lines · 3048 B
1// nx_wiki_publish_guard_sanity.nx -- READ-ONLY sanity run of the pre-publish guard against the REAL
2// emitted live page web_assets/nist_stem.html (-> nishifamily.com/wiki/nist_stem.html). It reads the
3// page bytes off disk (ss_readall) and runs pg_decide with the corpus = the slugs that page actually
4// links to. Expected verdict: PG_ALLOW (the page is fresh-stamped, has zero [[cite:...]] tokens, all
5// its /wiki/<x>.html links are in the corpus, and the body is real content). It writes NOTHING; it
6// only inspects + prints the verdict. license_tier: ORIGINAL
7import "nx_wiki_publish_guard.nx"
8import "nx_syscalls.nx"
9
10func s_w(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
11func s_num(v: i64) -> i64 {
12 let bb: *u8 = sys_mmap(28); var m: i64 = v; if m < 0 { m = 0 - m; sys_write(1, "-" as *u8, 1) }
13 let t: *u8 = sys_mmap(28); var k: i64 = 0
14 if m == 0 { t[0] = 48 as u8; k = 1 }
15 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 }
16 var i: i64 = 0; while i < k { bb[i] = t[k - 1 - i]; i = i + 1 }
17 sys_write(1, bb, k); return 0
18}
19func s_codename(v: i64) -> *u8 {
20 if v == PG_ALLOW { return "ALLOW" as *u8 }
21 if v == PG_REJECT_NO_FRESHNESS { return "REJECT NO_FRESHNESS" as *u8 }
22 if v == PG_REJECT_DANGLING_CITE { return "REJECT DANGLING_CITE" as *u8 }
23 if v == PG_REJECT_DEAD_LINK { return "REJECT DEAD_LINK" as *u8 }
24 if v == PG_REJECT_PLACEHOLDER { return "REJECT PLACEHOLDER" as *u8 }
25 return "UNKNOWN" as *u8
26}
27
28func main() -> i64 {
29 let szp: *i64 = sys_mmap(16) as *i64
30 let body: *u8 = ss_readall("web_assets/nist_stem.html" as *u8, szp)
31 let n: i64 = szp[0]
32 if n <= 0 { s_w("SANITY FATAL: could not read web_assets/nist_stem.html\n" as *u8); sys_exit(2); return 2 }
33 s_w("[sanity] read nist_stem.html bytes=" as *u8); s_num(n); s_w("\n" as *u8)
34
35 // corpus = the slugs the live page actually references via /wiki/<x>.html
36 // (nist_stem itself via the permalink/bookmark/alternate, start, charter, and search.html in the nav form)
37 let cs_ptr: *i64 = sys_mmap(8 * 8) as *i64
38 let cs_len: *i64 = sys_mmap(8 * 8) as *i64
39 cs_ptr[0] = "nist_stem" as *u8 as i64; cs_len[0] = 9
40 cs_ptr[1] = "start" as *u8 as i64; cs_len[1] = 5
41 cs_ptr[2] = "charter" as *u8 as i64; cs_len[2] = 7
42 cs_ptr[3] = "search" as *u8 as i64; cs_len[3] = 6
43 let ncorpus: i64 = 4
44
45 // production archive prefix (WAR_PREFIX) -- the page has zero cites so this is not exercised, but
46 // we pass the real prefix so the run is faithful to how the publisher would call it.
47 let v: i64 = pg_decide(WAR_PREFIX, body, n, cs_ptr, cs_len, ncorpus)
48 s_w("[sanity] nist_stem.html verdict=" as *u8); s_w(s_codename(v)); s_w(" (code=" as *u8); s_num(v); s_w(")\n" as *u8)
49 if v == PG_ALLOW { s_w("[sanity] OK -- the live page passes the guard (ALLOW)\n" as *u8); sys_exit(0); return 0 }
50 s_w("[sanity] the live page was REJECTED by the guard (see code above)\n" as *u8)
51 sys_exit(1); return 1
52}