code wiki / _hdl_build / nx_food_clean_source_gate.nx
nx_food_clean_source_gate.nx source
↩ module page · 131 lines · 8287 B
1// nx_food_clean_source_gate.nx -- GATE: R-IMPACT-3, the clean-sourcing badge joins the stir-fry SITE to the
2// impact ECONOMICS. T1 the stir-fry vegetables are seeded into the impact catalog (coverage probe). T2 HONEST:
3// a non-catalog ingredient (protein/sauce) is NOT claimed covered. T3 every seeded veg triple-wins (cleaner +
4// greener + cheaper + higher-margin), so the badge can't greenwash. T4 the per-build savings aggregate is
5// correct over covered veg only. T5 the badge renders with measured clean scores + savings, sovereign no-JS.
6// T6 END-TO-END: the badge appears on the REAL rendered restaurant site (fs_render_restaurant) ALONGSIDE the
7// existing science + recommendation sections (no regression), still sovereign. license_tier: ORIGINAL
8import "nx_food_clean_source.nx"
9import "nx_food_menu.nx"
10import "nx_syscalls.nx"
11import "nx_gate_verdict.nx"
12
13const FCS_CAT: *u8 = "knowledge/registry/nishi_builder.tsv"
14const FCS_STORE: *u8 = "knowledge/store/food-"
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_money(c: i64) -> i64 { let b: *u8 = sys_mmap(24); let o: i64 = im_money(b, 0, c); sys_write(1, b, o); return 0 }
26
27func main() -> i64 {
28 g_p("=== nx_food_clean_source_gate (R-IMPACT-3: clean-sourcing badge on the stir-fry site) ===\n" as *u8)
29 fd_seed(FCS_STORE)
30 fd_seed_restaurants(FCS_STORE)
31 let sw: i64 = fc_seed_veg(FCS_STORE)
32 g_p("veg impact records authored this run=" as *u8); g_i(sw); g_p("\n" as *u8)
33 fs_teach(FCS_CAT)
34
35 let h: *i64 = fd_world_open(FCS_STORE)
36
37 var pass: i64 = 0
38 var tot: i64 = 0
39
40 // T1 the stir-fry vegetables are now catalog-covered (durable readback, not first-write)
41 tot = tot + 1
42 var ok1: i64 = 1
43 if fc_covered(FCS_STORE, "broccoli" as *u8) != 1 { ok1 = 0 }
44 if fc_covered(FCS_STORE, "onion" as *u8) != 1 { ok1 = 0 }
45 if fc_covered(FCS_STORE, "snowpea" as *u8) != 1 { ok1 = 0 }
46 if fc_covered(FCS_STORE, "bokchoy" as *u8) != 1 { ok1 = 0 }
47 if fc_covered(FCS_STORE, "garlic" as *u8) != 1 { ok1 = 0 }
48 if ok1 == 1 { pass = pass + 1; g_p("PASS T1 stir-fry vegetables covered in the impact catalog (broccoli/onion/snowpea/bokchoy/garlic)\n" as *u8) } else { g_p("FAIL T1 coverage\n" as *u8) }
49
50 // T2 HONEST: ingredients NOT in the catalog are not claimed covered (no overclaim)
51 tot = tot + 1
52 var ok2: i64 = 1
53 if fc_covered(FCS_STORE, "beef" as *u8) != 0 { ok2 = 0 }
54 if fc_covered(FCS_STORE, "soy" as *u8) != 0 { ok2 = 0 }
55 if fc_covered(FCS_STORE, "chili" as *u8) != 0 { ok2 = 0 }
56 if fc_covered(FCS_STORE, "unicorn" as *u8) != 0 { ok2 = 0 }
57 if ok2 == 1 { pass = pass + 1; g_p("PASS T2 honest: non-catalog ingredients (beef/soy/chili/unknown) reported NOT covered\n" as *u8) } else { g_p("FAIL T2 overclaim\n" as *u8) }
58
59 // T3 every seeded veg is a genuine triple win (so the clean badge can't greenwash)
60 let slugs: *i64 = sys_mmap(8 * 16) as *i64
61 var ns: i64 = 0
62 slugs[ns] = "broccoli" as *u8 as i64; ns = ns + 1
63 slugs[ns] = "onion" as *u8 as i64; ns = ns + 1
64 slugs[ns] = "carrot" as *u8 as i64; ns = ns + 1
65 slugs[ns] = "snowpea" as *u8 as i64; ns = ns + 1
66 slugs[ns] = "mushroom" as *u8 as i64; ns = ns + 1
67 slugs[ns] = "bokchoy" as *u8 as i64; ns = ns + 1
68 slugs[ns] = "beansprout" as *u8 as i64; ns = ns + 1
69 slugs[ns] = "garlic" as *u8 as i64; ns = ns + 1
70 slugs[ns] = "ginger" as *u8 as i64; ns = ns + 1
71 var wins: i64 = 0
72 var si: i64 = 0
73 while si < ns { if im_triple_win(FCS_STORE, slugs[si] as *u8) == 1 { wins = wins + 1 } si = si + 1 }
74 g_p("triple-win veg=" as *u8); g_i(wins); g_p("/" as *u8); g_i(ns); g_p("\n" as *u8)
75 tot = tot + 1
76 if wins == ns { pass = pass + 1; g_p("PASS T3 every seeded vegetable is cleaner+greener+cheaper AND higher-margin (no greenwash)\n" as *u8) } else { g_p("FAIL T3 wins=" as *u8); g_i(wins); g_p("\n" as *u8) }
77
78 // T4 per-build savings aggregate over covered veg only. Construct a build: broccoli + snow peas.
79 let build: *i64 = sys_mmap(8 * 8) as *i64
80 let roles: *i64 = sys_mmap(8 * 8) as *i64
81 build[0] = fd_index_of(h, "broccoli" as *u8); roles[0] = FROLE_VEG
82 build[1] = fd_index_of(h, "snowpea" as *u8); roles[1] = FROLE_VEG
83 let cov: i64 = fc_build_covered(FCS_STORE, h, build, roles, 2)
84 let sav: i64 = fc_build_savings(FCS_STORE, h, build, roles, 2)
85 let expect: i64 = im_savings(FCS_STORE, "broccoli" as *u8, "nishi" as *u8, "conv" as *u8) + im_savings(FCS_STORE, "snowpea" as *u8, "nishi" as *u8, "conv" as *u8)
86 g_p("build covered=" as *u8); g_i(cov); g_p(" savings=" as *u8); g_money(sav); g_p(" expect=" as *u8); g_money(expect); g_p("\n" as *u8)
87 tot = tot + 1
88 if cov == 2 { if sav == expect { if sav > 0 { pass = pass + 1; g_p("PASS T4 per-build savings correct over covered veg (broccoli+snowpea)\n" as *u8) } else { g_p("FAIL T4 not positive\n" as *u8) } } else { g_p("FAIL T4 sum\n" as *u8) } } else { g_p("FAIL T4 cov=" as *u8); g_i(cov); g_p("\n" as *u8) }
89
90 // T5 the badge renders with measured clean scores + savings + disclaimer, sovereign (no third-party JS)
91 let frag: *u8 = sys_mmap(16384)
92 let nf: i64 = fc_render_badge(FCS_STORE, h, build, roles, 2, frag, 0)
93 frag[nf] = 0 as u8
94 tot = tot + 1
95 var ok5: i64 = 1
96 if as_contains(frag, nf, "Clean sourcing" as *u8) != 1 { ok5 = 0 }
97 if as_contains(frag, nf, "Broccoli" as *u8) != 1 { ok5 = 0 }
98 if as_contains(frag, nf, "Snow Peas" as *u8) != 1 { ok5 = 0 }
99 if as_contains(frag, nf, "save $" as *u8) != 1 { ok5 = 0 }
100 if as_contains(frag, nf, "regenerative-agriculture corpus" as *u8) != 1 { ok5 = 0 }
101 if as_has_thirdparty_js(frag, nf) != 0 { ok5 = 0 }
102 if ok5 == 1 { pass = pass + 1; g_p("PASS T5 badge: measured clean scores + savings + cited disclaimer, 0 third-party JS\n" as *u8) } else { g_p("FAIL T5\n" as *u8) }
103
104 // T6 END-TO-END: the badge appears on the REAL rendered restaurant site, with no regression.
105 let page: *u8 = sys_mmap(65536)
106 let np: i64 = fs_render_restaurant(FCS_STORE, FCS_CAT, "greenwok" as *u8, page)
107 g_p("rendered greenwok site = " as *u8); g_i(np); g_p(" bytes\n" as *u8)
108 tot = tot + 1
109 var ok6: i64 = 1
110 if np <= 0 { ok6 = 0 }
111 if as_contains(page, np, "Clean sourcing" as *u8) != 1 { ok6 = 0 } // the new badge is wired in
112 if as_contains(page, np, "save $" as *u8) != 1 { ok6 = 0 } // populated (>=1 covered veg)
113 if as_contains(page, np, "class='sci'" as *u8) != 1 { ok6 = 0 } // science section still present
114 if as_contains(page, np, "class='rec'" as *u8) != 1 { ok6 = 0 } // recommendation still present
115 if as_has_thirdparty_js(page, np) != 0 { ok6 = 0 } // still sovereign
116 sys_mkdir("knowledge/staging" as *u8, 0x1ed)
117 sys_mkdir("knowledge/staging/food" as *u8, 0x1ed)
118 let sfd: i64 = sys_openat_wr("knowledge/staging/food/greenwok_clean.html" as *u8, 420); if sfd >= 0 { sys_write(sfd, page, np); sys_close(sfd) }
119 if ok6 == 1 { pass = pass + 1; g_p("PASS T6 END-TO-END: clean-sourcing badge on the live restaurant site, beside science+recommendation, sovereign\n" as *u8) } else { g_p("FAIL T6\n" as *u8) }
120
121 g_p("nx_food_clean_source_gate pass=" as *u8); g_i(pass); g_p("/" as *u8); g_i(tot)
122 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check
123 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled
124 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify.
125 let ctr__dry: *i64 = gv_ctr()
126 ctr__dry[0] = pass
127 ctr__dry[1] = tot
128 let rc__dry: i64 = gv_verdict("FOOD-CLEAN-SOURCE-GATE" as *u8, ctr__dry, "the diner sees cleaner+cheaper sourcing on the same page that picks their dish)" as *u8)
129 sys_exit(rc__dry)
130 return rc__dry
131}