code wiki / _hdl_build / nx_consul_suite_test.nx
nx_consul_suite_test.nx source
↩ module page · 81 lines · 5368 B
1// nx_consul_suite_test.nx -- CSUITEGATE: the end-to-end regression-lock for the whole sovereign-Consul arc.
2// Imports ALL 5 organs (registry / kv / dns / health / connect) into ONE binary and runs the real flow:
3// register -> a health probe drives an instance CRITICAL -> discovery reflects it -> service-DNS reflects it
4// -> KV put+CAS -> mesh authorize. Proves they all COMPILE + COMPOSE together (a cross-organ break fails here)
5// AND the end-to-end path is consistent (the surviving discovered instance == the DNS A-record). exit 0 on 7/7.
6import "nx_consul_registry.nx"
7import "nx_consul_kv.nx"
8import "nx_consul_dns.nx"
9import "nx_consul_health.nx"
10import "nx_consul_connect.nx"
11import "nx_syscalls.nx"
12
13func us_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
14func us_num(v: i64) -> i64 { let b: *u8 = sys_mmap(28); var m: i64=v; if m<0 {m=0-m;sys_write(1,"-" as *u8,1)}; let t: *u8 = sys_mmap(28); var k: i64=0; if m==0 {t[0]=48;k=1}; while m>0 {t[k]=48+(m%10); m=m/10; k=k+1}; var i: i64=0; while i<k {b[i]=t[k-1-i]; i=i+1}; sys_write(1,b,k); return 0 }
15
16func main() -> i64 {
17 us_puts("=== SOVEREIGN CONSUL SUITE (register->health->discover->dns->kv->mesh, ONE binary) ===\n" as *u8)
18 let WEB: i64 = 100
19 let DB: i64 = 200
20
21 // 1) REGISTER: web has 2 instances (addr 10, 12); db has 1 (addr 20). all PASSING.
22 let reg: *i64 = sys_mmap(24) as *i64; reg[0]=1; reg[1]=1; reg[2]=1
23 let names: *i64 = sys_mmap(24) as *i64; names[0]=WEB; names[1]=WEB; names[2]=DB
24 let addrs: *i64 = sys_mmap(24) as *i64; addrs[0]=10; addrs[1]=12; addrs[2]=20
25 let health:*i64 = sys_mmap(24) as *i64; health[0]=SVC_PASSING; health[1]=SVC_PASSING; health[2]=SVC_PASSING
26 let cf: *i64 = sys_mmap(24) as *i64; cf[0]=0; cf[1]=0; cf[2]=0
27 let cp: *i64 = sys_mmap(24) as *i64; cp[0]=0; cp[1]=0; cp[2]=0
28 let out: *i64 = sys_mmap(64) as *i64
29 let d_initial: i64 = cs_discover(reg, names, health, 3, WEB, out) // 2
30
31 // 2) HEALTH: 3 failed probes drive web instance idx1 (addr12) CRITICAL (fail_thr=3)
32 hc_tick(health, cf, cp, 1, 0, 3, 2)
33 hc_tick(health, cf, cp, 1, 0, 3, 2)
34 hc_tick(health, cf, cp, 1, 0, 3, 2)
35
36 // 3) DISCOVER reflects health: web -> 1 (only addr10)
37 let d_after: i64 = cs_discover(reg, names, health, 3, WEB, out) // 1
38 let disc_addr: i64 = addrs[out[0]] // 10
39
40 // 4) SERVICE-DNS reflects health: web -> A-records {10}
41 let da: *i64 = sys_mmap(64) as *i64
42 let dns_n: i64 = csd_resolve(reg, names, addrs, health, 3, WEB, da) // 1, da[0]=10
43
44 // 5) KV: put a config value + CAS update it
45 let keys: *i64 = sys_mmap(64) as *i64
46 let vals: *i64 = sys_mmap(64) as *i64
47 let vers: *i64 = sys_mmap(64) as *i64
48 let pres: *i64 = sys_mmap(64) as *i64
49 var z: i64 = 0; while z < 8 { pres[z]=0; z=z+1 }
50 let kv_v1: i64 = ckv_put(keys, vals, vers, pres, 8, 555, 111) // version 1
51 let kv_cas: i64 = ckv_cas(keys, vals, vers, pres, 8, 555, 222, 1) // CAS on v1 -> applies
52
53 // 6) CONNECT: web->db authorize (intention allow + valid CA cert), and imposter rejected
54 let srcs: *i64 = sys_mmap(8) as *i64; srcs[0]=WEB
55 let dsts: *i64 = sys_mmap(8) as *i64; dsts[0]=DB
56 let acts: *i64 = sys_mmap(8) as *i64; acts[0]=INTENT_ALLOW
57 let mesh: i64 = mc_authorize(WEB, 1, WEB, DB, srcs, dsts, acts, 1) // ALLOW
58 let mesh_imp: i64 = mc_authorize(WEB, 0, WEB, DB, srcs, dsts, acts, 1) // DENY (unsigned)
59
60 us_puts(" register web=" as *u8); us_num(d_initial); us_puts(" -> after-health=" as *u8); us_num(d_after)
61 us_puts(" disc_addr=" as *u8); us_num(disc_addr); us_puts(" dns=" as *u8); us_num(dns_n); us_puts(" dns_addr=" as *u8); us_num(da[0])
62 us_puts(" | kv_v=" as *u8); us_num(kv_v1); us_puts(" cas=" as *u8); us_num(kv_cas); us_puts(" mesh=" as *u8); us_num(mesh); us_puts(" imp=" as *u8); us_num(mesh_imp); us_puts("\n" as *u8)
63
64 let r: *i64 = sys_mmap(8*8) as *i64
65 r[0] = 0; if d_initial == 2 { r[0] = 1 } // registry: 2 web instances
66 r[1] = 0; if d_after == 1 { r[1] = 1 } // health closes loop into discovery
67 r[2] = 0; if dns_n == 1 { if da[0] == 10 { r[2] = 1 } } // service-DNS healthy-only
68 r[3] = 0; if kv_v1 == 1 { if kv_cas == 1 { r[3] = 1 } } // KV + CAS
69 r[4] = 0; if mesh == MESH_ALLOW { r[4] = 1 } // mesh authorize (cert + intention)
70 r[5] = 0; if mesh_imp == MESH_DENY { r[5] = 1 } // mesh rejects imposter
71 r[6] = 0; if disc_addr == da[0] { if disc_addr == 10 { r[6] = 1 } } // end-to-end consistency: discovery == DNS
72
73 var pass: i64 = 0; var i: i64 = 0
74 while i < 7 { pass = pass + r[i]; i = i + 1 }
75 us_puts("----\n passed " as *u8); us_num(pass); us_puts("/7\n" as *u8)
76 if pass == 7 {
77 us_puts("CSUITEGATE organs=5 all_compose_in_one_binary=1 end_to_end_consistent=1 exceed[whole sovereign-Consul arc regression-locked: registry+discovery+kv+service-DNS+live-health+mesh-mTLS compose into one coherent flow; a cross-organ break fails HERE; bits-up] verdict=GREEN\n" as *u8)
78 sys_exit(0); return 0
79 }
80 us_puts("CSUITEGATE verdict=RED\n" as *u8); sys_exit(1); return 1
81}