Files
WoW-Hybrid-gateway/tests/m2_constant_bracket_family_test.py
praxisandClaude Fable 5.2 7f2139d8d0 Offline test fixtures
883 files, from working commit b1a079a.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-19 01:32:48 +02:00

102 lines
6.3 KiB
Python

#!/usr/bin/env python3
"""Only the newly proved constant-bracket failures; no completed model replay."""
import argparse
import bisect
import collections
import hashlib
import json
from pathlib import Path
import struct
import sys
from unittest.mock import patch
sys.path.insert(0,str(Path(__file__).resolve().parents[1]/'ops'))
import m2_equipment_convert as converter
from m2_track_convert import convert_track
from m2_track_convert_test import source,decoded
def check(job):
partition=json.loads((job/'complete23-constant-bracket-candidate-partition.json').read_text())
eligible=[r for r in partition['records']if r['eligible']]
assert len(partition['records'])==23 and len(eligible)==14
output=job/'model14-private-constant-bracket-conversion';output.mkdir(exist_ok=False)
original=converter.convert_track;observed=[];records=[]
def checked(raw,at,kind,windows,out,**kw):
header,audit=original(raw,at,kind,windows,out,**kw)
if audit.get('constant_bracket_sequences'):
interpolation,glob,nr,ro,nt,to,nk,ko=struct.unpack_from('<Hh6I',raw,at)
times=struct.unpack_from('<'+'I'*nt,raw,to);stride=12 if kind=='vec3'else 16
source_keys=[raw[ko+i*stride:ko+(i+1)*stride]for i in range(nk)]
ts,keys=decoded(out,header,12 if kind=='vec3'else 8)
for row in audit['constant_bracket_sequences']:
seq=row['animation'];begin,end=row['source_inclusive_range'];start,finish=row['source_window']
assert ts[seq]==bytes(4)
expected=struct.unpack('<'+'f'*(stride//4),source_keys[begin])
if kind=='vec3':assert keys[seq]==source_keys[begin]
else:
encoded=struct.unpack('<4h',keys[seq]);actual=[(v+32768)/32767 if v<0 else(v-32767)/32767 for v in encoded]
assert max(abs(a-b)for a,b in zip(expected,actual))<=1/32767
# Original FindKey's bracket selection and the observed
# component interpolation are evaluated at both endpoints
# and the interior, including a different global next key
# with exact0 fraction at the final endpoint.
for time in(start,(start+finish)/2,finish):
left=begin+bisect.bisect_right(times[begin:end+1],time)-1
right=min(left+1,nt-1)
factor=0 if left==right else(time-times[left])/(times[right]-times[left])
a=struct.unpack('<'+'f'*(stride//4),source_keys[left]);b=struct.unpack('<'+'f'*(stride//4),source_keys[right])
sample=a if interpolation==0 else tuple(x+(y-x)*factor for x,y in zip(a,b))
assert sample==expected
observed.append(dict(kind=kind,source_track_offset=at,**row))
return header,audit
with patch.object(converter,'convert_track',checked):
for row in eligible:
payload=row['Source_payload'];raw=Path(payload['file']).read_bytes()
assert hashlib.sha256(raw).hexdigest()==payload['sha256'];before=len(observed)
record=dict(Source_member=row['Source_member'],source_sha256=payload['sha256'])
try:body,skins,report=converter.convert_equipment(raw)
except ValueError as error:record.update(structural_conversion_complete=False,blocked=str(error))
else:
directory=output/payload['sha256'];directory.mkdir();files=[]
for name,data in [('model.m2',body)]+[(f'view{i}.skin',s)for i,s in enumerate(skins)]:
p=directory/name;p.write_bytes(data);files.append(dict(file=str(p.relative_to(output)),bytes=len(data),sha256=hashlib.sha256(data).hexdigest()))
record.update(structural_conversion_complete=True,outputs=files,report=report)
assert len(observed)>before;record['constant_brackets_checked']=observed[before:];records.append(record)
# Keep changing, uncovered, repeated-time and unsafe-right-guard cases held.
controls=[source([0,20],[(0,0,0),(1,0,0)],[(0,1)]),
source([0,20],[(1,2,3)]*2,[(0,1)]),
source([0,20,20],[(1,2,3)]*3,[(0,1)]),
source([0,0,20],[(1,2,3)]*3,[(0,2)])]
windows=[[(5,10)],[(25,30)],[(5,20)],[(5,10)]]
refusals=[]
for index,(raw,window)in enumerate(zip(controls,windows)):
target=bytearray(304)
try:convert_track(raw,324,'vec3',window,target)
except ValueError as error:refusals.append(dict(control=index,reason=str(error)))
else:raise AssertionError('Unproved timestamp control accepted')
assert target==bytearray(304)
guarded=source([0,20,30],[(1,2,3),(1,2,3),(8,9,10)],[(0,1)])
target=bytearray(304);header,audit=convert_track(guarded,324,'vec3',[(5,20)],target)
assert decoded(target,header,12)==([bytes(4)],[struct.pack('<3f',1,2,3)])
result=dict(status='PASS_ACTUAL14_CONSTANT_BRACKET_SOURCE_AND_NATIVE_STORAGE_BOUNDARY',
scope=14,complete_timestamp_partition=23,unaffected_timestamp_hold_models=9,
converted_bodies=sum(r['structural_conversion_complete']for r in records),
blocked_bodies=sum(not r['structural_conversion_complete']for r in records),
remaining_reasons=dict(collections.Counter(r['blocked']for r in records if not r['structural_conversion_complete'])),
actual_constant_brackets=len(observed),records=records,refusal_controls=refusals,
old786_models_reconverted=False,values_resampled=False,source_keys_clipped=False,
global_model_flags_modified=False,Native_original_model_reuses=0,
Source_exports_or_Native_body_reads=0,installed=False,engine_loaded=False,
converter_sha256=hashlib.sha256((Path(__file__).resolve().parents[1]/'ops/m2_equipment_convert.py').read_bytes()).hexdigest(),
track_converter_sha256=hashlib.sha256((Path(__file__).resolve().parents[1]/'ops/m2_track_convert.py').read_bytes()).hexdigest())
(output/'manifest.json').write_text(json.dumps(result,indent=2)+'\n')
(job/'constant-bracket14-focused-check.json').write_text(json.dumps({k:v for k,v in result.items()if k!='records'},indent=2)+'\n')
return result
if __name__=='__main__':
parser=argparse.ArgumentParser(description=__doc__);parser.add_argument('--job',type=Path,required=True)
args=parser.parse_args();check(args.job)
print('PASS:actual14 constant brackets/source endpoints;4refusals;old786 untouched.')