code wiki / _hdl_build / nx_food_clean_source_gate.nx
nx_food_clean_source_gate.nx source
↩ module page · 124 lines · 7881 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"
11
12const FCS_CAT: *u8 = "knowledge/registry/nishi_builder.tsv"
13const FCS_STORE: *u8 = "knowledge/store/food-"
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_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 }
25
26func main() -> i64 {
27 g_p("=== nx_food_clean_source_gate (R-IMPACT-3: clean-sourcing badge on the stir-fry site) ===\n" as *u8)
28 fd_seed(FCS_STORE)
29 fd_seed_restaurants(FCS_STORE)
30 let sw: i64 = fc_seed_veg(FCS_STORE)
31 g_p("veg impact records authored this run=" as *u8); g_i(sw); g_p("\n" as *u8)
32 fs_teach(FCS_CAT)
33
34 let h: *i64 = fd_world_open(FCS_STORE)
35
36 var pass: i64 = 0
37 var tot: i64 = 0
38
39 // T1 the stir-fry vegetables are now catalog-covered (durable readback, not first-write)
40 tot = tot + 1
41 var ok1: i64 = 1
42 if fc_covered(FCS_STORE, "broccoli" as *u8) != 1 { ok1 = 0 }
43 if fc_covered(FCS_STORE, "onion" as *u8) != 1 { ok1 = 0 }
44 if fc_covered(FCS_STORE, "snowpea" as *u8) != 1 { ok1 = 0 }
45 if fc_covered(FCS_STORE, "bokchoy" as *u8) != 1 { ok1 = 0 }
46 if fc_covered(FCS_STORE, "garlic" as *u8) != 1 { ok1 = 0 }
47 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) }
48
49 // T2 HONEST: ingredients NOT in the catalog are not claimed covered (no overclaim)
50 tot = tot + 1
51 var ok2: i64 = 1
52 if fc_covered(FCS_STORE, "beef" as *u8) != 0 { ok2 = 0 }
53 if fc_covered(FCS_STORE, "soy" as *u8) != 0 { ok2 = 0 }
54 if fc_covered(FCS_STORE, "chili" as *u8) != 0 { ok2 = 0 }
55 if fc_covered(FCS_STORE, "unicorn" as *u8) != 0 { ok2 = 0 }
56 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) }
57
58 // T3 every seeded veg is a genuine triple win (so the clean badge can't greenwash)
59 let slugs: *i64 = sys_mmap(8 * 16) as *i64
60 var ns: i64 = 0
61 slugs[ns] = "broccoli" as *u8 as i64; ns = ns + 1
62 slugs[ns] = "onion" as *u8 as i64; ns = ns + 1
63 slugs[ns] = "carrot" as *u8 as i64; ns = ns + 1
64 slugs[ns] = "snowpea" as *u8 as i64; ns = ns + 1
65 slugs[ns] = "mushroom" as *u8 as i64; ns = ns + 1
66 slugs[ns] = "bokchoy" as *u8 as i64; ns = ns + 1
67 slugs[ns] = "beansprout" as *u8 as i64; ns = ns + 1
68 slugs[ns] = "garlic" as *u8 as i64; ns = ns + 1
69 slugs[ns] = "ginger" as *u8 as i64; ns = ns + 1
70 var wins: i64 = 0
71 var si: i64 = 0
72 while si < ns { if im_triple_win(FCS_STORE, slugs[si] as *u8) == 1 { wins = wins + 1 } si = si + 1 }
73 g_p("triple-win veg=" as *u8); g_i(wins); g_p("/" as *u8); g_i(ns); g_p("\n" as *u8)
74 tot = tot + 1
75 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) }
76
77 // T4 per-build savings aggregate over covered veg only. Construct a build: broccoli + snow peas.
78 let build: *i64 = sys_mmap(8 * 8) as *i64
79 let roles: *i64 = sys_mmap(8 * 8) as *i64
80 build[0] = fd_index_of(h, "broccoli" as *u8); roles[0] = FROLE_VEG
81 build[1] = fd_index_of(h, "snowpea" as *u8); roles[1] = FROLE_VEG
82 let cov: i64 = fc_build_covered(FCS_STORE, h, build, roles, 2)
83 let sav: i64 = fc_build_savings(FCS_STORE, h, build, roles, 2)
84 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)
85 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)
86 tot = tot + 1
87 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) }
88
89 // T5 the badge renders with measured clean scores + savings + disclaimer, sovereign (no third-party JS)
90 let frag: *u8 = sys_mmap(16384)
91 let nf: i64 = fc_render_badge(FCS_STORE, h, build, roles, 2, frag, 0)
92 frag[nf] = 0 as u8
93 tot = tot + 1
94 var ok5: i64 = 1
95 if as_contains(frag, nf, "Clean sourcing" as *u8) != 1 { ok5 = 0 }
96 if as_contains(frag, nf, "Broccoli" as *u8) != 1 { ok5 = 0 }
97 if as_contains(frag, nf, "Snow Peas" as *u8) != 1 { ok5 = 0 }
98 if as_contains(frag, nf, "save $" as *u8) != 1 { ok5 = 0 }
99 if as_contains(frag, nf, "regenerative-agriculture corpus" as *u8) != 1 { ok5 = 0 }
100 if as_has_thirdparty_js(frag, nf) != 0 { ok5 = 0 }
101 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) }
102
103 // T6 END-TO-END: the badge appears on the REAL rendered restaurant site, with no regression.
104 let page: *u8 = sys_mmap(65536)
105 let np: i64 = fs_render_restaurant(FCS_STORE, FCS_CAT, "greenwok" as *u8, page)
106 g_p("rendered greenwok site = " as *u8); g_i(np); g_p(" bytes\n" as *u8)
107 tot = tot + 1
108 var ok6: i64 = 1
109 if np <= 0 { ok6 = 0 }
110 if as_contains(page, np, "Clean sourcing" as *u8) != 1 { ok6 = 0 } // the new badge is wired in
111 if as_contains(page, np, "save $" as *u8) != 1 { ok6 = 0 } // populated (>=1 covered veg)
112 if as_contains(page, np, "class='sci'" as *u8) != 1 { ok6 = 0 } // science section still present
113 if as_contains(page, np, "class='rec'" as *u8) != 1 { ok6 = 0 } // recommendation still present
114 if as_has_thirdparty_js(page, np) != 0 { ok6 = 0 } // still sovereign
115 sys_mkdir("knowledge/staging" as *u8, 0x1ed)
116 sys_mkdir("knowledge/staging/food" as *u8, 0x1ed)
117 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) }
118 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) }
119
120 g_p("nx_food_clean_source_gate pass=" as *u8); g_i(pass); g_p("/" as *u8); g_i(tot)
121 if pass == tot { g_p(" verdict=GREEN (the diner sees cleaner+cheaper sourcing on the same page that picks their dish)\n" as *u8); return 0 }
122 g_p(" verdict=RED\n" as *u8)
123 return 1
124}