code wiki / _hdl_build / nx_food_site_gate.nx

nx_food_site_gate.nx source

↩ module page · 116 lines · 7082 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" 9 10const FSG_CAT: *u8 = "knowledge/registry/nishi_builder.tsv" 11const FSG_STORE: *u8 = "knowledge/store/food-" 12const FSG_STAGE: *u8 = "knowledge/staging/food/index.html" 13const FSG_LIVE: *u8 = "knowledge/publish/food-live/index.html" 14 15func 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 } 16func g_i(v: i64) -> i64 { 17 let bb: *u8 = sys_mmap(28); var m: i64 = v 18 if m < 0 { sys_write(1, "-" as *u8, 1); m = 0 - m } 19 let t: *u8 = sys_mmap(28); var k: i64 = 0 20 if m == 0 { t[0] = 48 as u8; k = 1 } 21 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 22 var i: i64 = 0; while i < k { bb[i] = t[k - 1 - i]; i = i + 1 } sys_write(1, bb, k); return 0 23} 24func g_exists(path: *u8) -> i64 { let fd: i64 = sys_openat_rd(path); if fd < 0 { return 0 } sys_close(fd); return 1 } 25 26func main() -> i64 { 27 g_p("=== nx_food_site_gate (R-SITE: the restaurant site, store -> engine -> builder -> publisher) ===\n" as *u8) 28 29 // make sure the durable grounded store exists (food world + clean-sourcing impact records, so the 30 // SHIPPED flagship page carries the populated clean-sourcing badge, not the conventional fallback) 31 fd_seed(FSG_STORE) 32 fc_seed_veg(FSG_STORE) 33 34 var pass: i64 = 0 35 var tot: i64 = 0 36 37 // teach the food domain to the durable builder registry (grows the builder) 38 let taught: i64 = fs_teach(FSG_CAT) 39 g_p("taught food domain to durable registry; food emitters=" as *u8); g_i(taught); g_p("\n" as *u8) 40 41 // T1 composed from the catalog 42 let page: *u8 = sys_mmap(65536) 43 let n: i64 = fs_render(FSG_STORE, FSG_CAT, "Golden Wok" as *u8, page) 44 g_p("rendered site = " as *u8); g_i(n); g_p(" bytes\n" as *u8) 45 tot = tot + 1 46 var ok1: i64 = 1 47 if as_contains(page, n, "class='fbar'" as *u8) != 1 { ok1 = 0 } 48 if as_contains(page, n, "class='hero'" as *u8) != 1 { ok1 = 0 } 49 if as_contains(page, n, "class='rec'" as *u8) != 1 { ok1 = 0 } 50 if as_contains(page, n, "class='sci'" as *u8) != 1 { ok1 = 0 } 51 if as_contains(page, n, "class='ftr'" as *u8) != 1 { ok1 = 0 } 52 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) } 53 54 // T2 live data: the chooser's protein for this store appears on the page 55 let h: *i64 = fd_world_open(FSG_STORE) 56 let frame: *i64 = sys_mmap(8 * 16) as *i64 57 let nframe: i64 = fd_load_frame(FSG_STORE, frame) 58 let wts: *i64 = sys_mmap(8 * 8) as *i64 59 fd_load_weights(FSG_STORE, wts) 60 let nn: i64 = h[0] 61 let avail: *i64 = sys_mmap(8 * 64) as *i64 62 let avoid: *i64 = sys_mmap(8 * 64) as *i64 63 let prefw: *i64 = sys_mmap(8 * 8) as *i64 64 fd_set_all(avail, nn, 1); fd_set_all(avoid, nn, 0) 65 var z: i64 = 0; while z < FOOD_NAX { prefw[z] = 0; z = z + 1 } 66 let build: *i64 = sys_mmap(8 * 16) as *i64 67 let roles: *i64 = sys_mmap(8 * 16) as *i64 68 let nb: i64 = fd_choose(h, avail, avoid, prefw, frame, nframe, wts, build, roles) 69 let names: *i64 = h[4] as *i64 70 let protein: *u8 = names[build[0]] as *u8 71 g_p("live chooser protein = " as *u8); g_p(protein); g_p("\n" as *u8) 72 tot = tot + 1 73 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) } 74 75 // T3 sovereignty floor 76 tot = tot + 1 77 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) } 78 79 // T4 boundary escape: a malicious restaurant name cannot inject a script tag 80 let page2: *u8 = sys_mmap(65536) 81 let n2: i64 = fs_render(FSG_STORE, FSG_CAT, "<script>evil()</script>" as *u8, page2) 82 tot = tot + 1 83 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) } 84 85 // T5 teach durable + sovereign-safe templates 86 tot = tot + 1 87 var ok5: i64 = 1 88 if taught < 5 { ok5 = 0 } 89 let tpl: *u8 = sys_mmap(4096) 90 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 } 91 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 } 92 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 } 93 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) } 94 95 // stage the rendered site 96 sys_mkdir("knowledge/staging" as *u8, 0x1ed) 97 sys_mkdir("knowledge/staging/food" as *u8, 0x1ed) 98 let sfd: i64 = sys_openat_wr(FSG_STAGE, 420) 99 if sfd >= 0 { sys_write(sfd, page, n); sys_close(sfd) } 100 101 // T6 SHIP through the Nishi Publisher (request -> publisher ships to a LOCAL liveroot; outward = operator-gated) 102 pub_init() 103 sys_mkdir("knowledge/publish/food-stage" as *u8, 0x1ed) 104 sys_mkdir("knowledge/publish/food-live" as *u8, 0x1ed) 105 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) 106 g_p(" pub_submit index.html -> " as *u8); g_i(s1); g_p("\n" as *u8) 107 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) 108 g_p(" pub_run_full -> published_this_pass=" as *u8); g_i(pubd); g_p("\n" as *u8) 109 tot = tot + 1 110 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) } 111 112 g_p("nx_food_site_gate pass=" as *u8); g_i(pass); g_p("/" as *u8); g_i(tot) 113 if pass == tot { g_p(" verdict=GREEN (the restaurant SITE is rendered from the live store, composed from the builder, shipped by the publisher)\n" as *u8); return 0 } 114 g_p(" verdict=RED\n" as *u8) 115 return 1 116}