Fix HD atlas sampling and protected terrain joins
Add rational atlas cells and bounded authenticated Original-detail retention with standalone synthetic regression checks. Rebuild Linux and Windows runtimes; validate all 5384 supplied frames and preserve three exact 1080p regression controls.
This commit is contained in:
1 parent
ef8a649e03
commit
a073f73f3a
14 files changed
+1086
-40
No files matched your search
@@ -0,0 +1,62 @@
|
||||
"""Synthetic-only scalar model of the proposed opt-in kernel; no game/art IO."""
|
||||
import math
|
||||
import struct
|
||||
|
||||
def f32(value):
|
||||
return struct.unpack('<f', struct.pack('<f', value))[0]
|
||||
|
||||
def lanczos(value):
|
||||
if value == 0:
|
||||
return 1.0
|
||||
if abs(value) >= 3:
|
||||
return 0.0
|
||||
value *= math.pi
|
||||
return math.sin(value) / value * (math.sin(value / 3) / (value / 3))
|
||||
|
||||
def axis_weights(start, end, output):
|
||||
start, end = float(start), float(end)
|
||||
scale = max((end - start) / output, 1.0)
|
||||
rows = []
|
||||
for destination in range(output):
|
||||
center = start + (destination + 0.5) * (end - start) / output
|
||||
lower = max(math.floor(center - 3 * scale), math.floor(start))
|
||||
upper = min(math.ceil(center + 3 * scale), math.ceil(end))
|
||||
weights = []
|
||||
for index in range(lower, upper):
|
||||
overlap = max(0.0, min(index + 1, end) - max(index, start))
|
||||
weight = lanczos((index + 0.5 - center) / scale) * overlap
|
||||
if weight:
|
||||
weights.append((index, weight))
|
||||
total = sum(value for _, value in weights)
|
||||
if not math.isfinite(total) or abs(total) <= 1e-12:
|
||||
raise ValueError('invalid rational atlas filter weights')
|
||||
rows.append([(index, f32(value / total)) for index, value in weights])
|
||||
return rows
|
||||
|
||||
def sample_fractional(pixels, geometry):
|
||||
left, top, right, bottom = geometry['bounds']
|
||||
width, height = geometry['resident']
|
||||
_, first_y, _, last_y = geometry['pixels']
|
||||
x_weights = axis_weights(left, right, width)
|
||||
y_weights = axis_weights(top, bottom, height)
|
||||
horizontal = []
|
||||
for source_y in range(first_y, last_y):
|
||||
row = []
|
||||
for weights in x_weights:
|
||||
sample = [0.0] * 4
|
||||
for source_x, weight in weights:
|
||||
for channel in range(4):
|
||||
sample[channel] = f32(sample[channel] + f32(pixels[source_y][source_x][channel] * weight))
|
||||
row.append(sample)
|
||||
horizontal.append(row)
|
||||
result = []
|
||||
for weights in y_weights:
|
||||
row = []
|
||||
for x in range(width):
|
||||
sample = [0.0] * 4
|
||||
for source_y, weight in weights:
|
||||
for channel in range(4):
|
||||
sample[channel] = f32(sample[channel] + f32(horizontal[source_y - first_y][x][channel] * weight))
|
||||
row.append(tuple(math.floor(min(255, max(0, value)) + 0.5) for value in sample))
|
||||
result.append(row)
|
||||
return result
|
||||
@@ -0,0 +1,177 @@
|
||||
import copy
|
||||
from fractions import Fraction
|
||||
import hashlib
|
||||
import importlib.util
|
||||
import json
|
||||
from pathlib import Path
|
||||
import struct
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
from PIL import Image
|
||||
|
||||
PROJECT = Path(__file__).resolve().parents[1]
|
||||
Q = Path(__file__).resolve().parent
|
||||
sys.path.insert(0, str(PROJECT / 'tools'))
|
||||
import hd_frame_policy as policy
|
||||
import hd_art_audit as audit
|
||||
import hd_candidate_review as candidate
|
||||
import hd_register_reviewed as registration
|
||||
from grid_sampler_reference import axis_weights, sample_fractional
|
||||
|
||||
def frame(columns=2, rows=2, column=0, row=0, size=(1, 1)):
|
||||
return dict(frame=0, file='synthetic.png', logical_width=size[0], logical_height=size[1],
|
||||
origin=[0, 0], source_sha256='0' * 64,
|
||||
atlas_grid=dict(columns=columns, rows=rows, column=column, row=row))
|
||||
|
||||
class Geometry(unittest.TestCase):
|
||||
def test_exact_fractional_extents(self):
|
||||
item = frame(4, 2, 3, 1, (32, 32))
|
||||
result = policy.atlas_grid_geometry(item, 1774, 887)
|
||||
self.assertEqual(result['bounds'], (Fraction(2661, 2), Fraction(887, 2), Fraction(1774), Fraction(887)))
|
||||
self.assertEqual(result['pixels'], (1330, 443, 1774, 887))
|
||||
self.assertEqual(result['resident'], (128, 128))
|
||||
|
||||
def test_no_strip_gaps_or_omissions(self):
|
||||
for count in range(1, 17):
|
||||
extent = count * 5 + 1
|
||||
spans = [policy.atlas_grid_geometry(frame(count, count, cell, 0), extent, extent)['bounds'] for cell in range(count)]
|
||||
self.assertEqual(spans[0][0], 0)
|
||||
self.assertEqual(spans[-1][2], extent)
|
||||
self.assertTrue(all(left[2] == right[0] for left, right in zip(spans, spans[1:])))
|
||||
self.assertTrue(all(span[2] - span[0] == Fraction(extent, count) for span in spans))
|
||||
|
||||
def test_last_cell_bounds_never_exceed_atlas(self):
|
||||
for cols, rows, width, height in [(2, 2, 5, 5), (4, 2, 1774, 887), (7, 7, 31, 31), (1, 1, 9, 9)]:
|
||||
g = policy.atlas_grid_geometry(frame(cols, rows, cols-1, rows-1), width, height)
|
||||
self.assertEqual(g['pixels'][2:], (width, height))
|
||||
for output in [1, 2, 4, 16]:
|
||||
for weights in axis_weights(g['bounds'][0], g['bounds'][2], output):
|
||||
self.assertTrue(all(g['pixels'][0] <= index < width for index, _ in weights))
|
||||
|
||||
def test_resolution_is_common_bounded_factor(self):
|
||||
self.assertEqual(policy.atlas_grid_geometry(frame(), 5, 5)['resident'], (2, 2))
|
||||
self.assertEqual(policy.atlas_grid_geometry(frame(), 7, 7)['resident'], (3, 3))
|
||||
self.assertEqual(policy.atlas_grid_geometry(frame(), 13, 13)['resident'], (4, 4))
|
||||
|
||||
def test_non_square_logical_aspect(self):
|
||||
self.assertEqual(policy.atlas_grid_geometry(frame(2, 2, size=(2, 1)), 10, 5)['resident'], (4, 2))
|
||||
|
||||
def test_odd_grid_size_does_not_mutate_frame(self):
|
||||
item = frame(4, 2, 1, 0, (32, 32)); old = copy.deepcopy(item)
|
||||
policy.atlas_grid_geometry(item, 1774, 887)
|
||||
self.assertEqual(item, old)
|
||||
|
||||
def test_grid_and_crop_are_mutually_exclusive(self):
|
||||
item = frame(); item['crop'] = [0, 0, 2, 2]
|
||||
with self.assertRaises(ValueError): policy.validate_frame_policy(item)
|
||||
|
||||
def test_absent_grid_is_noop_and_adds_no_default_key(self):
|
||||
item = frame(); item.pop('atlas_grid'); old = copy.deepcopy(item)
|
||||
policy.validate_frame_policy(item)
|
||||
self.assertIsNone(policy.atlas_grid_geometry(item, 5, 4))
|
||||
self.assertEqual(item, old)
|
||||
self.assertNotIn('atlas_grid', item)
|
||||
|
||||
def test_null_grid_is_noop_without_adding_or_removing_keys(self):
|
||||
item = frame(); item['atlas_grid'] = None; old = copy.deepcopy(item)
|
||||
self.assertIsNone(policy.validate_atlas_grid(item)); self.assertEqual(item, old)
|
||||
|
||||
def test_invalid_typed_grid_fields(self):
|
||||
for field, value in [('columns', 0), ('rows', 0), ('columns', -1), ('rows', 2**32),
|
||||
('column', True), ('row', 0.0), ('columns', '2'), ('column', 2), ('row', 2)]:
|
||||
with self.subTest(field=field, value=value):
|
||||
item = frame(); item['atlas_grid'][field] = value
|
||||
with self.assertRaises(ValueError): policy.validate_frame_policy(item)
|
||||
|
||||
def test_grid_cell_budget_and_unknown_fields(self):
|
||||
for grid in [{}, [], 7, dict(columns=129, rows=129, column=0, row=0),
|
||||
dict(columns=2, rows=2, column=0, row=0, extra=1)]:
|
||||
item = frame(); item['atlas_grid'] = grid
|
||||
with self.assertRaises(ValueError): policy.validate_frame_policy(item)
|
||||
|
||||
def test_bad_aspect_resolution_and_dimensions(self):
|
||||
for size in [(5, 6), (3, 3), (0, 5), (5, 0), (-1, 5), (True, 5)]:
|
||||
with self.subTest(size=size):
|
||||
with self.assertRaises(ValueError): policy.atlas_grid_geometry(frame(), *size)
|
||||
|
||||
class Sampler(unittest.TestCase):
|
||||
def test_constant_rgba_preserved(self):
|
||||
g = policy.atlas_grid_geometry(frame(), 5, 5)
|
||||
pixels = [[(40, 80, 120, 255)] * 5 for _ in range(5)]
|
||||
self.assertEqual(sample_fractional(pixels, g), [[(40, 80, 120, 255)] * 2 for _ in range(2)])
|
||||
|
||||
def test_half_boundary_pixel_participates_on_both_sides(self):
|
||||
for start, end in [(Fraction(0), Fraction(5, 2)), (Fraction(5, 2), Fraction(5))]:
|
||||
weights = axis_weights(start, end, 2)
|
||||
self.assertTrue(any(index == 2 and weight != 0 for row in weights for index, weight in row))
|
||||
|
||||
def test_no_neighbor_pixel_bleed(self):
|
||||
pixels = [[(255, 0, 0, 255), (255, 0, 0, 255), (0, 255, 0, 255), (0, 0, 255, 255), (0, 0, 255, 255)] for _ in range(5)]
|
||||
left = sample_fractional(pixels, policy.atlas_grid_geometry(frame(), 5, 5))
|
||||
right = sample_fractional(pixels, policy.atlas_grid_geometry(frame(column=1), 5, 5))
|
||||
self.assertTrue(all(pixel[2] == 0 for row in left for pixel in row))
|
||||
self.assertTrue(all(pixel[0] == 0 for row in right for pixel in row))
|
||||
|
||||
def test_alpha_is_sampled_as_raw_channel(self):
|
||||
pixels = [[(0, 0, 0, 1)] * 5 for _ in range(5)]
|
||||
self.assertTrue(all(pixel[3] == 1 for row in sample_fractional(pixels, policy.atlas_grid_geometry(frame(), 5, 5)) for pixel in row))
|
||||
|
||||
def test_weight_normalization(self):
|
||||
for extent, output in [(Fraction(5, 2), 2), (Fraction(887, 2), 128), (Fraction(31, 7), 4)]:
|
||||
for weights in axis_weights(0, extent, output):
|
||||
self.assertAlmostEqual(sum(value for _, value in weights), 1, places=6)
|
||||
|
||||
class Consumers(unittest.TestCase):
|
||||
def test_candidate_retains_grid_and_source_identity(self):
|
||||
item = frame(); proposal = dict(sequences=[dict(name='Synthetic', base_asset=1, frame_count=1, frames=[item])])
|
||||
rows = candidate.proposal_frames(proposal)
|
||||
self.assertEqual(rows['00001']['atlas_grid'], item['atlas_grid'])
|
||||
changed = copy.deepcopy(rows); changed['00001']['atlas_grid']['column'] = 1
|
||||
self.assertNotEqual(candidate.binding_digest(rows), candidate.binding_digest(changed))
|
||||
self.assertEqual(candidate.binding_digest(rows), candidate.binding_digest(candidate.proposal_frames(proposal)))
|
||||
|
||||
def test_registration_typed_identity_cannot_ignore_grid_changes(self):
|
||||
original = frame()
|
||||
changed = copy.deepcopy(original); changed['atlas_grid']['row'] = 1
|
||||
self.assertFalse(registration.same_json(original, changed))
|
||||
changed = copy.deepcopy(original); changed['atlas_grid']['row'] = False
|
||||
self.assertFalse(registration.same_json(original, changed))
|
||||
self.assertTrue(registration.same_json(original, copy.deepcopy(original)))
|
||||
|
||||
def test_grid_policy_does_not_silently_drop_unknown_metadata(self):
|
||||
original = frame(); original['atlas_grid']['automatic_fit'] = True
|
||||
with self.assertRaises(ValueError): policy.validate_frame_policy(original)
|
||||
original = frame(); original['crop'] = [0, 0, 2, 2]
|
||||
with self.assertRaises(ValueError): candidate.proposal_frames(dict(sequences=[
|
||||
dict(name='Synthetic', base_asset=1, frame_count=1, frames=[original])]))
|
||||
|
||||
def test_candidate_targets_must_bind_same_grid(self):
|
||||
item = frame(); target = copy.deepcopy(item); target['asset'] = '00001'; target['atlas_grid']['column'] = 1
|
||||
proposal = dict(targets=[target], sequences=[dict(name='Synthetic', base_asset=1, frame_count=1, frames=[item])])
|
||||
with self.assertRaises(ValueError): candidate.proposal_frames(proposal)
|
||||
|
||||
def test_audit_rejects_bad_grid_and_accepts_fractional_without_modifying_png(self):
|
||||
payload = struct.pack('<5i', 1, 0, 0, 1, 1) + b'\x01'
|
||||
picture = Image.new('RGBA', (1, 1), (1, 1, 1, 255))
|
||||
with tempfile.TemporaryDirectory(prefix='synthetic-', dir=Q) as directory:
|
||||
root = Path(directory); path = root / 'synthetic.png'
|
||||
Image.new('RGBA', (5, 5), (30, 50, 70, 255)).save(path)
|
||||
previous = path.read_bytes(); item = frame(); item['source_sha256'] = hashlib.sha256(payload).hexdigest()
|
||||
self.assertEqual(audit.validate_hd_frame(root, item, payload, picture), 16)
|
||||
self.assertEqual(path.read_bytes(), previous)
|
||||
item['crop'] = [0, 0, 2, 2]
|
||||
with self.assertRaises(ValueError): audit.validate_hd_frame(root, item, payload, picture)
|
||||
|
||||
def test_audit_transparent_original_needs_raw_transparency(self):
|
||||
payload = struct.pack('<5i', 1, 0, 0, 1, 1) + b'\x01'
|
||||
picture = Image.new('RGBA', (1, 1), (0, 0, 0, 0))
|
||||
with tempfile.TemporaryDirectory(prefix='synthetic-', dir=Q) as directory:
|
||||
root = Path(directory); path = root / 'synthetic.png'
|
||||
Image.new('RGBA', (5, 5), (30, 50, 70, 255)).save(path)
|
||||
item = frame(); item['source_sha256'] = hashlib.sha256(payload).hexdigest()
|
||||
with self.assertRaises(ValueError): audit.validate_hd_frame(root, item, payload, picture)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main(verbosity=2)
|
||||
@@ -0,0 +1,140 @@
|
||||
"""Private generic bounds; synthetic Source/PNG fixtures, no real art or engine."""
|
||||
import ast, copy, hashlib, importlib.util, json, pathlib, struct, sys, tempfile, unittest
|
||||
from unittest import mock
|
||||
ROOT=pathlib.Path(__file__).resolve().parents[1]
|
||||
sys.path.insert(0,str(ROOT/'tools'));sys.path.insert(0,str(ROOT/'tests'))
|
||||
import hd_frame_policy as policy
|
||||
import hd_art_audit as audit
|
||||
import hd_register_reviewed as registrar
|
||||
import hd_candidate_review as candidate
|
||||
import test_hd_retained_original_policy as old
|
||||
from PIL import Image
|
||||
|
||||
def raw_source(painted, width=32, height=32):
|
||||
data=struct.pack('<5i',0,0,0,width,height)
|
||||
for y in range(height):
|
||||
n=max(0,min(width,painted-y*width))
|
||||
if n: data+=struct.pack('<4i',0,y,y*width,n)+bytes((y*width+x)%256 for x in range(n))
|
||||
return data+struct.pack('<4i',0,0,-1,0)
|
||||
|
||||
def frame(count, painted=625):
|
||||
raw=raw_source(painted)
|
||||
cells=sorted([[i%32,i//32] for i in range(painted)])[:count]
|
||||
return dict(frame=0,file='synthetic.png',logical_width=32,logical_height=32,origin=[0,0],source_sha256=hashlib.sha256(raw).hexdigest(),original_detail_cells=cells)
|
||||
|
||||
class ExtendedPolicy(unittest.TestCase):
|
||||
def test_exact_quarter_and_maximum_boundaries(self):
|
||||
for n,painted,ok in [(64,64,True),(65,260,True),(65,259,False),(73,625,True),(128,512,True),(128,511,False),(129,600,False)]:
|
||||
with self.subTest(n=n,painted=painted):
|
||||
if ok: policy.validate_frame_policy(frame(n,painted),raw_source(painted))
|
||||
else:
|
||||
with self.assertRaises(ValueError): policy.validate_frame_policy(frame(n,painted),raw_source(painted))
|
||||
def test_legacy_full_small_source_still_valid_without_new_density_rule(self):
|
||||
f=old.frame();f['original_detail_cells']=[[0,0],[0,1],[1,0],[1,1]]
|
||||
policy.validate_frame_policy(f,old.payload())
|
||||
def test_transparent_canvas_area_is_never_denominator(self):
|
||||
f=frame(65,259)
|
||||
self.assertEqual(f['logical_width']*f['logical_height'],1024)
|
||||
with self.assertRaisesRegex(ValueError,'quarter'): policy.validate_frame_policy(f,raw_source(259))
|
||||
def test_schema_preparation_is_not_final_density_approval(self):
|
||||
f=frame(65,259);policy.validate_frame_policy(f)
|
||||
rows=candidate.proposal_frames({'sequences':[dict(base_asset=1,frame_count=1,frames=[f])]})
|
||||
self.assertEqual(len(rows['00001']['original_detail_cells']),65)
|
||||
with self.assertRaises(ValueError):policy.validate_frame_policy(f,raw_source(259))
|
||||
def test_sorted_unique_inbounds_typed_and_painted_guards_remain(self):
|
||||
mutations=[lambda c:c[::-1],lambda c:c[:64]+[c[0]],lambda c:c[:64]+[[32,0]],lambda c:c[:64]+[[True,0]],lambda c:c[:64]+[[31,31]]]
|
||||
for mutate in mutations:
|
||||
f=frame(65);f['original_detail_cells']=mutate(f['original_detail_cells'])
|
||||
with self.subTest(cells=f['original_detail_cells'][-1]),self.assertRaises(ValueError):policy.validate_frame_policy(f,raw_source(625))
|
||||
def test_extended_reserved_painted_domain_and_nearest_cue_overlap(self):
|
||||
f=frame(128,512);policy.validate_frame_policy(f,raw_source(512))
|
||||
#256 is transparency, while raw labels0 and240..255 remain painted.
|
||||
self.assertEqual(sum(0<=p<=255 for p in policy._indices(raw_source(512))[2]),512)
|
||||
f['native_nearest_cues']=[f['original_detail_cells'][0]]
|
||||
with self.assertRaises(ValueError):policy.validate_frame_policy(f,raw_source(512))
|
||||
def test_legacy_v2_cannot_authorize_extended_and_v3_can_keep_legacy(self):
|
||||
for n in [1,64]:
|
||||
self.assertTrue(policy.retained_review_version_ok(policy.LEGACY_RETAINED_POLICY,{'00001':[[0,0]]*n}))
|
||||
self.assertTrue(policy.retained_review_version_ok(policy.EXTENDED_RETAINED_POLICY,{'00001':[[0,0]]*n}))
|
||||
self.assertFalse(policy.retained_review_version_ok(policy.LEGACY_RETAINED_POLICY,{'00001':[[0,0]]*65}))
|
||||
self.assertTrue(policy.retained_review_version_ok(policy.EXTENDED_RETAINED_POLICY,{'00001':[[0,0]]*65}))
|
||||
for bad in [None,True,'retained-original-details-v1',[]]:self.assertFalse(policy.retained_review_version_ok(bad,{'00001':[[0,0]]*65}))
|
||||
def test_audit_rejects_density_before_png_access(self):
|
||||
raw=raw_source(259);f=frame(65,259)
|
||||
with mock.patch.object(audit.Image,'open',side_effect=AssertionError('PNG read forbidden')):
|
||||
with self.assertRaisesRegex(ValueError,'quarter'):audit.validate_hd_frame(pathlib.Path('/absent'),f,raw,Image.new('RGBA',(32,32)))
|
||||
def test_real_synthetic_audit_accepts128_of512_without_raw_changes(self):
|
||||
with tempfile.TemporaryDirectory() as temp:
|
||||
q=pathlib.Path(temp);raw=raw_source(512);src=q/'Source';src.write_bytes(raw)
|
||||
picture=audit.decode(src,[(i,i,i) for i in range(256)])
|
||||
image=Image.new('RGBA',(64,64),(40,50,60,255));image.putpixel((63,63),(0,0,0,0));image.save(q/'synthetic.png')
|
||||
before=(q/'synthetic.png').read_bytes()
|
||||
self.assertEqual(audit.validate_hd_frame(q,frame(128,512),raw,picture),64*64*4)
|
||||
self.assertEqual(before,(q/'synthetic.png').read_bytes())
|
||||
def test_malformed_source_and_canvas_still_rejected(self):
|
||||
f=frame(65)
|
||||
for raw in [b'',struct.pack('<5i',1,0,0,32,32),raw_source(625,25,25)]:
|
||||
with self.subTest(length=len(raw)),self.assertRaises(ValueError):policy.validate_frame_policy(f,raw)
|
||||
|
||||
class ExtendedRegistrar(old.ActualRegistrarProvenance):
|
||||
# Inherited legacy tests exercise actual approved_job unmodified call surface.
|
||||
def extended(self, painted=625, count=73, layout='project'):
|
||||
self.f=frame(count,painted);self.f['file']='raw.png';raw=raw_source(painted)
|
||||
self.candidate['sequences'][0]['frames']=[self.f];self.rows=candidate.proposal_frames(self.candidate);digest=candidate.binding_digest(self.rows)
|
||||
self.review['frame_bindings_sha256']=digest
|
||||
decl=self.review['retained_original_detail_review'];decl.update(cells_by_asset={'00001':self.f['original_detail_cells']},frame_bindings_sha256=digest,policy_version=policy.EXTENDED_RETAINED_POLICY)
|
||||
self.write_json(self.job_dir/'candidate.json',self.candidate)
|
||||
self.write_json(self.job_dir/'job.json',dict(job_id='synthetic-complete1',targets=[dict(asset='00001',source_sha256=self.f['source_sha256'],logical_canvas=[32,32])]))
|
||||
qa=json.loads((self.root/'qa.json').read_text());qa['frame_bindings_sha256']=digest;qa['frames'][0].update(source_sha256=self.f['source_sha256'],logical_canvas=[32,32]);self.write_json(self.root/'qa.json',qa)
|
||||
data=(self.project/'data') if layout=='project' else self.project.parent/'data'
|
||||
(data/'sprites').mkdir(parents=True,exist_ok=True);(data/'sprites/fixture.pic').write_bytes(raw);(data/'INDEX').write_text(f'00001 {len(raw)} sprites/fixture.pic\n');return data
|
||||
def test_extended_actual_approved_job_both_catalog_layouts(self):
|
||||
data=self.extended();self.assertEqual(len(self.approve()[2]['00001']['original_detail_cells']),73)
|
||||
#Identical authenticated payload under the other product layout, no larger raw copies.
|
||||
(data/'INDEX').unlink();self.extended(layout='parent');self.assertEqual(len(self.approve()[2]['00001']['original_detail_cells']),73)
|
||||
def test_extended_old_version_rejected(self):
|
||||
self.extended();d=copy.deepcopy(self.review['retained_original_detail_review']);d['policy_version']=policy.LEGACY_RETAINED_POLICY
|
||||
with self.assertRaisesRegex(ValueError,'provenance'):self.approve(d)
|
||||
def test_extended_actual_source_density_beats_forged_claim(self):
|
||||
self.extended(259,65);self.review['retained_original_detail_review']['claimed_painted_Source_cell_count']=1024
|
||||
with self.assertRaisesRegex(ValueError,'quarter'):self.approve()
|
||||
def test_extended_actual_source_hash_required(self):
|
||||
data=self.extended();(data/'sprites/fixture.pic').write_bytes(raw_source(624))
|
||||
with self.assertRaisesRegex(ValueError,'authentic catalog Source'):self.approve()
|
||||
def test_extended_missing_source_rejected(self):
|
||||
data=self.extended();(data/'INDEX').unlink()
|
||||
with self.assertRaisesRegex(ValueError,'authentic catalog Source'):self.approve()
|
||||
def test_extended_source_path_escape_rejected(self):
|
||||
data=self.extended();(data/'INDEX').write_text('00001 4 ../outside.pic\n')
|
||||
with self.assertRaisesRegex(ValueError,'escapes catalog'):self.approve()
|
||||
def test_extended_genuine_context_and_retained_not_generated_still_required(self):
|
||||
self.extended()
|
||||
for key in ['hybrid_allscale_and_genuine_context_independent_review','retained_original_not_generated_HD']:
|
||||
d=copy.deepcopy(self.review['retained_original_detail_review']);d[key]=False
|
||||
with self.subTest(key=key),self.assertRaisesRegex(ValueError,'provenance'):self.approve(d)
|
||||
def test_density_helper_legacy_path_needs_no_catalog_io(self):
|
||||
with mock.patch.object(pathlib.Path,'read_text',side_effect=AssertionError('legacy catalog read')):
|
||||
registrar.validate_extended_retained_sources(pathlib.Path('/absent'),{'00001':old.selected()})
|
||||
|
||||
class RustSourceCompatibility(unittest.TestCase):
|
||||
def test_legacy_hd_function_bodies_and_normalized_key_tags_remain_exact(self):
|
||||
# Exact pre-bounds atlas baseline (36b3502e), formerly read from the
|
||||
# private proposal's sibling original/src/hd.rs. Inline fingerprints
|
||||
# preserve those exact guards in an ordinary standalone checkout.
|
||||
expected = {'source_reference_budget': '1e544a7639fd123a6e813fbb34f1ded100a1db192973faeb7ce1b96ad54339a0', 'retain_original_detail_samples': '5b1516291d05de782f4d81242f38686be1dca24d00ab0ee4858e3b92729a73b4', 'sprite_with_policy': '7def63d10f179c30ad71c02b3670ca457a7652a976b4c97c1a9098388655fed5', 'terrain_sprite': 'b5d713c0ed8e5327d96c1dae464b2aca4b5e8c9450f85c53928bdde5c99b6e99', 'frame_key': '3605c9fc321571dbc777036ff500f8c436ebb1e717343c056e363c4b634ea1a1', 'original_detail_cache_identity': 'bb9baa84ba832e34dea5274866ddbde52b35f48634cff0ff80533a4dc6d81ffc'}
|
||||
new=(ROOT/'src/hd.rs').read_text()
|
||||
def function(s,name):
|
||||
start=s.index('fn '+name+'(');left=s.index('{',start);depth=1;end=left+1
|
||||
while depth:depth+=(s[end]=='{')-(s[end]=='}');end+=1
|
||||
return s[start:end]
|
||||
for name in ['source_reference_budget','retain_original_detail_samples','sprite_with_policy','terrain_sprite']:
|
||||
self.assertEqual(expected[name],hashlib.sha256(function(new,name).encode()).hexdigest(),name)
|
||||
for name,old_bytes,call in [('frame_key','b"raptor-retained-original-details-v2-painted0255"','original_detail_policy_tag(frame.original_detail_cells.len(), false)'),('original_detail_cache_identity','b"retained-original-rejected-fallback-v2-painted0255"','original_detail_policy_tag(frame.original_detail_cells.len(), true)')]:
|
||||
self.assertEqual(expected[name],hashlib.sha256(function(new,name).replace(call,old_bytes).encode()).hexdigest(),name)
|
||||
def test_audit_still_calls_actual_payload_validator(self):
|
||||
tree=ast.parse((ROOT/'tools/hd_art_audit.py').read_text())
|
||||
node=next(n for n in tree.body if isinstance(n,ast.FunctionDef) and n.name=='validate_hd_frame')
|
||||
self.assertIsInstance(node.body[1],ast.Expr)
|
||||
self.assertEqual(ast.unparse(node.body[1]),'validate_frame_policy(frame, payload)')
|
||||
|
||||
if __name__=='__main__':unittest.main(verbosity=2)
|
||||
@@ -89,7 +89,7 @@ class PaintedPolicy(unittest.TestCase):
|
||||
def test_official_audit_and_schema_share_actual_validator(self):
|
||||
tree = ast.parse((TOOLS / "hd_art_audit.py").read_text())
|
||||
self.assertTrue(any(isinstance(n, ast.ImportFrom) and n.module == "hd_frame_policy"
|
||||
and {a.name for a in n.names} == {"FRAME_KEYS", "validate_frame_policy"} for n in tree.body))
|
||||
and {"FRAME_KEYS", "validate_frame_policy"} <= {a.name for a in n.names} for n in tree.body))
|
||||
self.assertIn("original_detail_cells", policy.FRAME_KEYS)
|
||||
self.assertIn("carried master74 frame has an unreviewed optional policy", (TOOLS / "hd_register_reviewed.py").read_text())
|
||||
|
||||
|
||||
Reference in new issue
Block a user