code wiki / _hdl_build / nx_domain_forge_gate.nx

nx_domain_forge_gate.nx source

↩ module page · 80 lines · 4893 B

1// nx_domain_forge_gate.nx -- SOVEREIGN gate for the append-driven domain auto-builder. Writes a 2-domain 2// registry, forges, and asserts each site was COMPOSED from Lego pieces (the hub blocks) into its docroot + 3// the vhost + cert-registry rows were emitted. Then APPENDS a 3rd domain + re-forges -> it appears (the 4// "append a domain and the builders emit it" property) AND the rewrite is IDEMPOTENT (3, not 6). GREEN iff T1..T8. 5// Sovereign: nx_domain_forge + nx_syscalls. license_tier: ORIGINAL 6import "nx_domain_forge.nx" 7import "nx_syscalls.nx" 8 9func g_w(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 10func g_len(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } 11func g_row(name: *u8, ok: i64) -> i64 { 12 if ok == 1 { g_w(" PASS " as *u8) } else { g_w(" FAIL " as *u8) } 13 g_w(name); g_w("\n" as *u8) 14 return ok 15} 16func g_trunc(path: *u8) -> i64 { let fd: i64 = sys_openat_wr(path, 0x180); if fd >= 0 { sys_close(fd) } return 0 } 17func g_writef(path: *u8, s: *u8) -> i64 { let fd: i64 = sys_openat_wr(path, 0x180); if fd < 0 { return 0-1 } sys_write(fd, s, g_len(s)); sys_close(fd); return 0 } 18func g_appendf(path: *u8, s: *u8) -> i64 { let fd: i64 = sys_openat_append(path, 0x1a4); if fd < 0 { return 0-1 } sys_write(fd, s, g_len(s)); sys_close(fd); return 0 } 19func g_has(path: *u8, needle: *u8) -> i64 { 20 let szb: *i64 = sys_mmap(16) as *i64; szb[0]=0 21 let buf: *u8 = sys_read_file(path, szb) 22 if (buf as i64)==0 { return 0 } 23 let n: i64 = szb[0]; let nn: i64 = g_len(needle) 24 var i: i64 = 0 25 while i + nn <= n { 26 var m: i64=1; var j: i64=0 27 while j<nn { if (buf[i+j] as i64)!=(needle[j] as i64){m=0;j=nn} else {j=j+1} } 28 if m==1 { return 1 } 29 i=i+1 30 } 31 return 0 32} 33 34func main() -> i64 { 35 g_w("domain-forge gate (APPEND a domain -> the builders auto-emit it from Lego pieces; idempotent SSOT)\n" as *u8) 36 let reg: *u8 = "/tmp/df_domains.conf" as *u8 37 let sc: *u8 = "/tmp/df_sites.conf" as *u8 38 let cr: *u8 = "/tmp/df_certs.conf" as *u8 39 let bidx: *u8 = "/tmp/df_brad/index.html" as *u8 40 let jidx: *u8 = "/tmp/df_jensen/index.html" as *u8 41 g_trunc(bidx); g_trunc(jidx) 42 g_writef(reg, "# domain registry SSOT -- append a row to add a site\nbradrwest.com /tmp/df_brad web_assets/_hubs/bradrwest.hub\njensendwest.com /tmp/df_jensen web_assets/_hubs/jensendwest.hub\n" as *u8) 43 44 let r1: i64 = df_forge(reg, sc, cr) 45 var pass: i64 = 0 46 47 pass = pass + g_row("T1 forge emitted 2 domains from the registry\x00" as *u8, (r1 == 2) as i64) 48 pass = pass + g_row("T2 bradrwest docroot COMPOSED from hub pieces (<h1>Brad West</h1>)\x00" as *u8, g_has(bidx, "<h1>Brad West</h1>" as *u8)) 49 pass = pass + g_row("T3 jensendwest docroot COMPOSED from hub pieces (<h1>Jensen West</h1>)\x00" as *u8, g_has(jidx, "<h1>Jensen West</h1>" as *u8)) 50 51 var t4: i64 = 0 52 if g_has(sc, "bradrwest.com\t/tmp/df_brad/index.html" as *u8) == 1 { if g_has(sc, "jensendwest.com\t/tmp/df_jensen/index.html" as *u8) == 1 { t4 = 1 } } 53 pass = pass + g_row("T4 vhost rows emitted (host TAB docroot) for both domains\x00" as *u8, t4) 54 55 var t5: i64 = 0 56 if g_has(cr, "bradrwest.com\tcerts/le_bradrwest.com_fullchain.der" as *u8) == 1 { if g_has(cr, "jensendwest.com\tcerts/le_jensendwest.com_fullchain.der" as *u8) == 1 { t5 = 1 } } 57 pass = pass + g_row("T5 per-domain CERT-REGISTRY rows emitted (host -> wildcard chain/key)\x00" as *u8, t5) 58 59 // ★ T6: APPEND a 3rd domain to the registry + re-forge -> it appears (the operator's exact property) 60 g_appendf(reg, "calebwest.com /tmp/df_caleb web_assets/_hubs/bradrwest.hub\n" as *u8) 61 let r2: i64 = df_forge(reg, sc, cr) 62 pass = pass + g_row("T6 APPENDED calebwest.com -> re-forge emits 3 (append a row -> auto-built)\x00" as *u8, (r2 == 3) as i64) 63 pass = pass + g_row("T7 the appended domain's vhost+cert rows are present\x00" as *u8, g_has(cr, "calebwest.com\tcerts/le_calebwest.com_fullchain.der" as *u8)) 64 65 // T8: IDEMPOTENT -- re-forge the SAME registry -> still 3 (truncate+rewrite from SSOT, not 6/accumulating) 66 let r3: i64 = df_forge(reg, sc, cr) 67 var t8: i64 = 0 68 if r3 == 3 { if g_has(sc, "calebwest.com\t/tmp/df_caleb/index.html" as *u8) == 1 { t8 = 1 } } 69 pass = pass + g_row("T8 idempotent re-forge -> still 3 (registry is the SSOT, no accumulation)\x00" as *u8, t8) 70 71 if pass == 8 { 72 let lg: i64 = sys_openat_append("knowledge/status/domain_forge_gate.log" as *u8, 0x1a4) 73 if lg >= 0 { sys_write(lg, "DOMAIN-FORGE-GATE pass=8/8 verdict=GREEN\n" as *u8, 39); sys_close(lg) } 74 g_w("DOMAIN-FORGE GATE GREEN 8/8 (append a domain row -> site auto-composed from pieces + vhost + cert; idempotent)\n" as *u8) 75 sys_exit(0) 76 } 77 g_w("DOMAIN-FORGE GATE RED\n" as *u8) 78 sys_exit(1) 79 return 1 80}