code wiki / _hdl_build / nx_hub_template_gate.nx

nx_hub_template_gate.nx source

↩ module page · 88 lines · 4355 B

1// nx_hub_template_gate.nx -- SOVEREIGN in-process gate for the personal-hub template emitter. Feeds a fixture 2// `.hub` blueprint into the PURE ht_emit_hub and asserts the rendered hub page: header/tagline, Blog (with HTML 3// escaping), Videos (+ publish-from-phone CTA), Calendar (event with coach + shared-calendar CTA), Friends (link 4// + video-chat). The load-bearing neg-control = a <script> in post content must be ESCAPED, never emitted raw 5// (XSS defense at the boundary -- migrated/user content is untrusted). GREEN iff T1..T8. license_tier: ORIGINAL 6import "nx_hub_template.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_contains(hay: *u8, n: i64, needle: *u8) -> i64 { 17 let nn: i64 = g_len(needle) 18 var i: i64 = 0 19 while i + nn <= n { 20 var m: i64 = 1 21 var j: i64 = 0 22 while j < nn { if (hay[i + j] as i64) != (needle[j] as i64) { m = 0; j = nn } else { j = j + 1 } } 23 if m == 1 { return 1 } 24 i = i + 1 25 } 26 return 0 27} 28 29func main() -> i64 { 30 g_w("hub-template SOVEREIGN gate (pure .hub -> hub HTML, in-process)\n" as *u8) 31 let cfg: *u8 = "name|Brad West\ntagline|Train and connect\npost|Hello & welcome|2026-06-29|Body with <script>alert(1)</script> here\nvideo|My Clip|/v/clip\nevent|Jul 1|Training|Coach\nfriend|Jensen West|https://jensendwest.com\nfooter|Brad West hub\x00" as *u8 32 let cn: i64 = g_len(cfg) 33 let out: *u8 = sys_mmap(1048576) 34 let on: i64 = ht_emit_hub(cfg, cn, out) 35 var pass: i64 = 0 36 37 pass = pass + g_row("T1 header shows the name (<h1>Brad West</h1>)\x00" as *u8, g_contains(out, on, "<h1>Brad West</h1>" as *u8)) 38 pass = pass + g_row("T2 tagline rendered\x00" as *u8, g_contains(out, on, "Train and connect" as *u8)) 39 pass = pass + g_row("T3 Blog post with '&' HTML-escaped (Hello &amp; welcome)\x00" as *u8, g_contains(out, on, "<h3>Hello &amp; welcome</h3>" as *u8)) 40 41 var t4: i64 = 0 42 if g_contains(out, on, "&lt;script&gt;" as *u8) == 1 { if g_contains(out, on, "<script>alert" as *u8) == 0 { t4 = 1 } } 43 pass = pass + g_row("T4 NEG: <script> ESCAPED, not emitted raw (XSS-safe boundary)\x00" as *u8, t4) 44 45 var t5: i64 = 0 46 if g_contains(out, on, "/v/clip" as *u8) == 1 { 47 if g_contains(out, on, "My Clip" as *u8) == 1 { 48 if g_contains(out, on, "Publish a video from your phone" as *u8) == 1 { t5 = 1 } 49 } 50 } 51 pass = pass + g_row("T5 Videos tile + 'publish from your phone' CTA\x00" as *u8, t5) 52 53 var t6: i64 = 0 54 if g_contains(out, on, "Training" as *u8) == 1 { 55 if g_contains(out, on, "with Coach" as *u8) == 1 { 56 if g_contains(out, on, "shared calendar" as *u8) == 1 { t6 = 1 } 57 } 58 } 59 pass = pass + g_row("T6 Calendar event (with Coach) + shared-calendar CTA\x00" as *u8, t6) 60 61 var t7: i64 = 0 62 if g_contains(out, on, "https://jensendwest.com" as *u8) == 1 { 63 if g_contains(out, on, "/meet?with=Jensen West" as *u8) == 1 { t7 = 1 } 64 } 65 pass = pass + g_row("T7 Friends link (jensendwest.com) + video-chat (/meet?with=)\x00" as *u8, t7) 66 67 var t8: i64 = 0 68 if g_contains(out, on, "id=blog" as *u8) == 1 { 69 if g_contains(out, on, "id=videos" as *u8) == 1 { 70 if g_contains(out, on, "id=cal" as *u8) == 1 { 71 if g_contains(out, on, "id=friends" as *u8) == 1 { 72 if g_contains(out, on, "<footer>Brad West hub</footer>" as *u8) == 1 { t8 = 1 } 73 } 74 } 75 } 76 } 77 pass = pass + g_row("T8 all 4 sections (blog/videos/cal/friends) + footer\x00" as *u8, t8) 78 79 if pass == 8 { 80 let lg: i64 = sys_openat_append("knowledge/status/hub_template_gate.log" as *u8, 0x1a4) 81 if lg >= 0 { sys_write(lg, "HUB-TEMPLATE-GATE pass=8/8 verdict=GREEN\n" as *u8, 40); sys_close(lg) } 82 g_w("HUB-TEMPLATE GATE GREEN 8/8 (blog/organizer/hub: blog+video+calendar+friends+video-chat, XSS-safe)\n" as *u8) 83 sys_exit(0) 84 } 85 g_w("HUB-TEMPLATE GATE RED\n" as *u8) 86 sys_exit(1) 87 return 1 88}