code wiki / _hdl_build / nx_hub_provision_gate.nx
nx_hub_provision_gate.nx source
↩ module page · 69 lines · 3866 B
1// nx_hub_provision_gate.nx -- SOVEREIGN in-process gate for standalone-domain hub provisioning. Writes a fixture
2// .hub, provisions it to /tmp, and asserts: the docroot index.html rendered the hub, the sites.conf got a
3// `<domain>\t<docroot>` host->docroot line (so sites.elf serves bradrwest.com as its OWN domain, not a nishifamily
4// path), the manifest marks it standalone, and a MISSING config is REFUSED (fail-closed). GREEN iff T1..T5.
5// Sovereign: nx_hub_provision + nx_syscalls. license_tier: ORIGINAL
6import "nx_hub_provision.nx"
7import "nx_syscalls.nx"
8
9func 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 }
10func g_len(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
11func g_row(name: *u8, ok: i64) -> i64 {
12 if ok == 1 { g_w(" PASS " as *u8) } else { g_w(" FAIL " as *u8) }
13 g_w(name); g_w("\n" as *u8)
14 return ok
15}
16func g_trunc(path: *u8) -> i64 { let fd: i64 = sys_openat_wr(path, 0x180); if fd >= 0 { sys_close(fd) } return 0 }
17func g_writef(path: *u8, s: *u8) -> i64 { let fd: i64 = sys_openat_wr(path, 0x180); if fd < 0 { return 0 - 1 } sys_write(fd, s, g_len(s)); sys_close(fd); return 0 }
18func g_contains_file(path: *u8, needle: *u8) -> i64 {
19 let szb: *i64 = sys_mmap(16) as *i64
20 szb[0] = 0
21 let buf: *u8 = sys_read_file(path, szb)
22 if (buf as i64) == 0 { return 0 }
23 let n: i64 = szb[0]
24 let nn: i64 = g_len(needle)
25 var i: i64 = 0
26 while i + nn <= n {
27 var m: i64 = 1
28 var j: i64 = 0
29 while j < nn { if (buf[i + j] as i64) != (needle[j] as i64) { m = 0; j = nn } else { j = j + 1 } }
30 if m == 1 { return 1 }
31 i = i + 1
32 }
33 return 0
34}
35
36func main() -> i64 {
37 g_w("hub-provision SOVEREIGN gate (.hub -> standalone domain site: docroot + sites.conf + manifest)\n" as *u8)
38 let hub: *u8 = "/tmp/nx_hp_test.hub" as *u8
39 let idx: *u8 = "/tmp/nx_hp_idx.html" as *u8
40 let conf: *u8 = "/tmp/nx_hp_sites.conf" as *u8
41 let man: *u8 = "/tmp/nx_hp_manifest" as *u8
42 g_trunc(conf)
43 g_writef(hub, "name|Brad West\ntagline|Test\npost|Hi|2026-06-29|Body\nvideo|Clip|/v/c\nevent|Jul 1|Train|Coach\nfriend|Jensen West|https://jensendwest.com\nfooter|Brad West hub\x00" as *u8)
44
45 let rc: i64 = hp_provision("bradrwest.com" as *u8, hub, idx, conf, man)
46 var pass: i64 = 0
47
48 pass = pass + g_row("T1 hp_provision returned 0 (provisioned)\x00" as *u8, (rc == 0) as i64)
49 pass = pass + g_row("T2 docroot index.html rendered the hub (<h1>Brad West</h1>)\x00" as *u8, g_contains_file(idx, "<h1>Brad West</h1>" as *u8))
50 pass = pass + g_row("T3 sites.conf got the host->docroot line (bradrwest.com TAB /tmp/nx_hp_idx.html)\x00" as *u8, g_contains_file(conf, "bradrwest.com\t/tmp/nx_hp_idx.html" as *u8))
51
52 var t4: i64 = 0
53 if g_contains_file(man, "PROVISIONED-HUB domain=bradrwest.com" as *u8) == 1 { if g_contains_file(man, "standalone=1" as *u8) == 1 { t4 = 1 } }
54 pass = pass + g_row("T4 manifest marks it a STANDALONE domain site\x00" as *u8, t4)
55
56 // NEG: a missing config must be REFUSED (fail-closed; nothing provisioned).
57 let rcn: i64 = hp_provision("nope.com" as *u8, "/tmp/nx_hp_DOES_NOT_EXIST.hub" as *u8, "/tmp/nx_hp_neg.html" as *u8, conf, "/tmp/nx_hp_neg_man" as *u8)
58 pass = pass + g_row("T5 NEG: missing config -> REFUSED (rc<0, fail-closed)\x00" as *u8, (rcn < 0) as i64)
59
60 if pass == 5 {
61 let lg: i64 = sys_openat_append("knowledge/status/hub_provision_gate.log" as *u8, 0x1a4)
62 if lg >= 0 { sys_write(lg, "HUB-PROVISION-GATE pass=5/5 verdict=GREEN\n" as *u8, 41); sys_close(lg) }
63 g_w("HUB-PROVISION GATE GREEN 5/5 (standalone domain site: docroot + host->docroot map + manifest, fail-closed)\n" as *u8)
64 sys_exit(0)
65 }
66 g_w("HUB-PROVISION GATE RED\n" as *u8)
67 sys_exit(1)
68 return 1
69}