code wiki / _hdl_build / nx_nishi_builder_gate.nx
nx_nishi_builder_gate.nx source
↩ module page · 67 lines · 4397 B
1// nx_nishi_builder_gate.nx -- GATE for THE NISHI BUILDER (universal, domain-aware). Hermetic (/tmp): teach
2// across ad/web/game -> count + round-trip, DOMAIN ISOLATION (an ad emitter is not visible in web), idempotent
3// re-teach, GROW (count increases), and the SOVEREIGNTY invariant (a <script/src= template is REJECTED in ANY
4// domain). Sovereign. license_tier: ORIGINAL
5import "nx_nishi_builder.nx"
6import "nx_ad_serve.nx"
7import "nx_syscalls.nx"
8
9const NG_PATH: *u8 = "/tmp/nishi_builder_gate.tsv"
10
11func g_p(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
12func g_i(v: i64) -> i64 { let t: *u8 = sys_mmap(24); var m: i64 = v; 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 } let o: *u8=sys_mmap(24); var w: i64=0; var q: i64=k-1; while q>=0 { o[w]=t[q]; w=w+1; q=q-1 } sys_write(1,o,w); return 0 }
13
14func main(argc: i64, argv: *i64) -> i64 {
15 g_p("=== nx_nishi_builder_gate ===\n" as *u8)
16 let fd: i64 = sys_openat_wr(NG_PATH, 420); if fd >= 0 { sys_close(fd) }
17 nb_register(NG_PATH, "ad" as *u8, "size" as *u8, "leaderboard" as *u8, "Leaderboard" as *u8, "728x90" as *u8)
18 nb_register(NG_PATH, "web" as *u8, "section" as *u8, "hero" as *u8, "Hero" as *u8, "<section><h1>{TITLE}</h1></section>" as *u8)
19 nb_register(NG_PATH, "game" as *u8, "mechanic" as *u8, "jump" as *u8, "Jump" as *u8, "impulse=12|gravity=0.6" as *u8)
20 var pass: i64 = 0; var tot: i64 = 0
21
22 // T1 cross-domain count + presence
23 tot = tot + 1; var ok1: i64 = 1
24 if nb_count(NG_PATH, "ad" as *u8, "*" as *u8) != 1 { ok1 = 0 }
25 if nb_count(NG_PATH, "web" as *u8, "*" as *u8) != 1 { ok1 = 0 }
26 if nb_count(NG_PATH, "game" as *u8, "*" as *u8) != 1 { ok1 = 0 }
27 if nb_present(NG_PATH, "web" as *u8, "section" as *u8, "hero" as *u8) != 1 { ok1 = 0 }
28 if ok1 == 1 { pass = pass + 1; g_p("PASS T1 cross-domain: ad/web/game each = 1, web hero present\n" as *u8) } else { g_p("FAIL T1\n" as *u8) }
29
30 // T2 round-trip the web hero template
31 let tpl: *u8 = sys_mmap(4096)
32 let got: i64 = nb_lookup(NG_PATH, "web" as *u8, "section" as *u8, "hero" as *u8, tpl)
33 tot = tot + 1; var ok2: i64 = 1
34 if got != 1 { ok2 = 0 }
35 if as_contains(tpl, as_len(tpl), "{TITLE}" as *u8) != 1 { ok2 = 0 }
36 if ok2 == 1 { pass = pass + 1; g_p("PASS T2 round-trip: web/section/hero template carries {TITLE}\n" as *u8) } else { g_p("FAIL T2\n" as *u8) }
37
38 // T3 DOMAIN ISOLATION: the ad emitter is NOT visible under web, and vice versa
39 tot = tot + 1; var ok3: i64 = 1
40 if nb_present(NG_PATH, "web" as *u8, "size" as *u8, "leaderboard" as *u8) != 0 { ok3 = 0 }
41 if nb_present(NG_PATH, "ad" as *u8, "section" as *u8, "hero" as *u8) != 0 { ok3 = 0 }
42 if ok3 == 1 { pass = pass + 1; g_p("PASS T3 domain isolation: emitters scoped to their domain\n" as *u8) } else { g_p("FAIL T3\n" as *u8) }
43
44 // T4 idempotent re-teach
45 let r: i64 = nb_register(NG_PATH, "web" as *u8, "section" as *u8, "hero" as *u8, "Hero" as *u8, "<section/>" as *u8)
46 tot = tot + 1; var ok4: i64 = 1
47 if r != 0 { ok4 = 0 }
48 if nb_count(NG_PATH, "web" as *u8, "*" as *u8) != 1 { ok4 = 0 }
49 if ok4 == 1 { pass = pass + 1; g_p("PASS T4 idempotent: re-teach returns 0, count unchanged\n" as *u8) } else { g_p("FAIL T4\n" as *u8) }
50
51 // T5 GROW a domain
52 nb_register(NG_PATH, "web" as *u8, "section" as *u8, "card" as *u8, "Card" as *u8, "<article>{BODY}</article>" as *u8)
53 tot = tot + 1
54 if nb_count(NG_PATH, "web" as *u8, "*" as *u8) == 2 { pass = pass + 1; g_p("PASS T5 grow: web 1->2 (the builder grew a domain)\n" as *u8) } else { g_p("FAIL T5\n" as *u8) }
55
56 // T6 SOVEREIGNTY invariant across domains
57 tot = tot + 1; var ok6: i64 = 1
58 if nb_template_safe("<section><h1>hi</h1></section>" as *u8) != 1 { ok6 = 0 }
59 if nb_template_safe("<script>x</script>" as *u8) != 0 { ok6 = 0 }
60 if nb_template_safe("<img src='//cdn/x'>" as *u8) != 0 { ok6 = 0 }
61 if ok6 == 1 { pass = pass + 1; g_p("PASS T6 sovereignty: clean safe; <script + src= REJECTED in any domain\n" as *u8) } else { g_p("FAIL T6\n" as *u8) }
62
63 g_p("nx_nishi_builder_gate pass=" as *u8); g_i(pass); g_p("/" as *u8); g_i(tot)
64 if pass == tot { g_p(" verdict=GREEN (ONE builder, MANY domains, sovereign-safe, self-growing)\n" as *u8); return 0 }
65 g_p(" verdict=RED\n" as *u8)
66 return 1
67}