nx_nxa_tier_region_gate_t143.nx source
↩ module page · 493 lines · 26776 B
1// nx_nxa_tier_gate.nx -- THE GATE FOR THE INGEST TIER LADDER (nx_nxa_tier, /compare/modding MD5).
2//
3// SUBJECT: the nx_nxa_tier ELF, forked for real on the banked pre-TEXM house asset (13 sections, TEXC present,
4// 14,164 verts) -- a real artifact that is READ, never written. Every tooth asserts an exit code or a byte read
5// back out of the emitted tier through the format's own verifier (nxa_find checks the TOC and every section
6// checksum before returning), so a tier that merely EXISTS cannot pass.
7//
8// THE DANGEROUS FAILURES THIS GATE EXISTS TO CATCH: a tier whose weights no longer sum to 4096 or name a joint
9// past the skeleton (the pose player would read that as a broken rig), a tier that quietly dropped SKEL or
10// TEXM (a rig-less or map-less cast member wearing a success receipt), a tier that grew or moved outside the
11// source's own bounding box, and a budget that silently UPSAMPLED. Each has a tooth; three have neg-controls.
12//
13// FIXTURES AT RUNTIME in /tmp/nx_nxa_tier_region_gate_t143/, every output unlinked at SETUP and the unlink asserted, so the
14// gate is idempotent. The truncated fixture and the ladder conf are assembled here, never read from source.
15// license_tier: ORIGINAL No hw writes (Rule 26). expect_exit: 0
16import "nx_syscalls.nx"
17import "nx_gate_verdict.nx"
18import "nx_tool_run.nx"
19import "nx_nxa.nx"
20
21const TG_SUBJECT_DEFAULT: *u8 = "_offc/nx_nxa_tier.elf"
22// FIRST-SHIP LADDER (measured 2026-09-05): on the first nx_organ_ship there is no _offc twin yet -- the ship's PROVE
23// ran this gate with no argument, the default resolved to an absent file, every fork returned 127 and the ship
24// REFUSED a correct organ (5 of 20 RED, all three from exit 127). A gate must find the artifact under test in the
25// ship's own order -- the promoted offc twin, the artifact STAGED at the serving root, then the sovereign build
26// fossil -- and SAY which rung it took, so a proof about a stage is never mistaken for a proof about the twin.
27const TG_SUBJECT_STAGED: *u8 = "nx_nxa_tier.sov.elf.new"
28const TG_SUBJECT_STAGED_UP: *u8 = "../nx_nxa_tier.sov.elf.new"
29const TG_SUBJECT_BUILD: *u8 = "_build/nx_nxa_tier.sov.elf"
30const TG_SUBJECT_BUILD_DOWN: *u8 = "buildroot/_build/nx_nxa_tier.sov.elf"
31const TG_PLAYER: *u8 = "/volume1/homes/elderwesto/nishihost/nx_nxa_play.elf"
32const TG_ASSET: *u8 = "/volume1/homes/elderwesto/nishihost/knowledge/bank/ref9d.nxa.pretexm-20260823"
33const TG_DIR: *u8 = "/tmp/nx_nxa_tier_region_gate_t143"
34const TG_OUT1: *u8 = "/tmp/nx_nxa_tier_region_gate_t143/t1.nxa"
35const TG_OUT2: *u8 = "/tmp/nx_nxa_tier_region_gate_t143/t2.nxa"
36const TG_OUT3: *u8 = "/tmp/nx_nxa_tier_region_gate_t143/over.nxa"
37const TG_OUT4: *u8 = "/tmp/nx_nxa_tier_region_gate_t143/tiny.nxa"
38const TG_OUT5: *u8 = "/tmp/nx_nxa_tier_region_gate_t143/fromtrunc.nxa"
39const TG_TRUNC: *u8 = "/tmp/nx_nxa_tier_region_gate_t143/trunc.nxa"
40const TG_LADDER: *u8 = "/tmp/nx_nxa_tier_region_gate_t143/ladder.conf"
41const TG_PFX: *u8 = "/tmp/nx_nxa_tier_region_gate_t143/lad"
42const TG_LAD16: *u8 = "/tmp/nx_nxa_tier_region_gate_t143/lad_t16k.nxa"
43const TG_LAD4: *u8 = "/tmp/nx_nxa_tier_region_gate_t143/lad_t4k.nxa"
44const TG_LAD1: *u8 = "/tmp/nx_nxa_tier_region_gate_t143/lad_t1k.nxa"
45const TG_LADDER_ROWS: *u8 = "# runtime fixture\ntier|t16k|16384|above the source, must be skipped\ntier|t4k|4096|the rig floor\ntier|t1k|1024|the far tier\n"
46// the budget is the donor-derived rig floor (charsim bar, AF_VERT_MIN 4000): under the 14,164-vert source
47const TG_BUDGET: *u8 = "4000"
48const TG_BUDGET_N: i64 = 4000
49const TG_OVER: *u8 = "20000" // at or above the source vertex count: must REFUSE
50const TG_TINY: *u8 = "2" // under the 3-vertex floor: must REFUSE
51const TG_TRUNC_BYTES: i64 = 600 // TOC intact, payload gone -- the corrupt-input control
52const TG_LADDER_VERB: *u8 = "ladder"
53const TG_EXIT_OK: i64 = 0
54const TG_EXIT_REFUSE: i64 = 3
55const TG_EXEC_NOT_FOUND: i64 = 127
56const TG_CAPCAP: i64 = 262144
57const TG_ARGVN: i64 = 8
58const TG_MODEDIR: i64 = 493
59const TG_WORD: i64 = 8
60const TG_HDR: i64 = 32
61const TG_TOCE: i64 = 32
62const TG_SKIN_W: i64 = 8
63const TG_SKIN_J: i64 = 4
64const TG_Q12: i64 = 4096
65const TG_MIN_VERTS: i64 = 3
66const TG_ASCII_ZERO: i64 = 48
67const TG_ASCII_NINE: i64 = 57
68const TG_BBOX_W: i64 = 6
69
70func tg_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
71func tg_rd64(b: *u8, off: i64) -> i64 { let p: *i64 = ((b as i64) + off) as *i64; return p[0] }
72func tg_exists(path: *u8) -> i64 {
73 let lp: *i64 = sys_mmap(TG_WORD*2) as *i64
74 let b: *u8 = sys_read_file(path, lp)
75 if (b as i64) == 0 { return 0 }
76 return 1
77}
78func tg_load(path: *u8, lenout: *i64) -> *u8 {
79 let lp: *i64 = sys_mmap(TG_WORD*2) as *i64
80 let b: *u8 = sys_read_file(path, lp)
81 if (b as i64) == 0 { lenout[0] = 0; return 0 as *u8 }
82 lenout[0] = lp[0]
83 return b
84}
85func tg_run3(subject: *u8, a1: *u8, a2: *u8, a3: *u8, out: *u8, olen: *i64) -> i64 {
86 let av: *i64 = sys_mmap(TG_WORD*TG_ARGVN) as *i64
87 av[0] = subject as i64
88 av[1] = a1 as i64
89 av[2] = a2 as i64
90 av[3] = a3 as i64
91 av[4] = 0
92 return tr_run_capture(subject, av, out, TG_CAPCAP, olen)
93}
94func tg_run4(subject: *u8, a1: *u8, a2: *u8, a3: *u8, a4: *u8, out: *u8, olen: *i64) -> i64 {
95 let av: *i64 = sys_mmap(TG_WORD*TG_ARGVN) as *i64
96 av[0] = subject as i64
97 av[1] = a1 as i64
98 av[2] = a2 as i64
99 av[3] = a3 as i64
100 av[4] = a4 as i64
101 av[5] = 0
102 return tr_run_capture(subject, av, out, TG_CAPCAP, olen)
103}
104func tg_run1(subject: *u8, a1: *u8, out: *u8, olen: *i64) -> i64 {
105 let av: *i64 = sys_mmap(TG_WORD*TG_ARGVN) as *i64
106 av[0] = subject as i64
107 av[1] = a1 as i64
108 av[2] = 0
109 return tr_run_capture(subject, av, out, TG_CAPCAP, olen)
110}
111// the integer that follows <key> in a captured receipt, or -1 when the key is absent
112func tg_kv(buf: *u8, n: i64, key: *u8) -> i64 {
113 let kl: i64 = tg_slen(key)
114 var i: i64 = 0
115 while i + kl <= n {
116 var m: i64 = 0
117 var j: i64 = 0
118 while j < kl { if buf[i + j] == key[j] { m = m + 1 } j = j + 1 }
119 if m == kl {
120 var v: i64 = 0
121 var p: i64 = i + kl
122 var any: i64 = 0
123 while p < n {
124 let c: i64 = buf[p] as i64
125 if c < TG_ASCII_ZERO { return v }
126 if c > TG_ASCII_NINE { return v }
127 v = v * 10 + (c - TG_ASCII_ZERO)
128 any = 1
129 p = p + 1
130 }
131 if any == 1 { return v }
132 return 0 - 1
133 }
134 i = i + 1
135 }
136 return 0 - 1
137}
138func tg_has(buf: *u8, n: i64, key: *u8) -> i64 { if tg_kv(buf, n, key) >= 0 { return 1 } return 0 }
139// the word length of section <tag> from a file's TOC, walking the whole table; -1 when absent
140func tg_toc_wl(b: *u8, tag: i64) -> i64 {
141 let ns: i64 = tg_rd64(b, 16)
142 var s: i64 = 0
143 while s < ns {
144 let e: i64 = TG_HDR + s*TG_TOCE
145 if tg_rd64(b, e) == tag { return tg_rd64(b, e + 16) }
146 s = s + 1
147 }
148 return 0 - 1
149}
150func tg_copyable(tag: i64) -> i64 {
151 if tag == nxa_tag4("SKEL" as *u8) { return 1 }
152 if tag == nxa_tag4("ANIM" as *u8) { return 1 }
153 if tag == nxa_tag4("POSE" as *u8) { return 1 }
154 if tag == nxa_tag4("MATL" as *u8) { return 1 }
155 if tag == nxa_tag4("TEXM" as *u8) { return 1 }
156 if tag == nxa_tag4("HSTR" as *u8) { return 1 }
157 return 0
158}
159// bbox of a verified VERT section into out[0..6) = minx maxx miny maxy minz maxz; returns nverts or -1
160func tg_bbox(b: *u8, flen: i64, out: *i64) -> i64 {
161 let vwo: i64 = nxa_find(b, flen, nxa_tag4("VERT" as *u8))
162 if vwo < 0 { return 0 - 1 }
163 let w: *i64 = b as *i64
164 let nv: i64 = w[vwo]
165 if nv < 1 { return 0 - 1 }
166 let vw: *i64 = ((w as i64) + (vwo + 1)*8) as *i64
167 out[0] = vw[0]; out[1] = vw[0]; out[2] = vw[1]; out[3] = vw[1]; out[4] = vw[2]; out[5] = vw[2]
168 var v: i64 = 1
169 while v < nv {
170 let x: i64 = vw[v*3]; let y: i64 = vw[v*3 + 1]; let z: i64 = vw[v*3 + 2]
171 if x < out[0] { out[0] = x }
172 if x > out[1] { out[1] = x }
173 if y < out[2] { out[2] = y }
174 if y > out[3] { out[3] = y }
175 if z < out[4] { out[4] = z }
176 if z > out[5] { out[5] = z }
177 v = v + 1
178 }
179 return nv
180}
181func tg_write_bytes(path: *u8, b: *u8, n: i64) -> i64 {
182 let fd: i64 = sys_openat_wr(path, MODE_0644)
183 if fd < 0 { return 0 - 1 }
184 let wr: i64 = sys_write(fd, b, n)
185 sys_close(fd)
186 if wr != n { return 0 - 1 }
187 return n
188}
189
190
191func tg_region_fixture(path:*u8, unique:i64)->i64 {
192 let n:i64=848;let b:*u8=sys_mmap(n);if (b as i64)<=0{return 0}
193 let w:*i64=b as *i64
194 w[0]=nxa_magic();w[1]=NXA_VER;w[2]=3
195 w[4]=nxa_tag4("VERT" as *u8);w[5]=128;w[6]=37
196 w[8]=nxa_tag4("TRIS" as *u8);w[9]=424;w[10]=13
197 w[12]=nxa_tag4("TEXC" as *u8);w[13]=528;w[14]=40
198 w[16]=12;w[53]=4;w[66]=12;w[67]=3;w[68]=2;w[69]=0
199 var v:i64=0
200 while v<12 {let corner:i64=v%3;w[17+v*3]=0;w[18+v*3]=0;w[19+v*3]=0
201 if corner==1 {w[17+v*3]=10000};if corner==2 {w[18+v*3]=10000}
202 var region:i64=v/6;if unique==1{region=v}
203 w[70+v*3]=1000+region*4000;w[71+v*3]=1000;w[72+v*3]=region
204 w[54+v]=v;v=v+1
205 }
206 w[7]=nxa_check2(1,((b as i64)+128) as *i64,37)
207 w[11]=nxa_check2(1,((b as i64)+424) as *i64,13)
208 w[15]=nxa_check2(1,((b as i64)+528) as *i64,40)
209 w[3]=nxa_check2(1,((b as i64)+32) as *i64,12)
210 if tg_write_bytes(path,b,n)==n{return 1};return 0
211}
212func tg_regions(subject:*u8,ctr:*i64,cap:*u8,olen:*i64)->i64 {
213 let inp:*u8="/tmp/nx_nxa_tier_region_gate_t143/regions.nxa"
214 let out:*u8="/tmp/nx_nxa_tier_region_gate_t143/regions-tier.nxa"
215 let bad:*u8="/tmp/nx_nxa_tier_region_gate_t143/region-budget.nxa"
216 sys_unlinkat(out);sys_unlinkat(bad)
217 gv_check("cross-region-nearcoincident-fixture-written",tg_region_fixture(inp,0),ctr)
218 let rc:i64=tg_run3(subject,inp,out,"6" as *u8,cap,olen)
219 let lp:*i64=sys_mmap(16) as *i64;let b:*u8=tg_load(out,lp);var ok:i64=0
220 if (b as i64)>0 {let vo:i64=nxa_find(b,lp[0],nxa_tag4("VERT" as *u8));let xo:i64=nxa_find(b,lp[0],nxa_tag4("TEXC" as *u8));let to:i64=nxa_find(b,lp[0],nxa_tag4("TRIS" as *u8))
221 if vo>=0&&xo>=0&&to>=0 {let w:*i64=b as *i64;var a:i64=0;var z:i64=0;var wrong:i64=0;var i:i64=0
222 while i<w[vo] {let reg:i64=w[xo+4+i*3+2];if reg==0{a=a+1}else{if reg==1{z=z+1}else{wrong=wrong+1}}
223 if w[xo+4+i*3]!=1000+reg*4000{wrong=wrong+1};i=i+1}
224 if rc==0&&w[vo]==6&&w[to]==4&&a==3&&z==3&&wrong==0{ok=1}
225 }
226 }
227 gv_check("nearcoincident-regions-retain-six-vertices-both-exact-UV-owners",ok,ctr)
228 gv_check("incompatible-region-budget-fixture-written",tg_region_fixture(inp,1),ctr)
229 let brc:i64=tg_run3(subject,inp,bad,"6" as *u8,cap,olen)
230 var refused:i64=0;if brc==3&&tg_exists(bad)==0{refused=1}
231 gv_check("budget-below-region-floor-refuses-with-no-output",refused,ctr)
232 return 0
233}
234
235
236func tg_toon(source:*u8,tier:*u8,budget:i64,ctr:*i64)->i64 {
237 let il:*i64=sys_mmap(16) as *i64;let ol:*i64=sys_mmap(16) as *i64
238 let ib:*u8=tg_load(source,il);let ob:*u8=tg_load(tier,ol)
239 var valid:i64=1;if (ib as i64)<=0||(ob as i64)<=0{valid=0}
240 if valid==0{gv_check("actual-toon-readable",0,ctr);return 0}
241 let iv:i64=nxa_find(ib,il[0],nxa_tag4("VERT" as *u8));let ov:i64=nxa_find(ob,ol[0],nxa_tag4("VERT" as *u8))
242 let ot:i64=nxa_find(ob,ol[0],nxa_tag4("TRIS" as *u8));let ox:i64=nxa_find(ob,ol[0],nxa_tag4("TEXC" as *u8));let ok:i64=nxa_find(ob,ol[0],nxa_tag4("SKIN" as *u8));let os:i64=nxa_find(ob,ol[0],nxa_tag4("SKEL" as *u8))
243 if iv<0||ov<0||ot<0||ox<0||ok<0||os<0{valid=0}
244 gv_check("actual-toon-used-geometry-rig-UV-sections-verify",valid,ctr);if valid==0{return 0}
245 let iw:*i64=ib as *i64;let ow:*i64=ob as *i64;let nv:i64=ow[ov];let nt:i64=ow[ot];let nj:i64=ow[os]
246 var fit:i64=0;if nv>0&&nv<=budget&&nv<iw[iv]&&ol[0]<il[0]{fit=1};gv_check("actual-toon-same-declared-budget-and-smaller-bytes",fit,ctr)
247 var bad:i64=0;var v:i64=0
248 if ow[ox]!=nv||ow[ox+1]!=3||ow[ok]!=nv{bad=bad+1}
249 while v<nv {var sum:i64=0;var k:i64=0;while k<4{let j:i64=ow[ok+1+v*8+k];let weight:i64=ow[ok+5+v*8+k];if j<0||j>=nj||weight<0{bad=bad+1};sum=sum+weight;k=k+1};if sum!=4096{bad=bad+1};v=v+1}
250 var t:i64=0;while t<nt*3{let index:i64=ow[ot+1+t];if index<0||index>=nv{bad=bad+1};t=t+1}
251 gv_check("actual-toon-all-index-and-SKIN-rows-valid",if_zero(bad),ctr)
252 var copied:i64=0;var tags:i64=0
253 while tags<2 {var tag:i64=nxa_tag4("SKEL" as *u8);if tags==1{tag=nxa_tag4("TEXM" as *u8)}
254 let io:i64=nxa_find(ib,il[0],tag);let oo:i64=nxa_find(ob,ol[0],tag);let n:i64=tg_toc_wl(ib,tag)
255 if io>=0&&oo>=0&&n==tg_toc_wl(ob,tag){var diff:i64=0;var k:i64=0;while k<n{if iw[io+k]!=ow[oo+k]{diff=diff+1};k=k+1};if diff==0{copied=copied+1}}
256 tags=tags+1}
257 var exact:i64=0;if copied==2{exact=1};gv_check("actual-toon-SKEL-and-TEXM-byte-identical-to-source",exact,ctr)
258 gv_kv("actual_toon_verts" as *u8,nv);gv_kv("actual_toon_tris" as *u8,nt);gv_kv("actual_toon_budget" as *u8,budget)
259 return 0
260}
261func if_zero(v:i64)->i64{if v==0{return 1};return 0}
262func tg_positive(a:*u8)->i64{var n:i64=0;var i:i64=0;while a[i]!=(0 as u8){let c:i64=a[i] as i64;if c<48||c>57{return 0};n=n*10+c-48;i=i+1};return n}
263
264func main(argc: i64, argv: *i64) -> i64 {
265 let ctr: *i64 = gv_ctr()
266 gv_head("nx_nxa_tier gate -- a smaller NXA under a declared budget, the rig and maps intact, no upsample ever" as *u8)
267 var subject: *u8 = TG_SUBJECT_DEFAULT
268 var rung: *u8 = "argv" as *u8
269 if argc >= 2 { subject = argv[1] as *u8 } else {
270 rung = "offc-twin" as *u8
271 if tg_exists(TG_SUBJECT_DEFAULT) == 0 { subject = TG_SUBJECT_STAGED; rung = "staged-at-serving-root" as *u8 }
272 if tg_exists(subject) == 0 { subject = TG_SUBJECT_STAGED_UP; rung = "staged-at-serving-root-from-buildroot" as *u8 }
273 if tg_exists(subject) == 0 { subject = TG_SUBJECT_BUILD; rung = "sovereign-build-fossil" as *u8 }
274 if tg_exists(subject) == 0 { subject = TG_SUBJECT_BUILD_DOWN; rung = "sovereign-build-fossil-from-serving-root" as *u8 }
275 }
276 gv_puts(" subject: " as *u8); gv_puts(subject); gv_puts(" (rung=" as *u8); gv_puts(rung); gv_puts(")\n" as *u8)
277 gv_check("setup-subject-artifact-exists-on-the-first-ship-ladder (named rung, never a silent 127)" as *u8, tg_exists(subject), ctr)
278 gv_puts(" asset: " as *u8); gv_puts(TG_ASSET); gv_puts("\n\n" as *u8)
279
280 // ---- SETUP ----
281 sys_mkdir(TG_DIR, TG_MODEDIR)
282 sys_unlinkat(TG_OUT1); sys_unlinkat(TG_OUT2); sys_unlinkat(TG_OUT3); sys_unlinkat(TG_OUT4); sys_unlinkat(TG_OUT5)
283 sys_unlinkat(TG_TRUNC); sys_unlinkat(TG_LADDER); sys_unlinkat(TG_LAD16); sys_unlinkat(TG_LAD4); sys_unlinkat(TG_LAD1)
284 var clean: i64 = 0
285 if tg_exists(TG_OUT1) == 0 { if tg_exists(TG_OUT2) == 0 { if tg_exists(TG_OUT3) == 0 { if tg_exists(TG_LAD4) == 0 { clean = 1 } } } }
286 gv_check("setup-outputs-absent-before-measuring (gate is idempotent)" as *u8, clean, ctr)
287 let cap: *u8 = sys_mmap(TG_CAPCAP)
288 let olen: *i64 = sys_mmap(TG_WORD*2) as *i64
289 let lin: *i64 = sys_mmap(TG_WORD*2) as *i64
290 let bin: *u8 = tg_load(TG_ASSET, lin)
291 let inbox: *i64 = sys_mmap(TG_WORD*TG_BBOX_W) as *i64
292 let nv_in: i64 = tg_bbox(bin, lin[0], inbox)
293 let w_in: *i64 = bin as *i64
294 var in_ok: i64 = 0
295 if nv_in > TG_BUDGET_N { in_ok = 1 }
296 gv_puts(" input verts=" as *u8); gv_num(nv_in); gv_puts(" bytes=" as *u8); gv_num(lin[0]); gv_puts("\n" as *u8)
297 gv_check("setup-real-asset-readable-and-ABOVE-the-budget (a budget the source already meets cannot test a tier)" as *u8, in_ok, ctr)
298 var in_texc: i64 = 0
299 if nxa_find(bin, lin[0], nxa_tag4("TEXC" as *u8)) >= 0 { in_texc = 1 }
300 var in_skin: i64 = 0
301 if nxa_find(bin, lin[0], nxa_tag4("SKIN" as *u8)) >= 0 { in_skin = 1 }
302 var in_rig: i64 = 0
303 if in_texc == 1 { if in_skin == 1 { in_rig = 1 } }
304 gv_check("setup-asset-carries-SKIN-and-TEXC (the rows the tier must carry through)" as *u8, in_rig, ctr)
305
306 // ---- T1: one tier at the rig floor ----
307 let rc1: i64 = tg_run3(subject, TG_ASSET, TG_OUT1, TG_BUDGET, cap, olen)
308 gv_puts(" [T1] tier rc=" as *u8); gv_num(rc1); gv_puts(" receipt_bytes=" as *u8); gv_num(olen[0]); gv_puts("\n" as *u8)
309 var t1: i64 = 0
310 if rc1 == TG_EXIT_OK { t1 = 1 }
311 gv_check("tier-at-the-rig-floor-exits-OK" as *u8, t1, ctr)
312 let r_out_verts: i64 = tg_kv(cap, olen[0], "out_verts=" as *u8)
313 let r_in_tris: i64 = tg_kv(cap, olen[0], "in_tris=" as *u8)
314 let r_out_tris: i64 = tg_kv(cap, olen[0], " out_tris=" as *u8)
315 let r_coll: i64 = tg_kv(cap, olen[0], "collapsed_tris=" as *u8)
316 let r_secin: i64 = tg_kv(cap, olen[0], "sections_in=" as *u8)
317 let r_sum: i64 = tg_kv(cap, olen[0], " sum=" as *u8)
318
319 // ---- T2: the tier verifies through the format's own reader and is SMALLER, within budget ----
320 let l1: *i64 = sys_mmap(TG_WORD*2) as *i64
321 let b1: *u8 = tg_load(TG_OUT1, l1)
322 var nv1: i64 = 0 - 1
323 var nt1: i64 = 0 - 1
324 var nj1: i64 = 0 - 1
325 let w1: *i64 = b1 as *i64
326 if (b1 as i64) != 0 {
327 let vo: i64 = nxa_find(b1, l1[0], nxa_tag4("VERT" as *u8))
328 let to: i64 = nxa_find(b1, l1[0], nxa_tag4("TRIS" as *u8))
329 let so: i64 = nxa_find(b1, l1[0], nxa_tag4("SKEL" as *u8))
330 if vo >= 0 { nv1 = w1[vo] }
331 if to >= 0 { nt1 = w1[to] }
332 if so >= 0 { nj1 = w1[so] }
333 }
334 gv_puts(" [T2] tier verts=" as *u8); gv_num(nv1); gv_puts(" tris=" as *u8); gv_num(nt1); gv_puts(" joints=" as *u8); gv_num(nj1); gv_puts(" bytes=" as *u8); gv_num(l1[0]); gv_puts("\n" as *u8)
335 var t2: i64 = 0
336 if nv1 >= TG_MIN_VERTS { if nv1 <= TG_BUDGET_N { if nv1 < nv_in { if nt1 >= 1 { t2 = 1 } } } }
337 gv_check("tier-verifies-through-nxa_find-and-is-under-budget-and-under-the-source (checksums, count, shrink)" as *u8, t2, ctr)
338
339 // ---- T3: every SKIN row still sums to 4096 and names joints inside the carried SKEL, full population ----
340 var skin_ok: i64 = 0
341 var bad_rows: i64 = 0
342 var audited: i64 = 0
343 if (b1 as i64) != 0 {
344 let ko: i64 = nxa_find(b1, l1[0], nxa_tag4("SKIN" as *u8))
345 if ko >= 0 { if w1[ko] == nv1 { if nj1 > 0 {
346 var r: i64 = 0
347 while r < nv1 {
348 var sum: i64 = 0
349 var jbad: i64 = 0
350 var f: i64 = 0
351 while f < TG_SKIN_J {
352 let j: i64 = w1[ko + 1 + r*TG_SKIN_W + f]
353 let wq: i64 = w1[ko + 1 + r*TG_SKIN_W + TG_SKIN_J + f]
354 sum = sum + wq
355 if j < 0 { jbad = 1 }
356 if j >= nj1 { jbad = 1 }
357 f = f + 1
358 }
359 if sum != TG_Q12 { bad_rows = bad_rows + 1 } else { if jbad == 1 { bad_rows = bad_rows + 1 } }
360 audited = audited + 1
361 r = r + 1
362 }
363 if audited == nv1 { if bad_rows == 0 { skin_ok = 1 } }
364 } } }
365 }
366 gv_puts(" [T3] skin rows audited=" as *u8); gv_num(audited); gv_puts(" bad=" as *u8); gv_num(bad_rows); gv_puts("\n" as *u8)
367 gv_check("every-tier-vertex-weights-sum-4096-and-name-a-joint-inside-SKEL (full population, count equals verts)" as *u8, skin_ok, ctr)
368
369 // ---- T4: TEXC carried, one row per tier vertex ----
370 var texc_ok: i64 = 0
371 if (b1 as i64) != 0 {
372 let xo: i64 = nxa_find(b1, l1[0], nxa_tag4("TEXC" as *u8))
373 if xo >= 0 { if w1[xo] == nv1 { if w1[xo + 1] >= 1 { texc_ok = 1 } } }
374 }
375 gv_check("TEXC-carried-with-one-row-per-tier-vertex (the atlas still samples)" as *u8, texc_ok, ctr)
376
377 // ---- T5: the tier lies inside the source bbox (a centroid can never leave its members' hull) ----
378 let obox: *i64 = sys_mmap(TG_WORD*TG_BBOX_W) as *i64
379 var inside: i64 = 0
380 if (b1 as i64) != 0 { if tg_bbox(b1, l1[0], obox) > 0 {
381 if obox[0] >= inbox[0] { if obox[1] <= inbox[1] { if obox[2] >= inbox[2] { if obox[3] <= inbox[3] { if obox[4] >= inbox[4] { if obox[5] <= inbox[5] { inside = 1 } } } } } }
382 } }
383 gv_puts(" [T5] source bbox x=" as *u8); gv_num(inbox[0]); gv_puts(".." as *u8); gv_num(inbox[1]); gv_puts(" tier bbox x=" as *u8); gv_num(obox[0]); gv_puts(".." as *u8); gv_num(obox[1]); gv_puts("\n" as *u8)
384 gv_check("tier-bbox-inside-source-bbox-on-all-three-axes" as *u8, inside, ctr)
385
386 // ---- T6: every copyable section of the source survives with its exact wordlen (SKEL at least) ----
387 var copy_want: i64 = 0
388 var copy_got: i64 = 0
389 if (b1 as i64) != 0 {
390 let ns_in: i64 = tg_rd64(bin, 16)
391 var s: i64 = 0
392 while s < ns_in {
393 let e: i64 = TG_HDR + s*TG_TOCE
394 let tag: i64 = tg_rd64(bin, e)
395 if tg_copyable(tag) == 1 {
396 copy_want = copy_want + 1
397 if tg_toc_wl(b1, tag) == tg_rd64(bin, e + 16) { copy_got = copy_got + 1 }
398 }
399 s = s + 1
400 }
401 }
402 gv_puts(" [T6] copyable sections carried=" as *u8); gv_num(copy_got); gv_puts(" of " as *u8); gv_num(copy_want); gv_puts("\n" as *u8)
403 var t6: i64 = 0
404 if copy_want >= 1 { if copy_got == copy_want { t6 = 1 } }
405 gv_check("every-copyable-section-survives-with-its-exact-wordlen (SKEL ANIM POSE MATL TEXM HSTR, denominator from the source)" as *u8, t6, ctr)
406
407 // ---- T7: the receipt's arithmetic closes and agrees with the bytes ----
408 gv_puts(" [T7] receipt out_verts=" as *u8); gv_num(r_out_verts); gv_puts(" in_tris=" as *u8); gv_num(r_in_tris); gv_puts(" out_tris=" as *u8); gv_num(r_out_tris); gv_puts(" collapsed=" as *u8); gv_num(r_coll); gv_puts(" sections_in=" as *u8); gv_num(r_secin); gv_puts(" sum=" as *u8); gv_num(r_sum); gv_puts("\n" as *u8)
409 var t7: i64 = 0
410 if r_out_verts == nv1 { if r_out_tris == nt1 { if r_in_tris == r_out_tris + r_coll { if r_secin == r_sum { if r_secin >= 1 { t7 = 1 } } } } }
411 gv_check("receipt-partition-closes (kept + collapsed = source tris, remapped + copied + dropped = sections) and matches the bytes" as *u8, t7, ctr)
412
413 // ---- T8: determinism -- the same input and budget emit byte-identical bytes ----
414 let rc2: i64 = tg_run3(subject, TG_ASSET, TG_OUT2, TG_BUDGET, cap, olen)
415 let l2: *i64 = sys_mmap(TG_WORD*2) as *i64
416 let b2: *u8 = tg_load(TG_OUT2, l2)
417 var same: i64 = 0
418 if rc2 == TG_EXIT_OK { if (b2 as i64) != 0 { if l2[0] == l1[0] { if l1[0] > 0 {
419 var diff: i64 = 0
420 var k: i64 = 0
421 while k < l1[0] { if b1[k] != b2[k] { diff = diff + 1 } k = k + 1 }
422 if diff == 0 { same = 1 }
423 } } } }
424 gv_check("determinism-second-run-is-byte-identical" as *u8, same, ctr)
425
426 // ---- T9: neg-control -- a budget at or above the source REFUSES and writes nothing ----
427 let rc3: i64 = tg_run3(subject, TG_ASSET, TG_OUT3, TG_OVER, cap, olen)
428 gv_puts(" [T9] over-budget rc=" as *u8); gv_num(rc3); gv_puts("\n" as *u8)
429 var t9: i64 = 0
430 if rc3 == TG_EXIT_REFUSE { if tg_exists(TG_OUT3) == 0 { t9 = 1 } }
431 gv_check("neg-control-upsample-budget-refused-by-name-AND-writes-no-output" as *u8, t9, ctr)
432 var fired_bad: i64 = 0
433 if rc3 == TG_EXIT_REFUSE { fired_bad = 1 }
434 var fired_good: i64 = 0
435 if rc1 == TG_EXIT_REFUSE { fired_good = 1 }
436 gv_bite("neg-control-refusal-fires-on-the-upsample-and-not-on-the-real-budget" as *u8, fired_bad, fired_good, ctr)
437
438 // ---- T10: neg-control -- a budget under the 3-vertex floor REFUSES ----
439 let rc4: i64 = tg_run3(subject, TG_ASSET, TG_OUT4, TG_TINY, cap, olen)
440 var t10: i64 = 0
441 if rc4 == TG_EXIT_REFUSE { if tg_exists(TG_OUT4) == 0 { t10 = 1 } }
442 gv_check("neg-control-budget-under-three-vertices-refused-and-writes-no-output" as *u8, t10, ctr)
443
444 // ---- T11: neg-control -- a truncated container (TOC intact, payload cut) REFUSES ----
445 var trunc_ok: i64 = 0
446 if lin[0] > TG_TRUNC_BYTES { if tg_write_bytes(TG_TRUNC, bin, TG_TRUNC_BYTES) == TG_TRUNC_BYTES { trunc_ok = 1 } }
447 gv_check("setup-truncated-fixture-reached-the-condition (TOC intact, payload cut)" as *u8, trunc_ok, ctr)
448 let rc5: i64 = tg_run3(subject, TG_TRUNC, TG_OUT5, TG_BUDGET, cap, olen)
449 gv_puts(" [T11] truncated rc=" as *u8); gv_num(rc5); gv_puts("\n" as *u8)
450 var t11: i64 = 0
451 if rc5 == TG_EXIT_REFUSE { if tg_exists(TG_OUT5) == 0 { t11 = 1 } }
452 gv_check("neg-control-truncated-input-refused-by-name-and-writes-no-output" as *u8, t11, ctr)
453
454 // ---- T12: the tier PLAYS -- the independent pose player evaluates it with zero unweighted vertices ----
455 let rc6: i64 = tg_run1(TG_PLAYER, TG_OUT1, cap, olen)
456 let zw: i64 = tg_kv(cap, olen[0], "zero_weight_verts=" as *u8)
457 let pj: i64 = tg_kv(cap, olen[0], "joints=" as *u8)
458 let pv: i64 = tg_kv(cap, olen[0], "verts=" as *u8)
459 gv_puts(" [T12] player rc=" as *u8); gv_num(rc6); gv_puts(" joints=" as *u8); gv_num(pj); gv_puts(" verts=" as *u8); gv_num(pv); gv_puts(" zero_weight_verts=" as *u8); gv_num(zw); gv_puts("\n" as *u8)
460 var t12: i64 = 0
461 if rc6 == TG_EXIT_OK { if zw == 0 { if pv == nv1 { if pj == nj1 { t12 = 1 } } } }
462 gv_check("independent-pose-player-plays-the-tier-with-zero-unweighted-vertices-and-the-same-counts" as *u8, t12, ctr)
463
464 // ---- T13: the ladder verb -- tiers under the source emitted, the tier above it skipped, partition printed ----
465 let lw: i64 = tg_write_bytes(TG_LADDER, TG_LADDER_ROWS, tg_slen(TG_LADDER_ROWS))
466 var lad_setup: i64 = 0
467 if lw > 0 { lad_setup = 1 }
468 gv_check("setup-ladder-conf-written-at-runtime" as *u8, lad_setup, ctr)
469 let rc7: i64 = tg_run4(subject, TG_LADDER_VERB, TG_ASSET, TG_PFX, TG_LADDER, cap, olen)
470 let em: i64 = tg_kv(cap, olen[0], "emitted=" as *u8)
471 let sk: i64 = tg_kv(cap, olen[0], "skipped=" as *u8)
472 let fl: i64 = tg_kv(cap, olen[0], "failed=" as *u8)
473 gv_puts(" [T13] ladder rc=" as *u8); gv_num(rc7); gv_puts(" emitted=" as *u8); gv_num(em); gv_puts(" skipped=" as *u8); gv_num(sk); gv_puts(" failed=" as *u8); gv_num(fl); gv_puts("\n" as *u8)
474 var t13: i64 = 0
475 if rc7 == TG_EXIT_OK { if em == 2 { if sk == 1 { if fl == 0 { if tg_exists(TG_LAD4) == 1 { if tg_exists(TG_LAD1) == 1 { if tg_exists(TG_LAD16) == 0 { t13 = 1 } } } } } } }
476 gv_check("ladder-emits-every-tier-under-the-source-skips-the-one-above-and-the-partition-sums" as *u8, t13, ctr)
477
478 // ---- the subject actually ran ----
479 var ran: i64 = 1
480 if rc1 < 0 { ran = 0 }
481 if rc1 == TG_EXEC_NOT_FOUND { ran = 0 }
482 gv_check("neg-control-subject-actually-executed (not 127, not a harness sentinel)" as *u8, ran, ctr)
483
484 tg_regions(subject,ctr,cap,olen)
485 if argc>=5{tg_toon(argv[2] as *u8,argv[3] as *u8,tg_positive(argv[4] as *u8),ctr)}
486 gv_kv("tier_verts" as *u8, nv1)
487 gv_kv("tier_tris" as *u8, nt1)
488 gv_kv("source_verts" as *u8, nv_in)
489 gv_kv("collapsed_tris" as *u8, r_coll)
490 let rc: i64 = gv_verdict("NXA-TIER" as *u8, ctr, "a smaller verified NXA under the budget, rig and atlas rows carried, no upsample and no silent section loss" as *u8)
491 sys_exit(rc)
492 return rc
493}