code wiki / _hdl_build / nx_deploy_verify_test.nx
nx_deploy_verify_test.nx source
↩ module page · 49 lines · 4253 B
1// nx_deploy_verify_test.nx -- the team refuses to gamble with the live site. Scenarios:
2// identical : rebuild matches live on all routes + new route ok -> SAFE -> swap
3// regression : one route differs -> REGRESS -> DO NOT swap (caught before it ships)
4// UNVERIFIABLE : source not pinned (the CURRENT reality) -> DO NOT swap -> live protected
5// new-missing : existing routes match but the new route is absent -> REGRESS
6// In every unsafe case the live site is protected. Exit 0 on 7/7. license_tier: ORIGINAL
7
8import "nx_deploy_verify.nx"
9import "nx_syscalls.nx"
10
11func vt_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
12func vt_num(v: i64) -> i64 { let bb: *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 {bb[i]=t[k-1-i]; i=i+1}; sys_write(1, bb, k); return 0 }
13
14func main() -> i64 {
15 vt_puts("=== DEPLOY VERIFIER: prove a rebuild reproduces live before any swap ===\n" as *u8)
16 let n: i64 = 3
17 let live: *i64 = sys_mmap(8*8) as *i64; live[0]=111; live[1]=222; live[2]=333 // content hashes of 3 live routes
18 let same: *i64 = sys_mmap(8*8) as *i64; same[0]=111; same[1]=222; same[2]=333 // a faithful rebuild
19 let diff: *i64 = sys_mmap(8*8) as *i64; diff[0]=111; diff[1]=999; diff[2]=333 // route 1 regressed
20
21 // identical rebuild, source pinned + runs, new route ok -> SAFE
22 let v_safe: i64 = dv_verdict(dv_verifiable(1,1), dv_routes_equivalent(n, live, same), 1)
23 // a route differs -> REGRESS
24 let v_reg: i64 = dv_verdict(dv_verifiable(1,1), dv_routes_equivalent(n, live, diff), 1)
25 let dr: i64 = dv_first_divergent_route(n, live, diff)
26 // source NOT pinned (the real current situation) -> UNVERIFIABLE
27 let v_unv: i64 = dv_verdict(dv_verifiable(0,1), 1, 1)
28 // existing routes match but new route absent -> REGRESS
29 let v_newmiss: i64 = dv_verdict(dv_verifiable(1,1), dv_routes_equivalent(n, live, same), 0)
30
31 vt_puts(" identical -> verdict=" as *u8); vt_num(v_safe); vt_puts(" (1=SAFE) swap=" as *u8); vt_num(dv_safe_to_swap(v_safe)); vt_puts("\n" as *u8)
32 vt_puts(" regression -> verdict=" as *u8); vt_num(v_reg); vt_puts(" (0=REGRESS) at route " as *u8); vt_num(dr); vt_puts(" swap=" as *u8); vt_num(dv_safe_to_swap(v_reg)); vt_puts("\n" as *u8)
33 vt_puts(" UNVERIFIABLE -> verdict=" as *u8); vt_num(v_unv); vt_puts(" (2=UNVERIFIABLE, the CURRENT case: source not pinned) swap=" as *u8); vt_num(dv_safe_to_swap(v_unv)); vt_puts("\n" as *u8)
34 vt_puts(" new-missing -> verdict=" as *u8); vt_num(v_newmiss); vt_puts(" (0=REGRESS) swap=" as *u8); vt_num(dv_safe_to_swap(v_newmiss)); vt_puts("\n" as *u8)
35
36 let r: *i64 = sys_mmap(8*8) as *i64
37 r[0] = 0; if v_safe == DV_SAFE { if dv_safe_to_swap(v_safe) == 1 { r[0] = 1 } } // only swap when proven safe
38 r[1] = 0; if v_reg == DV_REGRESS { if dv_safe_to_swap(v_reg) == 0 { r[1] = 1 } } // regression caught -> no swap
39 r[2] = 0; if dr == 1 { r[2] = 1 } // names the divergent route
40 r[3] = 0; if v_unv == DV_UNVERIFIABLE { if dv_safe_to_swap(v_unv) == 0 { r[3] = 1 } }// unpinned source -> no swap
41 r[4] = 0; if v_newmiss == DV_REGRESS { r[4] = 1 } // missing new route -> fail
42 r[5] = 0; if dv_live_protected(v_unv, 0) == 1 { if dv_live_protected(v_reg, 0) == 1 { r[5] = 1 } } // live protected in unsafe cases
43 r[6] = 0; if dv_live_protected(v_unv, 1) == 0 { r[6] = 1 } // swapping while UNVERIFIABLE would break it (so we don't)
44 var pass: i64 = 0; var i: i64 = 0
45 while i < 7 { pass = pass + r[i]; i = i + 1 }
46 vt_puts("----\n passed " as *u8); vt_num(pass); vt_puts("/7\n" as *u8)
47 if pass == 7 { vt_puts(" RISK ADDRESSED: a swap happens ONLY when the rebuild provably reproduces live + adds the route. The current case (source unpinned) verdicts UNVERIFIABLE -> the team does NOT swap -> the live family site is protected. No corner cut.\n" as *u8); sys_exit(0); return 0 }
48 vt_puts(" FAIL\n" as *u8); sys_exit(1); return 1
49}