code wiki / _hdl_build / nx_produce_gate.nx
nx_produce_gate.nx source
↩ module page · 110 lines · 5878 B
1// nx_produce_gate.nx -- GATE: R-IMPACT-2. The clean-produce catalog at product-line scale. T1 catalog (Dirty
2// Dozen subset), T2 EVERY item triple-wins, T3 basket customer savings, T4 we earn more on the basket (vertical
3// integration), T5 clean gap (Nishi clean >=90, conventional <=35 across the board), T6 sovereign storefront
4// shipped. license_tier: ORIGINAL
5import "nx_produce.nx"
6import "nx_impact.nx"
7import "nx_food_science.nx"
8import "nx_publisher.nx"
9import "nx_seg_store.nx"
10import "nx_syscalls.nx"
11import "nx_gate_verdict.nx"
12
13const QG_FOOD: *u8 = "knowledge/store/food-"
14const QG_Q: *u8 = "knowledge/publish/produce-queue.tsv"
15const QG_LED: *u8 = "knowledge/publish/produce-ledger.tsv"
16const QG_STG: *u8 = "knowledge/publish/produce-stage"
17const QG_LIVE: *u8 = "knowledge/publish/produce-live"
18const QG_STAGE_FILE: *u8 = "knowledge/staging/produce/clean-produce.html"
19const QG_LIVE_FILE: *u8 = "knowledge/publish/produce-live/clean-produce.html"
20
21func 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 }
22func g_i(v: i64) -> i64 {
23 let bb: *u8 = sys_mmap(28); var m: i64 = v
24 if m < 0 { sys_write(1, "-" as *u8, 1); m = 0 - m }
25 let t: *u8 = sys_mmap(28); var k: i64 = 0
26 if m == 0 { t[0] = 48 as u8; k = 1 }
27 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 }
28 var i: i64 = 0; while i < k { bb[i] = t[k - 1 - i]; i = i + 1 } sys_write(1, bb, k); return 0
29}
30func 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 }
31func g_exists(path: *u8) -> i64 { let fd: i64 = sys_openat_rd(path); if fd < 0 { return 0 } sys_close(fd); return 1 }
32
33func main() -> i64 {
34 g_p("=== nx_produce_gate (R-IMPACT-2: the clean-produce catalog) ===\n" as *u8)
35 fd_seed(QG_FOOD)
36 let sw: i64 = pd_seed(QG_FOOD)
37 g_p("produce records authored this run=" as *u8); g_i(sw); g_p("\n" as *u8)
38
39 let ids: *i64 = sys_mmap(8 * 64) as *i64
40 let n: i64 = pd_list(QG_FOOD, ids)
41
42 var pass: i64 = 0
43 var tot: i64 = 0
44
45 // T1 catalog size
46 tot = tot + 1
47 if n == 8 { pass = pass + 1; g_p("PASS T1 catalog: 8 Dirty-Dozen items\n" as *u8) } else { g_p("FAIL T1 n=" as *u8); g_i(n); g_p("\n" as *u8) }
48
49 // T2 every item triple-wins
50 let totp: *i64 = sys_mmap(16) as *i64
51 let wins: i64 = pd_all_triple_win(QG_FOOD, totp)
52 g_p("triple-win items=" as *u8); g_i(wins); g_p("/" as *u8); g_i(totp[0]); g_p("\n" as *u8)
53 tot = tot + 1
54 if wins == totp[0] { if totp[0] == 8 { pass = pass + 1; g_p("PASS T2 EVERY item is cleaner+greener+cheaper AND higher-margin (8/8 triple win)\n" as *u8) } else { g_p("FAIL T2 count\n" as *u8) } } else { g_p("FAIL T2 wins\n" as *u8) }
55
56 // T3 basket customer savings
57 let bsave: i64 = pd_basket_savings(QG_FOOD)
58 g_p("basket: customer saves " as *u8); g_money(bsave); g_p("\n" as *u8)
59 tot = tot + 1
60 if bsave == 800 { pass = pass + 1; g_p("PASS T3 whole-basket savings $8.00 vs the supermarket\n" as *u8) } else { g_p("FAIL T3 bsave=" as *u8); g_i(bsave); g_p("\n" as *u8) }
61
62 // T4 we earn MORE on the basket
63 let mn: i64 = pd_basket_margin(QG_FOOD, "nishi" as *u8)
64 let mc: i64 = pd_basket_margin(QG_FOOD, "conv" as *u8)
65 g_p("basket margin: nishi=" as *u8); g_money(mn); g_p(" conv=" as *u8); g_money(mc); g_p("\n" as *u8)
66 tot = tot + 1
67 if mn > mc { if bsave > 0 { pass = pass + 1; g_p("PASS T4 we earn MORE on the basket (" as *u8); g_money(mn); g_p(" > " as *u8); g_money(mc); g_p(") while the customer pays less\n" as *u8) } else { g_p("FAIL T4 savings\n" as *u8) } } else { g_p("FAIL T4 margin\n" as *u8) }
68
69 // T5 clean gap across the board
70 tot = tot + 1
71 var ok5: i64 = 1
72 var i: i64 = 0
73 while i < n {
74 if im_clean(QG_FOOD, ids[i] as *u8, "nishi" as *u8) < 90 { ok5 = 0 }
75 if im_clean(QG_FOOD, ids[i] as *u8, "conv" as *u8) > 35 { ok5 = 0 }
76 i = i + 1
77 }
78 if ok5 == 1 { pass = pass + 1; g_p("PASS T5 clean gap: every Nishi item >=90 clean, every conventional <=35\n" as *u8) } else { g_p("FAIL T5\n" as *u8) }
79
80 // T6 sovereign storefront + ship
81 let page: *u8 = sys_mmap(65536)
82 let np: i64 = pd_render_storefront(QG_FOOD, page)
83 tot = tot + 1
84 var ok6: i64 = 1
85 if as_has_thirdparty_js(page, np) != 0 { ok6 = 0 }
86 if as_contains(page, np, "strawberries" as *u8) != 1 { ok6 = 0 }
87 if as_contains(page, np, "blueberries" as *u8) != 1 { ok6 = 0 }
88 if as_contains(page, np, "$8.00" as *u8) != 1 { ok6 = 0 }
89 sys_mkdir("knowledge/staging" as *u8, 0x1ed)
90 sys_mkdir("knowledge/staging/produce" as *u8, 0x1ed)
91 let sfd: i64 = sys_openat_wr(QG_STAGE_FILE, 420); if sfd >= 0 { sys_write(sfd, page, np); sys_close(sfd) }
92 pub_init()
93 sys_mkdir(QG_STG, 0x1ed)
94 sys_mkdir(QG_LIVE, 0x1ed)
95 pub_submit_to(QG_Q, QG_STAGE_FILE, "clean-produce.html" as *u8, "nishifoodfamily" as *u8, "nishi-produce" as *u8, "internal" as *u8)
96 pub_run_full(QG_Q, QG_LED, QG_STG, QG_LIVE, "publish:produce" as *u8)
97 if g_exists(QG_LIVE_FILE) != 1 { ok6 = 0 }
98 if ok6 == 1 { pass = pass + 1; g_p("PASS T6 sovereign clean-produce storefront shipped (" as *u8); g_i(np); g_p(" bytes)\n" as *u8) } else { g_p("FAIL T6\n" as *u8) }
99
100 g_p("nx_produce_gate pass=" as *u8); g_i(pass); g_p("/" as *u8); g_i(tot)
101 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check
102 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled
103 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify.
104 let ctr__dry: *i64 = gv_ctr()
105 ctr__dry[0] = pass
106 ctr__dry[1] = tot
107 let rc__dry: i64 = gv_verdict("PRODUCE-GATE" as *u8, ctr__dry, "clean-produce line: the triple win at basket scale, shipped)" as *u8)
108 sys_exit(rc__dry)
109 return rc__dry
110}