code wiki / _hdl_build / nx_dedupe_source_gate.nx
nx_dedupe_source_gate.nx source
↩ module page · 42 lines · 2509 B
1// nx_dedupe_source_gate.nx -- D001 gate for the sovereign dual-copy reconcile (gv-verdict anchored).
2// Proves the RESOLUTION of the seq207 hazard is safe + discriminating on hermetic CWD kat files (never
3// touches buildroot): a divergent shadow is soft-deleted (renamed, bytes preserved) leaving one copy;
4// a missing shadow is a benign no-op; a missing canonical SSOT is REFUSED (never reconcile toward a
5// missing truth); the op is idempotent. NO real source is mutated by this gate.
6// license_tier: ORIGINAL expect_exit: 0
7import "nx_dedupe_source_lib.nx"
8import "nx_gate_verdict.nx"
9
10func main() -> i64 {
11 let ctr: *i64 = gv_ctr()
12 gv_head("nx_dedupe_source_gate -- seq207 dual-copy RESOLUTION: soft-delete stale twin, fail-safe" as *u8)
13 let bak: *u8 = sys_mmap(512)
14 ds_write_kat("dsgcanon.nx" as *u8, "CANON with the fix\n" as *u8)
15 ds_write_kat("dsgshadow.nx" as *u8, "SHADOW stale different bytes\n" as *u8)
16 let r1: i64 = ds_reconcile("dsgcanon.nx" as *u8, "dsgshadow.nx" as *u8, bak)
17 var t1: i64=0
18 if r1==0 { t1=1 }
19 gv_check("T1 divergent dual-copy -> reconciled (code 0)" as *u8, t1, ctr)
20 var t2: i64=0
21 if ds_exists("dsgshadow.nx" as *u8)==0 { t2=1 }
22 gv_check("T2 stale shadow GONE from the build path after reconcile" as *u8, t2, ctr)
23 var t3: i64=0
24 if ds_exists(bak)==1 { if ds_exists("dsgcanon.nx" as *u8)==1 { t3=1 } }
25 gv_check("T3 shadow bytes PRESERVED in .dupe-reconciled backup (rule-13) + canonical untouched" as *u8, t3, ctr)
26 let r2: i64 = ds_reconcile("dsgcanon.nx" as *u8, "dsgshadow.nx" as *u8, bak)
27 var t4: i64=0
28 if r2==10 { t4=1 }
29 gv_check("T4 idempotent: re-run with shadow gone = benign no-op (code 10)" as *u8, t4, ctr)
30 let bak2: *u8 = sys_mmap(512)
31 let r3: i64 = ds_reconcile("dsg_no_such_canon.nx" as *u8, "dsgcanon.nx" as *u8, bak2)
32 var t5: i64=0
33 if r3==2 { if ds_exists("dsgcanon.nx" as *u8)==1 { t5=1 } }
34 gv_check("T5 REFUSE when canonical SSOT missing (code 2), shadow left intact (never reconcile toward missing truth)" as *u8, t5, ctr)
35 let sf: i64 = ds_selftest()
36 var t6: i64=0
37 if sf==0 { t6=1 }
38 gv_check("T6 embedded selftest (the CLI --kat contract) 0 fails" as *u8, t6, ctr)
39 let rc: i64 = gv_verdict("DEDUPE-SOURCE-GATE" as *u8, ctr, "seq207 dual-copy resolution: soft-delete stale twin (rename+preserve), benign no-op, refuse-no-canonical, idempotent -- the sovereign fix for the mgmt build guard's detection" as *u8)
40 sys_exit(rc)
41 return rc
42}