Files
WoW-Hybrid-gateway/tests/tirisfal_changed_minimaps_test.py

51 lines
3.9 KiB
Python

#!/usr/bin/env python3
import hashlib,json,os,sys
from pathlib import Path
from functools import lru_cache
from PIL import Image
ROOT=Path(__file__).resolve().parents[1];sys.path.insert(0,str(ROOT/'ops'))
from octo_parity.turtle_changed import classify
from minimap_neighbor_stage import tile,logical
from minimap_seam_audit import edge_difference
from content_candidate_rehearsal import rehearse
class Archive:
def __init__(self,raw):self.raw=raw
def find(self,path):return path if self.raw is not None else None
def read(self,path):return self.raw
assert classify('tile',[('patch-4.mpq',Archive(b'a')),('patch.MPQ',Archive(b'a'))])['status']=='same'
assert classify('tile',[('patch-4.mpq',Archive(b'b')),('patch.MPQ',Archive(b'a'))])['status']=='turtle-changed'
assert classify('tile',[('patch-4.mpq',Archive(b'b')),('patch.MPQ',Archive(None))])['status']=='turtle-new'
assert classify('tile',[('patch.MPQ',Archive(b'a'))])['status']=='same'
if os.environ.get('GW_TIRISFAL_CHANGED_ROOT'):
root=Path(os.environ['GW_TIRISFAL_CHANGED_ROOT']);load=lambda path:json.loads(path.read_text());digest=lambda path:hashlib.sha256(path.read_bytes()).hexdigest()
decisions=load(root/'eligibility.json');rows=load(root/'candidate-assets.json');selected={tile(r['path']):r for r in rows};seed=load(root.parent/'tirisfal-geometry-25/candidate-assets.json');seed_tiles={tile(r['path']) for r in seed}
assert len(seed_tiles)==45 and seed_tiles<=selected.keys()
for decision in decisions:
arch=[]
for key in ['turtle_proof','base_proof']:
proof=decision[key]
if proof:
raw=Path(proof['file']).read_bytes();assert hashlib.sha256(raw).hexdigest()==proof['sha256'];arch.append((proof['archive'],Archive(raw)))
assert classify(decision['path'],arch)['status']==decision['status']
assert (tuple(decision['tile']) in selected)==(decision['seed'] or decision['status'] in ('turtle-changed','turtle-new'))
for original in seed:assert selected[tile(original['path'])]['after_sha256']==original['after_sha256']
for row in rows:
assert digest(Path(row['file']))==row['after_sha256'] and digest(root/'native-minimaps'/row['path'])==row['before_sha256'] and digest(Path(row['source_file']))==row['source_sha256']
@lru_cache(maxsize=128)
def image(path):
im=Image.open(path);im.load();return im.convert('RGB')
boundaries=load(root/'boundaries.json');pairs=set()
for boundary in boundaries:
left,right=tuple(boundary['a']),tuple(boundary['b']);assert (left in selected)!=(right in selected);assert (left,right) not in pairs;pairs.add((left,right))
lp=Path(selected[left]['file']) if left in selected else root/'native-minimaps'/logical(left);rp=Path(selected[right]['file']) if right in selected else root/'native-minimaps'/logical(right)
if not lp.exists() or not rp.exists():assert boundary['delta'] is None
else:assert abs(edge_difference(image(lp),image(rp),boundary['axis'])['mean_rgb_delta']-boundary['delta'])<1e-9
report=load(root/'report.json');scope=load(root/'scope.json');assert not scope['recursive_rings'] and len(scope['fixed_neighbour_scope'])==99
assert report['candidate_tiles']==len(rows) and report['retained_native_boundaries']==len(boundaries) and not report['numeric_seam_gate'] and report['source_internal_seams_accepted']
assert not report['geometry_changed'] and not report['installed'] and report['publication']=='HOLD'
core=load(root/'content-step/candidate/core.json');assert core['complete_root_inverse'] and {r['file_data_id'] for r in core['assets']}=={r['file_data_id'] for r in rows}
assert all(c['type']=='root_selector' for c in core['components'])
assert not list(root.rglob('*.adt')) and not list(root.rglob('*.wmo'))
rehearse(root)
print('PASS Turtle-changed eligibility, unchanged seeds, native-boundary list, image-only ROOT delta and physical forward/inverse rehearsal')