883 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
175 lines
10 KiB
Python
175 lines
10 KiB
Python
"""Changed-artifact boundary for the private, unpublishable used-tile candidate."""
|
|
import hashlib
|
|
import json
|
|
from pathlib import Path
|
|
import struct
|
|
import sys
|
|
|
|
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / 'ops'))
|
|
from map_asset_preflight import adt_height_profile, adt_near_terrain_candidate
|
|
|
|
|
|
def check(plan_path, output_dir):
|
|
plan = json.loads(Path(plan_path).read_text())
|
|
out = Path(output_dir)
|
|
out.mkdir(parents=True, exist_ok=True, mode=0o700)
|
|
native = Path(plan['inputs']['native_root']).read_bytes()
|
|
source = Path(plan['inputs']['source_existing_body']).read_bytes()
|
|
candidate, receipt = adt_near_terrain_candidate(native, source, (40, 29),
|
|
map_id=1, native_file_data_id=786640)
|
|
assert len(candidate) == len(native)
|
|
allowed = bytearray(len(native))
|
|
kinds = {}
|
|
tails = 0
|
|
for span in receipt['allowed_spans']:
|
|
n, s, length = span['native_offset'], span['source_offset'], span['bytes']
|
|
assert not any(allowed[n:n+length]), 'overlapping output spans'
|
|
allowed[n:n+length] = b'\x01' * length
|
|
assert candidate[n:n+length] == source[s:s+length]
|
|
kinds[span['kind']] = kinds.get(span['kind'], 0) + 1
|
|
if span['kind'] == 'existing_MCNR':
|
|
assert struct.unpack_from('<I', candidate, n-4)[0] == 448
|
|
assert candidate[n+435:n+448] == native[n+435:n+448]
|
|
tails += 1
|
|
assert kinds == {'baseZ': 256, 'MCVT': 256, 'existing_MCNR': 256}
|
|
changed = sum(a != b for a, b in zip(native, candidate))
|
|
assert changed > 0
|
|
assert all(a == b or allowed[i] for i, (a, b) in enumerate(zip(native, candidate)))
|
|
decoded = adt_height_profile(candidate, (40, 29))
|
|
expected = adt_height_profile(source, (40, 29))
|
|
assert decoded['V9'] == expected['V9'] and decoded['V8'] == expected['V8']
|
|
assert all(decoded['cells'][xy]['base_height'] == expected['cells'][xy]['base_height']
|
|
for xy in decoded['cells'])
|
|
# Mutate actual source context, not simulated expected writer output.
|
|
base = next(s for s in receipt['allowed_spans'] if s['kind'] == 'baseZ')['source_offset'] - 112
|
|
bad_holes = bytearray(source)
|
|
flags = struct.unpack_from('<I', source, base)[0]
|
|
hole_offset = base + (20 if flags & 0x10000 else 60)
|
|
bad_holes[hole_offset] ^= 1
|
|
bad_world = bytearray(source)
|
|
struct.pack_into('<f', bad_world, base+104,
|
|
struct.unpack_from('<f', source, base+104)[0] + 100)
|
|
bad_nonfinite_world = bytearray(source)
|
|
struct.pack_into('<f', bad_nonfinite_world, base+104, float('nan'))
|
|
normal = next(s for s in receipt['allowed_spans'] if s['kind'] == 'existing_MCNR')['source_offset']
|
|
bad_shape = bytearray(source)
|
|
struct.pack_into('<I', bad_shape, normal-4, 434)
|
|
refusals = []
|
|
for label, raw, binding in [
|
|
('different_holes', bad_holes, 786640),
|
|
('different_world_basis', bad_world, 786640),
|
|
('nonfinite_world_basis', bad_nonfinite_world, 786640),
|
|
('different_normal_shape', bad_shape, 786640),
|
|
('unreviewed_binding', source, 786641),
|
|
]:
|
|
try:
|
|
adt_near_terrain_candidate(native, raw, (40, 29),
|
|
map_id=1, native_file_data_id=binding)
|
|
except ValueError:
|
|
refusals.append(label)
|
|
else:
|
|
raise AssertionError('unsafe context accepted: ' + label)
|
|
target = out / 'kalimdor_40_29.private-near-terrain.adt'
|
|
with target.open('xb') as f:
|
|
f.write(candidate)
|
|
target.chmod(0o600)
|
|
receipt.update(status='PASS_PRIVATE_CHANGED_ARTIFACT_ONLY',
|
|
output=str(target), output_sha256=hashlib.sha256(candidate).hexdigest(),
|
|
output_bytes=len(candidate), actual_changed_bytes=changed,
|
|
allowed_span_bytes=sum(allowed), unchanged_outside_allowed_spans=True,
|
|
source_existing_values_preserved=True, source_absolute_V9_V8_preserved=True,
|
|
native_normal_tails_preserved=tails, refusal_cases=refusals,
|
|
old_grounding_or_consumer_checks_repeated=False,
|
|
accepted_inputs=plan['inputs'])
|
|
r = out / 'focused-check.json'
|
|
r.write_text(json.dumps(receipt, indent=2) + '\n')
|
|
r.chmod(0o600)
|
|
print('PASS: private terrain spans, native preservation, and five context refusals')
|
|
|
|
|
|
def check_geometry_family(job):
|
|
import copy,pickle
|
|
from map_asset_preflight import adt_terrain_family_diagnostics,adt_lod_geometry_profile
|
|
job=Path(job);old=pickle.loads((job/'retained-three-tile-geometry-profiles.pkl').read_bytes())
|
|
source={};native={};raws={};changed_parser_cases=0
|
|
for (role,tile),cached in old.items():
|
|
raw=Path(cached['source_file']).read_bytes();raws[role,tile]=raw
|
|
parsed=adt_height_profile(raw,tile,include_normals=True)
|
|
# Reuse the owning accepted height arrays as immutable expected inputs;
|
|
# no original sampler/axis/export validation is repeated.
|
|
assert parsed['V9']==cached['V9'] and parsed['V8']==cached['V8']
|
|
assert len(parsed['N9'])==16641 and len(parsed['N8'])==16384
|
|
(source if role=='source'else native)[tile]=parsed;changed_parser_cases+=1
|
|
real=adt_terrain_family_diagnostics(source,native)
|
|
assert real['tiles']==3 and len(real['shared_seams'])==2 and len(real['outer_boundaries'])==8
|
|
baseline=adt_terrain_family_diagnostics(native,native)
|
|
assert not baseline['required_neighbor_tiles'] and baseline['preserved_native_outer_boundaries']==8
|
|
tile=(40,29);neighbor=[41,29];edge_index=64*129+128
|
|
for label,mutate in [
|
|
('height',lambda p:p['V9'].__setitem__(edge_index,p['V9'][edge_index]+2)),
|
|
('normal',lambda p:p['N9'].__setitem__(edge_index,(127,126,125))),
|
|
('hole',lambda p:p['cells'][(15,8)].update(holes=p['cells'][(15,8)]['holes']^(1<<7))),
|
|
]:
|
|
changed=copy.deepcopy(native);mutate(changed[tile])
|
|
result=adt_terrain_family_diagnostics(changed,native)
|
|
assert result['required_neighbor_tiles']==[neighbor],(label,result['required_neighbor_tiles'])
|
|
# A changed shared edge must remain visible as a mismatch; do not silently
|
|
# accept the second tile merely because both bodies are available.
|
|
changed=copy.deepcopy(native);changed[(39,29)]['V9'][64*129+128]+=2
|
|
pair=next(r for r in adt_terrain_family_diagnostics(changed,native)['shared_seams']if r['second']==[40,29])
|
|
assert pair['source']['height_vertices_different']>pair['native_baseline']['height_vertices_different']
|
|
for src,dst,present in [({tile:native[tile]},native,None),(native,native,{(0,0)}),({(64,29):native[tile]},{(64,29):native[tile]},None)]:
|
|
try:adt_terrain_family_diagnostics(src,dst,known_present_tiles=present)
|
|
except ValueError:pass
|
|
else:raise AssertionError('Unproved family/WDT scope admitted')
|
|
# The shared child reader changed; check only the new refactor dependency
|
|
# against the already accepted candidate digest, not its old whole suite.
|
|
candidate,_=adt_near_terrain_candidate(raws['native',tile],raws['source',tile],tile,map_id=1,native_file_data_id=786640)
|
|
assert hashlib.sha256(candidate).hexdigest()=='77a8297fc8cae28f76507c27586b8014e0a3c41a0d9c74bb4c4a58695511b196'
|
|
bodies=json.loads((job/'new-three-companion-native-read-receipt.json').read_text())
|
|
lod_row=next(r for r in bodies['rows']if r['MAID_role']=='lodADT');lod_raw=Path(lod_row['file']).read_bytes()
|
|
lod=adt_lod_geometry_profile(lod_raw,near_profile=native[tile])
|
|
assert lod['vertex_count']==33180 and lod['regular_vertex_count']==33025
|
|
assert lod['index_count']==103128 and len(lod['levels'])==4 and len(lod['skirt_source_indices'])==155
|
|
assert lod['near_height_comparison']['V9']['bit_differences']==3272
|
|
assert lod['near_height_comparison']['V9']['max_absolute_difference']>3.9
|
|
assert lod['near_height_comparison']['V8']['max_absolute_difference']<0.00001
|
|
assert not lod['generation_safe'] and not lod['normal_map_generation_proven']
|
|
chunks={r['tag']:r for r in lod_row['chunks']}
|
|
invalid_index=bytearray(lod_raw);struct.pack_into('<H',invalid_index,chunks['MLVI']['offset']+8,65535)
|
|
invalid_partition=bytearray(lod_raw);struct.pack_into('<I',invalid_partition,chunks['MLLL']['offset']+8+4,1)
|
|
invalid_version=bytearray(lod_raw);struct.pack_into('<I',invalid_version,8,17)
|
|
for bad in (invalid_index,invalid_partition,invalid_version,lod_raw[:-1]):
|
|
try:adt_lod_geometry_profile(bytes(bad))
|
|
except ValueError:pass
|
|
else:raise AssertionError('Malformed/unreviewed LOD relationship admitted')
|
|
# Existing BLP decoder verifies the two new native companions; their
|
|
# directional/channel/baking roles are expressly not inferred here.
|
|
from octo_icon_assets import decode_blp
|
|
textures=[]
|
|
for row in bodies['rows']:
|
|
if row['MAID_role']not in('mapTexture','mapTextureN'):continue
|
|
decoded=decode_blp(Path(row['file']).read_bytes());textures.append(dict(role=row['MAID_role'],**decoded))
|
|
report=dict(status='PASS_CHANGED_TERRAIN_NORMAL_SEAM_AND_LOD_DIAGNOSTIC_FAMILY',source_tiles=3,native_tiles=3,
|
|
new_normal_grid_profiles=changed_parser_cases,shared_seam_pairs=2,outer_boundaries=8,
|
|
unchanged_native_boundary_reuses=8,changed_height_normal_and_hole_neighbor_detection=3,
|
|
source_shared_seam_difference_retained=True,wrong_family_WDT_cases_refused=3,malformed_LOD_cases_refused=4,
|
|
LOD_vertices=33180,LOD_indices=103128,LOD_levels=4,LOD_first_float_skirt_matches=lod['observed_first_level_float_skirt_matches'],
|
|
optimized_LOD_V9_differences=3272,naive_near_to_LOD_copy_not_admitted=True,new_native_BLPS_decoded=textures,
|
|
shared_child_refactor_existing_candidate_digest_unchanged=True,original_height_axis_tail_SDK_checks_repeated=False,
|
|
source_exports_or_scans=0,published=False,native_runtime_acceptance=False)
|
|
(job/'retained-family-edge-diagnostic.json').write_text(json.dumps(real,indent=2)+'\n')
|
|
with(job/'validated-terrain-normal-profiles.pkl').open('wb')as stream:pickle.dump(dict(source=source,native=native),stream)
|
|
# Save the useful scalar/relationship output, not another full byte export.
|
|
summary={k:v for k,v in lod.items()if k not in('heights','skirt_source_indices')}
|
|
(job/'validated-first-LOD-geometry-profile.json').write_text(json.dumps(summary,indent=2)+'\n')
|
|
(job/'completed-geometry-family-focused-check.json').write_text(json.dumps(report,indent=2)+'\n')
|
|
print('PASS: six normal grids/two seams/family neighbor guards; original LOD and two textures diagnosed without publication.')
|
|
|
|
|
|
if __name__ == '__main__':
|
|
if sys.argv[1] == '--geometry-family':
|
|
check_geometry_family(sys.argv[2])
|
|
else:
|
|
check(sys.argv[1], sys.argv[2])
|