883 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
74 lines
6.6 KiB
Python
74 lines
6.6 KiB
Python
#!/usr/bin/env python3
|
|
"""Consume one completed converted family into numeric containers, without reconversion."""
|
|
import argparse,copy,hashlib,json,struct,sys
|
|
from pathlib import Path
|
|
from unittest.mock import patch
|
|
sys.path.insert(0,str(Path(__file__).resolve().parents[1]/'ops'))
|
|
import casc_asset_package as c
|
|
from item_appearance_preflight import model_dependency_chunks
|
|
from item_model_assets import stage_registered
|
|
|
|
def check(job):
|
|
load=lambda p:json.loads(Path(p).read_text())
|
|
pin=lambda p:hashlib.sha256(Path(p).read_bytes()).hexdigest()
|
|
parameters=load(job/'stage-parameters.json');audit=load(job/'fixture-input-audit.json')
|
|
original=load(parameters['retained_conversion_manifest']);selected=[r for r in original['records']if r['structural_conversion_complete']]
|
|
held=[r for r in original['records']if not r['structural_conversion_complete']]
|
|
assert len(selected)==1046 and len(held)==122 and c.MAX_ASSET_BATCH==32768
|
|
baseline=load(parameters['baseline_manifest']);old={r['path']:r for r in baseline['assets']}
|
|
assert len(old)==14921
|
|
outputs=set(audit['conversion_output_files']);forbidden=set(audit['forbidden_parent_texture_files'])|{str(Path(p).resolve())for p in audit['Source_body_paths']}
|
|
body_expectations={r['native_body_sha256']:r for r in selected};output_rows={r['file']:r for x in selected for r in x['outputs']}
|
|
reader=Path.read_bytes;container=c.model_container;reads={};containers=[];input_model_hashes=set();root_memory=[None]
|
|
def read(path):
|
|
key=str(path.resolve());assert key not in forbidden,'Source or accepted texture body was read'
|
|
raw=reader(path)
|
|
if key in outputs:
|
|
reads[key]=reads.get(key,0)+1
|
|
expected=output_rows[path.name]
|
|
assert len(raw)==expected['bytes'] and hashlib.sha256(raw).hexdigest()==expected['sha256'],'Retained new-container input changed'
|
|
if path.resolve()==Path(parameters['native_root']).resolve():root_memory[0]=raw
|
|
return raw
|
|
def numeric(body,skins,textures):
|
|
digest=hashlib.sha256(body).hexdigest();assert digest in body_expectations and digest not in input_model_hashes;input_model_hashes.add(digest)
|
|
result=container(body,skins,textures);deps=model_dependency_chunks(result)
|
|
assert deps['skin_file_ids']==skins and deps['texture_file_ids']==textures and not deps['skin_path_fallback_unreviewed']
|
|
assert len(skins)==struct.unpack_from('<I',body,68)[0]
|
|
count,offset=struct.unpack_from('<II',body,80);assert len(textures)==count and all(type(i)is int and i>0 for i in skins+textures)
|
|
tag,size=struct.unpack_from('<4sI',result);assert tag==b'MD21'and size==len(body)
|
|
expected=bytearray(body)
|
|
for i in range(count):struct.pack_into('<II',expected,offset+16*i+8,0,0)
|
|
actual=result[8:8+size];assert actual==expected,'MD21 construction changed bytes outside numeric texture references'
|
|
assert struct.unpack_from('<I',actual,16)[0]==struct.unpack_from('<I',body,16)[0]
|
|
containers.append(dict(native_body_sha256=digest,SFID=skins,TXID=textures,Source_and_inline_flags_and_tracks_preserved=True,only_fixed_texture_name_references_cleared=True))
|
|
return result
|
|
arguments={k:Path(v)if k in('source_manifest','conversion_manifest','baseline_manifest','native_root','output','retained_conversion_manifest','validated_model_texture_bindings')else v for k,v in parameters.items()}
|
|
with patch.object(Path,'read_bytes',read),patch.object(c,'model_container',numeric):result=stage_registered(**arguments)
|
|
assert len(containers)==1046 and len(reads)==5209 and all(n==1 for n in reads.values())
|
|
after={r['path']:r for r in result['assets']};assert all(after[p]==r for p,r in old.items());delta=[r for p,r in after.items()if p not in old]
|
|
assert len(after)==20130 and len(delta)==5209 and not result['excluded']
|
|
assert sum(r['kind']=='model'for r in delta)==1046 and sum(r['kind']=='skin'for r in delta)==4163
|
|
assert all(result['registry']['slots'][p]==i for p,i in baseline['registry']['slots'].items())
|
|
# Complete held cohort insertion fails before asset inputs/output; no successful stage is repeated.
|
|
refusals=[];ref=job/'new-family-refusals';ref.mkdir()
|
|
invalid=load(parameters['conversion_manifest']);invalid['records']+=held
|
|
bad=ref/'held122-inserted.json';bad.write_text(json.dumps(invalid))
|
|
args=dict(arguments,conversion_manifest=bad,output=ref/'never-held-output')
|
|
try:stage_registered(**args)
|
|
except ValueError as e:
|
|
assert str(e)=='Retained conversion output identity differs';assert not args['output'].exists();refusals.append(dict(case='all122-held-model-insertion',reason=str(e)))
|
|
else:raise AssertionError('Unsupported122cohort admitted')
|
|
# New upper-bound refusal uses the existing framing entry point before any native context/root lookup.
|
|
upper=ref/'32769-assets.json';upper.write_text(json.dumps(dict(assets=[None]*32769)));proof=ref/'proof';proof.mkdir();(proof/'report.json').write_text(json.dumps(dict(asset_manifest_sha256=pin(upper))))
|
|
with patch.object(c,'root_groups',side_effect=AssertionError('Oversize reached native ROOT parser')):
|
|
try:c.stage_framed_native_assets(upper,ref/'missing-native-context',proof,ref/'never-oversize-output')
|
|
except ValueError as e:assert str(e)=='Framed asset batch bound';refusals.append(dict(case='new32769-early-refusal',reason=str(e)))
|
|
else:raise AssertionError('Oversize framing family admitted')
|
|
mp=Path(parameters['output'])/'manifest.json'
|
|
report=dict(status='PASS_COMPLETE1046_RETAINED_MODEL_NUMERIC_RELATIONSHIPS',family_models=1046,SKINs=4163,new_IDs=5209,parent_assets=14921,candidate_assets=20130,texture_payloads_added=0,Source_and_derived_inline_flags_exact=True,all_body_bytes_preserved_except_numeric_texture_filename_refs=True,container_relationships=containers,retained_output_files_read_once=5209,Source_model_body_reads=0,existing_texture_body_reads=0,old277_models_reimported=0,old_conversions_or_SDK_checks_repeated=False,whole_held_cohort_preserved=122,refusals=refusals,new_max_asset_batch=32768,casc_asset_package_source_sha256=pin(Path(c.__file__)),all_old_parent_asset_rows_and_ID_reservations_preserved=True,Native_constructor_material_scene_acceptance=False,B_or_Game_actions=False,candidate_manifest=str(mp),candidate_manifest_sha256=pin(mp))
|
|
(job/'completed1046-numeric-family-check.json').write_text(json.dumps(report,indent=2)+'\n')
|
|
print('PASS1046MD21+4163SKIN numeric links;20130candidate;122held;32769refused;0oldpayloadreads.')
|
|
|
|
if __name__=='__main__':
|
|
p=argparse.ArgumentParser(description=__doc__);p.add_argument('--job',type=Path,required=True);check(p.parse_args().job)
|