97 lines
4.2 KiB
Python
97 lines
4.2 KiB
Python
import hashlib
|
|
import json
|
|
import os
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
import numpy as np
|
|
from PIL import Image
|
|
|
|
sys.path.insert(0, str(Path(__file__).resolve().parents[1]/'ops'))
|
|
import booty_bay_source_water as m
|
|
from content_candidate_rehearsal import rehearse
|
|
|
|
|
|
def main():
|
|
v = os.environ.get('GW_BOOTY_BAY_SOURCE_WATER_ROOT')
|
|
if not v or not Path(v).is_dir():
|
|
print('SKIP: GW_BOOTY_BAY_SOURCE_WATER_ROOT not set (staged artifact lives outside the repo)'); sys.exit(77)
|
|
root = Path(v)
|
|
load = lambda p: json.loads(p.read_text())
|
|
for path, sha in load(root/'input-pins.json').items():
|
|
assert hashlib.sha256(Path(path).read_bytes()).hexdigest() == sha
|
|
source, candidate, wet = {}, {}, {}
|
|
assets = load(root/'candidate-assets.json')
|
|
assert {v['file_data_id'] for v in assets} == {8704453, 204463}
|
|
for row in load(root/'inputs.json'):
|
|
tile = row['x'], row['y']
|
|
src, parent = Path(row['source']).read_bytes(), Path(row['parent']).read_bytes()
|
|
source[tile] = m.rgb512(src)
|
|
try:
|
|
wet[tile] = m.native_water(Path(row['terrain']).read_bytes())
|
|
except StopIteration:
|
|
wet[tile] = np.zeros((512, 512), dtype=bool)
|
|
if tile in m.TARGETS:
|
|
asset = next(v for v in assets if v['file_data_id'] == row['file_data_id'])
|
|
output = Path(asset['file']).read_bytes()
|
|
assert output == m.restore(src, parent)
|
|
m.verify_tile(src, parent, output)
|
|
assert m.digest(Path(asset['file'])) == asset['after_sha256']
|
|
assert m.digest(Path(row['parent'])) == asset['before_sha256']
|
|
for offset in (20, m.opaque_bc1(parent, 512)):
|
|
bad = bytearray(output)
|
|
if offset == 20:
|
|
bad[offset] ^= 1
|
|
else:
|
|
bad[offset:offset+8] = bytes(8)
|
|
try:
|
|
m.verify_tile(src, parent, bytes(bad))
|
|
except ValueError:
|
|
pass
|
|
else:
|
|
raise AssertionError('corrupted tile accepted')
|
|
candidate[tile] = m.bc1_rgb(output)
|
|
else:
|
|
candidate[tile] = m.rgb512(parent)
|
|
assert np.array_equal(candidate[tile], source[tile])
|
|
measured = m.edges(source, candidate, wet)
|
|
report = load(root/'report.json')
|
|
assert measured == report['edges'] and len(measured) == 8
|
|
assert report['tolerance'] == 1e-6 and not report['installed']
|
|
assert report['local_capture_required'] and not report['native_runtime_verified']
|
|
north = next(v for v in measured if v['tile'] == [31, 58] and v['side'] == 'north')
|
|
assert north['water']['result'] == north['geometry_ocean']['result'] == 'N/A'
|
|
bad = dict(candidate)
|
|
bad[30, 58] = bad[30, 58].copy()
|
|
bad[30, 58][:, 0] = 255
|
|
try:
|
|
m.edges(source, bad, wet)
|
|
except ValueError:
|
|
pass
|
|
else:
|
|
raise AssertionError('seam regression accepted')
|
|
canvas = np.asarray(Image.open(root/'candidate-neighbourhood.png').convert('RGB'))
|
|
for (x, y), pixels in candidate.items():
|
|
assert np.array_equal(canvas[(y-57)*512:(y-56)*512, (x-29)*512:(x-28)*512], pixels)
|
|
core = load(root/'content-step/candidate/core.json')
|
|
assert core['complete_root_inverse']
|
|
assert {v['file_data_id'] for v in core['assets']} == {8704453, 204463}
|
|
assert len(core['components']) == 2 and all(v['type'] == 'root_selector' for v in core['components'])
|
|
frozen = Path(load(root/'current-content-parent-path.json')[0])
|
|
assert m.digest(frozen/'.build.info.candidate') == report['parent_build_info_sha256']
|
|
before = (frozen/'decoded/root.bin').read_bytes()
|
|
expected = before
|
|
for fdid in (8704453, 204463):
|
|
component = load(root/f'content-step/{fdid}.json')
|
|
old = bytes.fromhex(component['original_decoded']['md5'])
|
|
new = bytes.fromhex(component['after_decoded']['md5'])
|
|
assert expected.count(old) == 1
|
|
expected = expected.replace(old, new)
|
|
assert expected == (root/'content-step/candidate/decoded/root.bin').read_bytes()
|
|
rehearse(root)
|
|
print('Two exact Source BC1 tiles, parent headers, eight edge gates, PNG and physical inverse PASS')
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|