code wiki / (root) / nx_staging_structured_gate_t296.nx

nx_staging_structured_gate_t296.nx source

↩ module page · 74 lines · 5296 B

1// nx_staging_structured_gate_t296.nx -- Validates and classifies structured gate artifacts for staging compatibility and content integrity. 2import "_hdl_build/nx_staging_guard.nx" 3import "nx_gate_verdict.nx" 4import "nx_fs_create_lib.nx" 5func sgg_copy(b:*u8,n:i64)->*u8{let p:*u8=sys_mmap_try(n);if (p as i64)<=0{return p};var i:i64=0;while i<n{p[i]=b[i];i=i+1};return p} 6func sgg_mutate(b:*u8,n:i64,s:*u8)->i64{let z:i64=sg_strlen(s);var hits:i64=0;var i:i64=0;while i<=n-z{if cdl_bytes_eq(b+i,z,s,z)==1{b[i]=63 as u8;hits=hits+1};i=i+1};return hits} 7func sgg_fixture(path:*u8,b:*u8,n:i64)->i64{ 8 let r:i64=fxc_create(path,b,n);if r==n{return 1};if r!=FXC_EXISTS{return 0} 9 var z:i64=0;let old:*u8=sys_map_file(path,&z);if (old as i64)<=0{return 0} 10 let same:i64=cdl_bytes_eq(old,z,b,n);sys_munmap_direct(old,z);return same 11} 12func main()->i64{ 13 let ctr:*i64=gv_ctr();let cfg:*i64=sys_mmap_try(SG_C_SLOTS*__size_of(i64)) as *i64 14 let out:*i64=sys_mmap_try(SG_OUT_SLOTS*__size_of(i64)) as *i64 15 if (cfg as i64)<=0||(out as i64)<=0{return 2} 16 sg_conf_load(cfg);cfg[SG_C_MAXTOK]=0 17 let legacy:*i64=sys_mmap_try(5*__size_of(i64)) as *i64 18 if (legacy as i64)<=0{return 2} 19 let raw:*u8="raw-api-compatibility-message!" 20 let rawN:i64=sg_strlen(raw) 21 gv_check("legacy raw buffer identical remains accepted",sg_caploss(raw,rawN,raw,rawN,cfg,legacy)==0&&legacy[1]==0,ctr) 22 gv_check("legacy raw buffer removal remains measured",sg_caploss(raw,rawN,"",0,cfg,legacy)==1000&&legacy[1]==1,ctr) 23 sys_munmap_direct(legacy as *u8,5*__size_of(i64)) 24 var c:i64=-1 25 while c<=8{ 26 var normal:i64=0;if c==SG_FORWARD||c==SG_ORPHAN{normal=1} 27 var approved:i64=normal;if c>=SG_BACKDATE{if c<=SG_CAPLOSS{approved=1}} 28 gv_check("class matrix normal/exact approval/nonexact refusal",sg_allows_override(c,0)==normal&&sg_allows_override(c,1)==approved&&sg_allows_override(c,2)==normal,ctr) 29 c=c+1 30 } 31 let lp:*u8="../nx_gltf_render_prepare_candidate_t230.elf" 32 let np:*u8="../nx_gltf_render_prepare_candidate_t230.sov.elf.new" 33 var an:i64=0;var bn:i64=0;let a:*u8=sys_map_file(lp,&an);let b:*u8=sys_map_file(np,&bn) 34 if (a as i64)<=0||(b as i64)<=0{return 2} 35 var e:SgContentEvidence;let rc:i64=sg_measure_bytes(a,an,b,bn,cfg,&e) 36 gv_check("actual material pair structured qualified zero loss",rc==0&&e.state==0&&e.missing==0&&e.source_removed==0,ctr) 37 let cl:i64=sg_classify(lp,np,0,cfg,out) 38 gv_check("actual path comparison qualified same loss",cl!=SG_UNQUALIFIED&&out[SG_O_CONTENT_STATE]==0&&out[SG_O_MISSING]==0&&out[SG_O_SOURCE_REMOVED]==0,ctr) 39 let same:i64=sg_classify(lp,lp,0,cfg,out) 40 gv_check("same complete artifact forward and identical",same==SG_FORWARD&&out[SG_O_IDENTICAL]==1,ctr) 41 let missing:*u8="knowledge/gates/not-created-staging-t296.elf" 42 gv_check("true missing candidate NONE not overrideable",sg_classify(lp,missing,0,cfg,out)==SG_NONE&&sg_allows_override(SG_NONE,1)==0,ctr) 43 gv_check("valid first promotion structurally qualified",sg_classify(missing,np,0,cfg,out)==SG_ORPHAN&&out[SG_O_CONTENT_STATE]==0,ctr) 44 let invalid:*u8="knowledge/gates/contentdiff-invalid-t295.elf" 45 gv_check("malformed existing candidate unqualified",sg_classify(lp,invalid,0,cfg,out)==SG_UNQUALIFIED&&out[SG_O_CONTENT_STATE]<0,ctr) 46 gv_check("malformed first promotion unqualified",sg_classify(missing,invalid,0,cfg,out)==SG_UNQUALIFIED,ctr) 47 gv_check("non ENOENT live error not orphan",sg_classify("knowledge/gates/contentdiff-invalid-t295.elf/child",np,0,cfg,out)==SG_UNQUALIFIED,ctr) 48 gv_check("directory candidate unqualified",sg_classify(lp,"knowledge/gates",0,cfg,out)==SG_UNQUALIFIED,ctr) 49 gv_check("unknown ELF refused",sg_classify(lp,"knowledge/gates/contentdiff-unknown-t295.elf",0,cfg,out)==SG_UNQUALIFIED,ctr) 50 let cp:*u8=sgg_copy(b,bn);if (cp as i64)<=0{return 2} 51 let hits:i64=sgg_mutate(cp,bn,"runtime/nx_gltf_render_prepare_candidate_t230.nx") 52 let rp:*u8="knowledge/gates/staging-source-removed-t296.elf" 53 if sgg_fixture(rp,cp,bn)!=1{return 3} 54 cfg[SG_C_MAXTOK]=1 55 let removal:i64=sg_classify(lp,rp,0,cfg,out) 56 gv_check("source removal exhaustive despite one sample",hits>0&&removal==SG_CAPLOSS&&out[SG_O_SOURCE_REMOVED]>0&&out[SG_O_CONTENT_STATE]==0,ctr) 57 cfg[SG_C_MAXTOK]=0 58 let huge:i64=SG_FILECAP+an 59 let hb:*u8=sys_mmap_try(huge);if (hb as i64)<=0{return 2} 60 var j:i64=0;while j<an{hb[j]=a[j];j=j+1} 61 let token:*u8="STAGING_TAIL_ONLY_REMOVAL_T296";let tn:i64=sg_strlen(token) 62 j=0;while j<tn{hb[SG_FILECAP+j]=token[j];j=j+1} 63 let hp:*u8="knowledge/gates/staging-large-live-t296.elf" 64 let hq:*u8="knowledge/gates/staging-large-new-t296.elf" 65 if sgg_fixture(hp,hb,huge)!=1{return 3};hb[SG_FILECAP]=63 as u8 66 if sgg_fixture(hq,hb,huge)!=1{return 3} 67 cfg[SG_C_CAPLOSSABS]=1 68 let hc:i64=sg_classify(hp,hq,0,cfg,out) 69 gv_check("complete mapping finds loss beyond former 8MiB cap",hc==SG_CAPLOSS&&out[SG_O_MISSING]==1&&out[SG_O_NEWSZ]==huge,ctr) 70 gv_check("unqualified cannot use approval",sg_allows_override(SG_UNQUALIFIED,1)==0,ctr) 71 sys_munmap_direct(hb,huge);sys_munmap_direct(cp,bn);sys_munmap_direct(a,an);sys_munmap_direct(b,bn) 72 sys_munmap_direct(cfg as *u8,SG_C_SLOTS*__size_of(i64));sys_munmap_direct(out as *u8,SG_OUT_SLOTS*__size_of(i64)) 73 return gv_verdict("staging-structured-t296",ctr,"Candidate staging only; structured identity evidence, not behavioral equivalence; no promotion invoked") 74}