code wiki / _hdl_build / nx_brick_compose_gate.nx

nx_brick_compose_gate.nx source

↩ module page · 91 lines · 4473 B

1// nx_brick_compose_gate.nx -- referee for R-BRICKS-COMPOSE (sa_brick_n + the SA_GRIDN hook): consumed part: 2// bricks drive grid richness in corpus-driven composition. Wrapper pre-authored fixtures + ran nx_tpl_parts.elf: 3// /tmp/brickstore/ <- a gallery brick with 4 headings (from a 4-item template) 4// /tmp/brickstore2/ <- a gallery brick with 9 headings (clamp case) 5// Proves: median derivation, brick-driven card count in the composed page, default fallback with no store, 6// clamp at 6, and no-bricks-of-kind -> 0 (fixed sections unaffected). GREEN iff 5/5. 7// license_tier: ORIGINAL expect_exit: 0 8import "nx_gate.nx" 9import "nx_site_archetype.nx" 10import "nx_gate_verdict.nx" 11 12func bg_count(hay: *u8, hn: i64, needle: *u8) -> i64 { 13 if (hay as i64)==0 { return 0 } 14 var nl: i64=0; while needle[nl]!=(0 as u8){nl=nl+1} 15 if nl==0 { return 0 } 16 var c: i64=0 17 var i: i64=0 18 while i+nl<=hn { var j: i64=0; var ok: i64=1; while j<nl { if (hay[i+j] as i64)!=(needle[j] as i64) { ok=0; j=nl } else { j=j+1 } } if ok==1 { c=c+1; i=i+nl } else { i=i+1 } } 19 return c 20} 21func bg_row(name: *u8, ok: i64) -> i64 { gw(" " as *u8); gw(name); if ok==1 { gw(" PASS\n" as *u8) } else { gw(" FAIL\n" as *u8) } return 0 } 22 23func main() -> i64 { 24 let buf: *u8 = sys_mmap(262144) 25 // T1: median heads of the 4-heading gallery brick 26 let h1: *i64 = ss_open("/tmp/brickstore/" as *u8) 27 var t1: i64=0 28 if (h1 as i64)!=0 { 29 SA_STOREH = h1 as i64 30 if sa_brick_n("gal" as *u8) == 4 { t1=1 } 31 } 32 // T2: the composed seq page's gallery grid has EXACTLY 4 cards (brick-driven) 33 var t2: i64=0 34 if (h1 as i64)!=0 { 35 SA_STOREH = h1 as i64 36 let o: i64 = sa_recipe_seq(1, "gal" as *u8, 0, "Nishi" as *u8, "brick test" as *u8, buf) 37 if bg_count(buf, o, "<article class=\"card\"" as *u8) == 4 { t2=1 } 38 } 39 // T3: default fallback -- no store -> 6 cards 40 SA_STOREH = 0 41 let o3: i64 = sa_recipe_seq(1, "gal" as *u8, 0, "Nishi" as *u8, "brick test" as *u8, buf) 42 var t3: i64=0 43 if bg_count(buf, o3, "<article class=\"card\"" as *u8) == 6 { if sa_brick_n("gal" as *u8) == 0 { t3=1 } } 44 // T4: clamp -- the 9-heading brick clamps to 6 45 let h2: *i64 = ss_open("/tmp/brickstore2/" as *u8) 46 var t4: i64=0 47 if (h2 as i64)!=0 { 48 SA_STOREH = h2 as i64 49 if sa_brick_n("gal" as *u8) == 6 { t4=1 } 50 } 51 // T5 (NEG): no bricks of a kind -> 0, and fixed sections stay fixed (faq emits exactly 3 cards) 52 var t5: i64=0 53 if (h1 as i64)!=0 { 54 SA_STOREH = h1 as i64 55 if sa_brick_n("faq" as *u8) == 0 { 56 let o5: i64 = sa_recipe_seq(1, "faq" as *u8, 0, "Nishi" as *u8, "brick test" as *u8, buf) 57 if bg_count(buf, o5, "<article class=\"card\"" as *u8) == 3 { t5=1 } 58 } 59 } 60 SA_STOREH = 0 61 62 var passes: i64=0 63 if t1==1 { passes=passes+1 } if t2==1 { passes=passes+1 } if t3==1 { passes=passes+1 } 64 if t4==1 { passes=passes+1 } if t5==1 { passes=passes+1 } 65 var green: i64=0; if passes==5 { green=1 } 66 67 gw("=== nx_brick_compose_gate -- R-BRICKS consumed bricks drive section richness ===\n" as *u8) 68 bg_row("T1-brick-median-derived " as *u8, t1) 69 bg_row("T2-grid-count-brick-driven " as *u8, t2) 70 bg_row("T3-default-6-without-store " as *u8, t3) 71 bg_row("T4-clamped-at-6 " as *u8, t4) 72 bg_row("T5-no-kind-bricks-fixed-3(neg) " as *u8, t5) 73 gw("verdict=" as *u8); if green==1 { gw("GREEN" as *u8) } else { gw("RED" as *u8) } 74 gw(" passes=" as *u8); gn(passes); gw("/5\n" as *u8) 75 76 let lg: i64 = sys_openat_append("knowledge/status/brick_compose.log" as *u8, 0x1a4) 77 if lg >= 0 { 78 if green==1 { let m: *u8 = "BRICK-COMPOSE rows=5 pass=5 verdict=GREEN\n" as *u8; sys_write(lg, m, 42) } 79 else { let m2: *u8 = "BRICK-COMPOSE verdict=RED\n" as *u8; sys_write(lg, m2, 26) } 80 sys_close(lg) 81 } 82 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check 83 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled 84 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify. 85 let ctr__dry: *i64 = gv_ctr() 86 ctr__dry[0] = green 87 ctr__dry[1] = 1 88 let rc__dry: i64 = gv_verdict("BRICK-COMPOSE-GATE" as *u8, ctr__dry, "teeth unchanged; verdict emission migrated onto the shared base class" as *u8) 89 sys_exit(rc__dry) 90 return rc__dry 91}