code wiki / _hdl_build / nx_pub_nobypass_gate.nx
nx_pub_nobypass_gate.nx source
↩ module page · 58 lines · 4739 B
1// nx_pub_nobypass_gate.nx -- R7d: the BINDING mechanism for the no-bypass LAW = a NO-NEW-BYPASS ratchet.
2//
3// A legacy tree has known direct-publishers (migration is coordinated + ongoing). The forcing function that makes the
4// law BINDING NOW is: the build fails if anyone INTRODUCES a NEW bypass (current real-bypass count > frozen baseline),
5// while a clean change (count unchanged) ships -- so the set can only shrink. This gate proves that ratchet on a
6// fixture, and proves the comment-aware audit is load-bearing (a comment-only mention of a primitive is NOT counted,
7// where the un-stripped audit would flag it = the false-positive killer). File-based. license_tier: ORIGINAL expect_exit: 0
8import "nx_syscalls.nx"
9import "nx_publisher.nx"
10import "nx_runpath.nx"
11
12func 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 }
13func g_n(v: i64) -> i64 { var m: i64=v; if m<0{g_w("-" as *u8);m=0-m} let t:*u8=sys_mmap(24); var k:i64=0; if m==0{t[0]=48 as u8;k=1} while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1} var i:i64=0; let o:*u8=sys_mmap(24); while i<k{o[i]=t[k-1-i];i=i+1} sys_write(1,o,k); return 0 }
14func g_row(id: *u8, ok: i64, pass: *i64) -> i64 { g_w(" " as *u8); g_w(id); g_w(": " as *u8); if ok==1 { g_w("OK\n" as *u8); pass[0]=pass[0]+1 } else { g_w("FAIL\n" as *u8) } return 0 }
15func sv_write(path: *u8, content: *u8) -> i64 { let fd: i64 = sys_openat_wr(path, 0x1a4); if fd<0 { return 0 } var n: i64=0; while content[n]!=(0 as u8){n=n+1} sys_write(fd, content, n); sys_close(fd); return 1 }
16func mkf(D: *u8, name: *u8, content: *u8) -> *u8 { let p: *u8 = sys_mmap(700); pub_join(D, name, p); sv_write(p, content); return p }
17
18func main() -> i64 {
19 let pass: *i64 = sys_mmap(8) as *i64; pass[0]=0
20 g_w("=== NX-PUB-NOBYPASS GATE (no-new-bypass ratchet = the binding forcing function) ===\n" as *u8)
21 let wsid: *u8 = sys_mmap(64); rp_wsid(wsid); rp_ensure(wsid)
22 let D: *u8 = sys_mmap(512); rp_path(wsid, "pnb" as *u8, D); __syscall(83, D as i64, 493, 0, 0, 0, 0)
23
24 // legacy fixture: 2 real bypassers + 1 clean + 1 comment-only mention (must NOT count)
25 let b1: *u8 = mkf(D, "ws_b1.nx" as *u8, "func ship(){ pub_deploy(sha, src, st, live) }\n" as *u8)
26 let b2: *u8 = mkf(D, "ws_b2.nx" as *u8, "func ship(){ nx_aw_send(host, p, bytes) }\n" as *u8)
27 let cl: *u8 = mkf(D, "ws_clean.nx" as *u8, "func ship(){ pub_submit(src, dest, site, me, internal) }\n" as *u8)
28 let cm: *u8 = mkf(D, "ws_comment.nx" as *u8, "// legacy: this used nx_aw_send before the publisher\nfunc ship(){ pub_submit(s, d, si, me, internal) }\n" as *u8)
29
30 // baseline = real bypasses now (comment-aware)
31 let baseline: i64 = pub_audit_call_strict(b1, 0) + pub_audit_call_strict(b2, 0) + pub_audit_call_strict(cl, 0) + pub_audit_call_strict(cm, 0)
32
33 // a CLEAN change: add another pub_submit-only workstream -> count unchanged
34 let cl2: *u8 = mkf(D, "ws_clean2.nx" as *u8, "func ship(){ pub_submit(a, b, c, d, internal) }\n" as *u8)
35 let after_clean: i64 = baseline + pub_audit_call_strict(cl2, 0)
36 let allow_clean: i64 = (after_clean <= baseline) as i64 // ratchet: no increase -> ship
37
38 // a NEW BYPASS: add a workstream calling a primitive directly -> count increases -> blocked
39 let b3: *u8 = mkf(D, "ws_b3.nx" as *u8, "func ship(){ pub_promote_atomic(st, live) }\n" as *u8)
40 let after_bypass: i64 = baseline + pub_audit_call_strict(b3, 0)
41 let block_bypass: i64 = (after_bypass > baseline) as i64 // ratchet: increase -> RED
42
43 // comment-strip load-bearing: comment-only mention is 0 with strip, 1 without
44 let cm_strip: i64 = pub_audit_call_strict(cm, 0)
45 let cm_nostrip: i64 = pub_audit_file_strict(cm, 0)
46
47 g_w(" baseline_real_bypasses=" as *u8); g_n(baseline); g_w(" (expect 2) after_clean=" as *u8); g_n(after_clean); g_w(" after_new_bypass=" as *u8); g_n(after_bypass); g_w("\n" as *u8)
48 g_w(" comment-only mention: strip=" as *u8); g_n(cm_strip); g_w(" nostrip=" as *u8); g_n(cm_nostrip); g_w("\n" as *u8)
49
50 g_row("BASELINE: exactly 2 real bypassers counted (comment-only mention NOT counted)" as *u8, (baseline==2) as i64, pass)
51 g_row("RATCHET allows a no-new-bypass change (clean addition ships)" as *u8, allow_clean, pass)
52 g_row("RATCHET BLOCKS a newly-introduced bypass (build fails on increase)" as *u8, block_bypass, pass)
53 g_row("COMMENT-STRIP load-bearing: comment-only mention excluded (strip=0, nostrip=1)" as *u8, ((cm_strip==0) as i64) & ((cm_nostrip==1) as i64), pass)
54
55 g_w("NX-PUB-NOBYPASS rows=4 pass=" as *u8); g_n(pass[0])
56 if pass[0]==4 { g_w(" verdict=GREEN\n" as *u8); sys_exit(0); return 0 }
57 g_w(" verdict=RED\n" as *u8); sys_exit(1); return 1
58}