code wiki / _hdl_build / nx_brand_builder_gate.nx
nx_brand_builder_gate.nx source
↩ module page · 88 lines · 4252 B
1import "nx_gate_gn.nx"
2import "nx_gate_base.nx"
3// nx_brand_builder_gate.nx -- R1b proof: the BUILDER (nx_web_builder) is now token-driven. Builds real pages to
4// /tmp, reads them back, and asserts (T1) the page DECLARES the design tokens (:root{--nx-*}) AND USES them
5// (var(--nx-*)); (T2) a branded build with a RED .brand swaps the primary to #ff0000 with NO code change (the
6// re-theme-from-DATA property at the builder level); (T3) the branded build still references tokens via var().
7// Complements nx_sitegen_gate (structure + zero-regression) with the positive "tokens actually drive the CSS"
8// claim. 100% sovereign (nx_cc->nxasm, no gcc/JS). license_tier: ORIGINAL expect_exit: 0
9import "nx_syscalls.nx"
10import "nx_web_builder.nx"
11import "nx_brand_tokens.nx"
12
13func grow(name: *u8, ok: i64) -> i64 { if ok==1 { gw(" PASS " as *u8) } else { gw(" FAIL " as *u8) } gw(name); gw("
14" as *u8); return ok }
15func g_has(s: *u8, n: i64, lit: *u8) -> i64 { if bt_find(s, n, lit, bt_len(lit)) >= 0 { return 1 } return 0 }
16func t_row(name: *u8, ok: i64, tot: *i64) -> i64 {
17 if ok == 1 { gw(" PASS " as *u8); tot[0]=tot[0]+1 } else { gw(" FAIL " as *u8); tot[1]=tot[1]+1 }
18 gw(name); gw("\n" as *u8); return 0
19}
20
21func build_default(path: *u8) -> i64 {
22 let fd: i64 = sys_openat_wr(path, 0x1a4)
23 if fd < 0 { return 0 - 1 }
24 wb_doc_open(fd, "R1b Test" as *u8)
25 wb_w(fd, "<p>body</p>\n" as *u8)
26 wb_doc_close(fd)
27 sys_close(fd)
28 return 0
29}
30func build_branded(path: *u8, brand: *u8) -> i64 {
31 let fd: i64 = sys_openat_wr(path, 0x1a4)
32 if fd < 0 { return 0 - 1 }
33 wb_doc_open_branded(fd, "R1b Brand" as *u8, brand, bt_len(brand))
34 wb_w(fd, "<p>body</p>\n" as *u8)
35 wb_doc_close(fd)
36 sys_close(fd)
37 return 0
38}
39
40func main() -> i64 {
41 let tot: *i64 = sys_mmap(32) as *i64
42 tot[0]=0; tot[1]=0
43 let lenp: *i64 = sys_mmap(16) as *i64
44 gw("=== nx_brand_builder_gate -- R1b: the builder is token-driven (proof on real built pages) ===\n" as *u8)
45
46 // T1: default page DECLARES tokens and USES them
47 build_default("/tmp/nx_r1b_def.html" as *u8)
48 let a: *u8 = sys_read_file("/tmp/nx_r1b_def.html" as *u8, lenp)
49 let an: i64 = lenp[0]
50 var t1: i64 = 0
51 if an > 0 {
52 if g_has(a, an, ":root{" as *u8) == 1 {
53 if g_has(a, an, "--nx-color-primary: #0b2545" as *u8) == 1 {
54 if g_has(a, an, "var(--nx-color-primary)" as *u8) == 1 {
55 if g_has(a, an, "</style>" as *u8) == 1 { t1 = 1 }
56 }
57 }
58 }
59 }
60 t_row("T1 built page DECLARES tokens (:root --nx-*) AND USES them (var(--nx-*))" as *u8, t1, tot)
61
62 // T2: re-theme from DATA -- a RED brand swaps primary to #ff0000, no code change
63 let red: *u8 = "token|color|primary|#ff0000\ntoken|color|accent|#e8a534\ntoken|color|accent-ink|#0b2545\ntoken|color|hero|#13315c\ntoken|color|ink|#16202e\ntoken|color|bg|#ffffff\ntoken|color|muted|#eef3f8\ntoken|color|line|#cdd7e3\ntoken|font|sans|system-ui\ntoken|font|size-base|16px\ntoken|font|leading|1.6\ntoken|radius|md|8px\ntoken|radius|sm|6px\n" as *u8
64 build_branded("/tmp/nx_r1b_red.html" as *u8, red)
65 let b: *u8 = sys_read_file("/tmp/nx_r1b_red.html" as *u8, lenp)
66 let bn: i64 = lenp[0]
67 var t2: i64 = 0
68 if bn > 0 {
69 if g_has(b, bn, "--nx-color-primary: #ff0000" as *u8) == 1 {
70 if g_has(b, bn, "--nx-color-primary: #0b2545" as *u8) == 0 { t2 = 1 }
71 }
72 }
73 t_row("T2 re-theme: branded build swaps primary to #ff0000 (DATA edit, no code change)" as *u8, t2, tot)
74
75 // T3: the branded build still references tokens via var(--nx-*) (consistent theming, not stale literals)
76 var t3: i64 = 0
77 if bn > 0 {
78 if g_has(b, bn, "var(--nx-color-primary)" as *u8) == 1 {
79 if g_has(b, bn, "var(--nx-color-accent)" as *u8) == 1 { t3 = 1 }
80 }
81 }
82 t_row("T3 branded build references tokens via var(--nx-*) (theming is live, not baked)" as *u8, t3, tot)
83
84 gw("\nrows pass=" as *u8); gn(tot[0]); gw(" fail=" as *u8); gn(tot[1]); gw("\n" as *u8)
85 if tot[1] == 0 { gw("VERDICT=GREEN -- nx_web_builder is token-driven; sites re-brand by swapping .brand DATA\n" as *u8); return 0 }
86 gw("VERDICT=RED\n" as *u8)
87 return 1
88}