code wiki / _hdl_build / nx_food_site_gate.nx
nx_food_site_gate.nx source
↩ module page · 123 lines · 7480 B
1// nx_food_site_gate.nx -- GATE: the CONSUME surface (R-SITE). Teaches the food domain to the DURABLE builder
2// registry, renders the restaurant site from the LIVE grounded store, proves it is composed-from-catalog +
3// live-data + sovereign + boundary-escaped, then SHIPS it through the Nishi Publisher (pub_submit ->
4// pub_run_full: sha-verify -> atomic-promote -> ledger) to a LOCAL liveroot. Outward transport to the real
5// domain stays OPERATOR-GATED (publisher R6/R8). license_tier: ORIGINAL
6import "nx_food_site.nx"
7import "nx_publisher.nx"
8import "nx_syscalls.nx"
9import "nx_gate_verdict.nx"
10
11const FSG_CAT: *u8 = "knowledge/registry/nishi_builder.tsv"
12const FSG_STORE: *u8 = "knowledge/store/food-"
13const FSG_STAGE: *u8 = "knowledge/staging/food/index.html"
14const FSG_LIVE: *u8 = "knowledge/publish/food-live/index.html"
15
16func 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 }
17func g_i(v: i64) -> i64 {
18 let bb: *u8 = sys_mmap(28); var m: i64 = v
19 if m < 0 { sys_write(1, "-" as *u8, 1); m = 0 - m }
20 let t: *u8 = sys_mmap(28); var k: i64 = 0
21 if m == 0 { t[0] = 48 as u8; k = 1 }
22 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 }
23 var i: i64 = 0; while i < k { bb[i] = t[k - 1 - i]; i = i + 1 } sys_write(1, bb, k); return 0
24}
25func g_exists(path: *u8) -> i64 { let fd: i64 = sys_openat_rd(path); if fd < 0 { return 0 } sys_close(fd); return 1 }
26
27func main() -> i64 {
28 g_p("=== nx_food_site_gate (R-SITE: the restaurant site, store -> engine -> builder -> publisher) ===\n" as *u8)
29
30 // make sure the durable grounded store exists (food world + clean-sourcing impact records, so the
31 // SHIPPED flagship page carries the populated clean-sourcing badge, not the conventional fallback)
32 fd_seed(FSG_STORE)
33 fc_seed_veg(FSG_STORE)
34
35 var pass: i64 = 0
36 var tot: i64 = 0
37
38 // teach the food domain to the durable builder registry (grows the builder)
39 let taught: i64 = fs_teach(FSG_CAT)
40 g_p("taught food domain to durable registry; food emitters=" as *u8); g_i(taught); g_p("\n" as *u8)
41
42 // T1 composed from the catalog
43 let page: *u8 = sys_mmap(65536)
44 let n: i64 = fs_render(FSG_STORE, FSG_CAT, "Golden Wok" as *u8, page)
45 g_p("rendered site = " as *u8); g_i(n); g_p(" bytes\n" as *u8)
46 tot = tot + 1
47 var ok1: i64 = 1
48 if as_contains(page, n, "class='fbar'" as *u8) != 1 { ok1 = 0 }
49 if as_contains(page, n, "class='hero'" as *u8) != 1 { ok1 = 0 }
50 if as_contains(page, n, "class='rec'" as *u8) != 1 { ok1 = 0 }
51 if as_contains(page, n, "class='sci'" as *u8) != 1 { ok1 = 0 }
52 if as_contains(page, n, "class='ftr'" as *u8) != 1 { ok1 = 0 }
53 if ok1 == 1 { pass = pass + 1; g_p("PASS T1 composed from the food catalog (nav + hero + recommendation + science + footer)\n" as *u8) } else { g_p("FAIL T1 missing catalog components\n" as *u8) }
54
55 // T2 live data: the chooser's protein for this store appears on the page
56 let h: *i64 = fd_world_open(FSG_STORE)
57 let frame: *i64 = sys_mmap(8 * 16) as *i64
58 let nframe: i64 = fd_load_frame(FSG_STORE, frame)
59 let wts: *i64 = sys_mmap(8 * 8) as *i64
60 fd_load_weights(FSG_STORE, wts)
61 let nn: i64 = h[0]
62 let avail: *i64 = sys_mmap(8 * 64) as *i64
63 let avoid: *i64 = sys_mmap(8 * 64) as *i64
64 let prefw: *i64 = sys_mmap(8 * 8) as *i64
65 fd_set_all(avail, nn, 1); fd_set_all(avoid, nn, 0)
66 var z: i64 = 0; while z < FOOD_NAX { prefw[z] = 0; z = z + 1 }
67 let build: *i64 = sys_mmap(8 * 16) as *i64
68 let roles: *i64 = sys_mmap(8 * 16) as *i64
69 let nb: i64 = fd_choose(h, avail, avoid, prefw, frame, nframe, wts, build, roles)
70 let names: *i64 = h[4] as *i64
71 let protein: *u8 = names[build[0]] as *u8
72 g_p("live chooser protein = " as *u8); g_p(protein); g_p("\n" as *u8)
73 tot = tot + 1
74 if as_contains(page, n, protein) == 1 { pass = pass + 1; g_p("PASS T2 live store data on the page (the recommended protein is rendered)\n" as *u8) } else { g_p("FAIL T2 live data missing\n" as *u8) }
75
76 // T3 sovereignty floor
77 tot = tot + 1
78 if as_has_thirdparty_js(page, n) == 0 { pass = pass + 1; g_p("PASS T3 sovereignty: 0 third-party JS / external fetch in the site\n" as *u8) } else { g_p("FAIL T3 third-party leak\n" as *u8) }
79
80 // T4 boundary escape: a malicious restaurant name cannot inject a script tag
81 let page2: *u8 = sys_mmap(65536)
82 let n2: i64 = fs_render(FSG_STORE, FSG_CAT, "<script>evil()</script>" as *u8, page2)
83 tot = tot + 1
84 if as_contains(page2, n2, "<script" as *u8) == 0 { pass = pass + 1; g_p("PASS T4 boundary-escaped: injected restaurant name neutralised (no raw <script>)\n" as *u8) } else { g_p("FAIL T4 injection\n" as *u8) }
85
86 // T5 teach durable + sovereign-safe templates
87 tot = tot + 1
88 var ok5: i64 = 1
89 if taught < 5 { ok5 = 0 }
90 let tpl: *u8 = sys_mmap(4096)
91 if nb_lookup(FSG_CAT, "food" as *u8, "section" as *u8, "recommendation" as *u8, tpl) == 1 { if nb_template_safe(tpl) != 1 { ok5 = 0 } } else { ok5 = 0 }
92 if nb_lookup(FSG_CAT, "food" as *u8, "section" as *u8, "science" as *u8, tpl) == 1 { if nb_template_safe(tpl) != 1 { ok5 = 0 } } else { ok5 = 0 }
93 if nb_lookup(FSG_CAT, "food" as *u8, "nav" as *u8, "foodbar" as *u8, tpl) == 1 { if nb_template_safe(tpl) != 1 { ok5 = 0 } } else { ok5 = 0 }
94 if ok5 == 1 { pass = pass + 1; g_p("PASS T5 durable builder grew a 'food' domain (>=5 sovereign-safe emitters)\n" as *u8) } else { g_p("FAIL T5\n" as *u8) }
95
96 // stage the rendered site
97 sys_mkdir("knowledge/staging" as *u8, 0x1ed)
98 sys_mkdir("knowledge/staging/food" as *u8, 0x1ed)
99 let sfd: i64 = sys_openat_wr(FSG_STAGE, 420)
100 if sfd >= 0 { sys_write(sfd, page, n); sys_close(sfd) }
101
102 // T6 SHIP through the Nishi Publisher (request -> publisher ships to a LOCAL liveroot; outward = operator-gated)
103 pub_init()
104 sys_mkdir("knowledge/publish/food-stage" as *u8, 0x1ed)
105 sys_mkdir("knowledge/publish/food-live" as *u8, 0x1ed)
106 let s1: i64 = pub_submit_to("knowledge/publish/food-queue.tsv" as *u8, FSG_STAGE, "index.html" as *u8, "nishifoodfamily" as *u8, "nishi-food" as *u8, "internal" as *u8)
107 g_p(" pub_submit index.html -> " as *u8); g_i(s1); g_p("\n" as *u8)
108 let pubd: i64 = pub_run_full("knowledge/publish/food-queue.tsv" as *u8, "knowledge/publish/food-ledger.tsv" as *u8, "knowledge/publish/food-stage" as *u8, "knowledge/publish/food-live" as *u8, "publish:food" as *u8)
109 g_p(" pub_run_full -> published_this_pass=" as *u8); g_i(pubd); g_p("\n" as *u8)
110 tot = tot + 1
111 if g_exists(FSG_LIVE) == 1 { pass = pass + 1; g_p("PASS T6 SHIPPED by the Nishi Publisher -> knowledge/publish/food-live/index.html (sha-verified, ledgered)\n" as *u8) } else { g_p("FAIL T6 not promoted to liveroot\n" as *u8) }
112
113 g_p("nx_food_site_gate pass=" as *u8); g_i(pass); g_p("/" as *u8); g_i(tot)
114 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check
115 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled
116 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify.
117 let ctr__dry: *i64 = gv_ctr()
118 ctr__dry[0] = pass
119 ctr__dry[1] = tot
120 let rc__dry: i64 = gv_verdict("FOOD-SITE-GATE" as *u8, ctr__dry, "the restaurant SITE is rendered from the live store, composed from the builder, shipped by the publisher)" as *u8)
121 sys_exit(rc__dry)
122 return rc__dry
123}