27 lines
7.6 KiB
Python
27 lines
7.6 KiB
Python
from pathlib import Path
|
||
import json,hashlib,sys,importlib.util,collections,struct
|
||
sys.dont_write_bytecode=True
|
||
R=Path('/home/quintine/Projects/RaptorReplica/RustRaptor');A=R/'.reference/hd-iron-names-terrain2054d-2054e-and2057f-20581-20588-Original-primary-author-20261019-v1';C=A/'source-material-code-proposal';O=Path(__file__).resolve().parent;sys.path.insert(0,str(R/'tools'));from hd_candidate_review import proposal_frames,binding_digest
|
||
import numpy as np
|
||
from PIL import Image
|
||
sha=lambda p:hashlib.sha256(p.read_bytes()).hexdigest()
|
||
def pin(p):return dict(path=str(p),sha256=sha(p),bytes=p.stat().st_size)
|
||
request=C/'CODE-AND-ACTUAL-BINDING-REVIEW-REQUEST.json';req=json.loads(request.read_text());tool=C/'terrain_night_hardware_cleanup.py';assert sha(tool)==req['tool']['sha256']=='1b448911a7af01e1f19aae945f1e581c2b2a8f7bb66ed7ad597bd6450cd9191c';assert sha(O/tool.name)==sha(tool);dep=R/'tools/hd_terrain_cleanup.py';assert sha(dep)=='3284cf6f85ced107dfc364ea90e15aed341d478bea7e308024b5bc5218b03092';assert sha(C/'test_terrain_night_hardware_cleanup.py')==req['synthetic_tests']['sha256']==sha(O/'test_terrain_night_hardware_cleanup.py')
|
||
spec=importlib.util.spec_from_file_location('isolated_independent_night',O/tool.name);m=importlib.util.module_from_spec(spec);spec.loader.exec_module(m)
|
||
index={f'{int(q[0],16):05x}':R/'data'/q[2]for line in (R/'data/INDEX').read_text().splitlines()if len(q:=line.split())==3};rows=[];inputpins=[]
|
||
for group in req['bindings']:
|
||
cohort=group['cohort'];root=C/cohort;rp=root/'recipe.json';recipe=json.loads(rp.read_text());assert sha(rp)==group['recipe_sha256'];assert tuple(v['asset']for v in recipe['sources'])==m.COHORTS[cohort];assert recipe['method']==m.METHOD;assert [recipe[x]for x in ['output_side','band_sigma','band_clip','band_strength']]==[512,2.0,12.0,0.5];cp=A/cohort/'candidate-prepared-before-cleanup.json';frames=proposal_frames(json.loads(cp.read_text()));assert set(frames)==set(m.COHORTS[cohort]);materials=[];crops=[]
|
||
for binding in group['inputs']:
|
||
p=root/binding['path'];assert sha(p)==binding['sha256'] and p.stat().st_size==binding['bytes'];inputpins.append(pin(p))
|
||
pb=(root/recipe['palette']['path']).read_bytes();assert pb==(R/'data/misc/PALETTE_DAT').read_bytes();palette=m.palette_rgb(pb)
|
||
for source in recipe['sources']:
|
||
a=source['asset'];p=root/source['path'];raw=p.read_bytes();assert raw==index[a].read_bytes() and sha(p)==source['sha256'];indices=m.decode_source32(raw);labels=m.source_labels(indices);union=m.support_union(indices);frame=frames[a];assert frame['logical_width']==32 and frame['logical_height']==32 and frame['origin']==[0,0] and frame['source_sha256']==sha(p);assert frame.get('original_detail_cells',[])==union
|
||
assert len(union)==(4 if a in ['20581','20588']else0);materials.append(dict(asset=a,Source=pin(p),canonical_Source=pin(index[a]),source_header_le_i32=list(struct.unpack_from('<5i',raw)),palette_indices_counts={str(k):v for k,v in sorted(collections.Counter(indices.flat).items())},material_owner_class_counts={str(int(k)):int(v)for k,v in zip(*np.unique(labels,return_counts=True))},Original_functional_support_union=union,prepared_native_frame=frame))
|
||
for key,binding in recipe['donors'].items():
|
||
p=root/binding['path'];assert sha(p)==binding['sha256'];im=Image.open(p);assert im.format=='PNG' and im.mode in ['RGB','RGBA'] and im.width*im.height<=m.MAX_PNG_PIXELS;rgb=np.array(im.convert('RGB'));x,y,w,h=binding['box'];assert all(type(n)is int for n in binding['box'])and min(x,y)>=0 and min(w,h)>0 and x+w<=im.width and y+h<=im.height;box=rgb[y:y+h,x:x+w];crops.append(dict(material_class=int(key),raw=pin(p),dimensions=list(im.size),crop_xywh=binding['box'],RGB_min=box.min((0,1)).tolist(),RGB_max=box.max((0,1)).tolist(),RGB_mean=box.mean((0,1)).tolist(),coarse_geometry_not_transferred=True))
|
||
rows.append(dict(cohort=cohort,recipe=pin(rp),candidate=pin(cp),frame_bindings_sha256=binding_digest(frames),materials=materials,donor_crops=crops))
|
||
assert (O/'actual-isolated-five-synthetic-tests.stderr').read_text().rstrip().endswith('OK')
|
||
# Only Source ownership/union and PNG read-only crop statistics were measured. derive/main never called on real inputs.
|
||
report=dict(status='PASS_DIFFERENT_CODE_AND_EXACT_ACTUAL5_BINDINGS_BEFORE_FIRST_REAL_CLEANUP',reviewer='/root/terrain_context_review',author='/root/iron_coast_names',different_from_author=True,request=pin(request),tool=pin(tool),authenticated_dependency=pin(dep),synthetic_test_source=pin(O/'test_terrain_night_hardware_cleanup.py'),actual_synthetic_suite=dict(tests=5,passed=5,exit_code=0,stdout=pin(O/'actual-isolated-five-synthetic-tests.stdout'),stderr=pin(O/'actual-isolated-five-synthetic-tests.stderr'),isolation='Exact copied helper/test bytes under independent folder; PYTHONDONTWRITEBYTECODE=1; test temporary writes restricted to this copy folder. No synthetic test temp writes in original producer.'),cohorts=rows,actual_input_pins=inputpins,CODE_findings=['Bounded regular O_NOFOLLOW component-by-component reads authenticate SHA against buffered immutable bytes before decoding; finite source32 and opaque singlePNG constraints enforced.','Actual recipes select exact complete cohorts and fixed512/sigma2/clip12/strength0.5. Source owners use public authenticated SourceNx math; gray/olive normalized in-class shading prevents cross-material color transfer.','Only clipped fine RGB donor band transfers; coarse donor machinery geometry is not copied. Source31 opaque-black and>=240 functional owners remain exact Original RGB; these receive zero HD credit.','Prepared frame Source hashes/canvas/origin and fullscale functional support unions match actual Original bytes:20581/20588fourretainedcells each, others0.','Output is prepared completely before creating a new output directory; successful receipt explicitly says derived, records actualtool/dependency/recipe/input/output hashes. Read-onlybinding audit did not invoke real derive/main, write real outputs or run G2.'],donor_visual_binding='Both genuine untouched wholemasters visually opened. Hardware gray box lies inside plain upperplate; dark gray box excludes outerframe; olive box lies in topmiddle olivepanel. The dark3 wholemaster was display-resized2172x724→2048x683; literal bounds and RGBstatistics use exact original pixels, no fullnativeARTapproval claimed.',scope='Different CODE plus exact actual-input/recipe/preparedframe binding gate only. This permits the author’s separately Root-authorized finite first cleanup and final G2 checks; output ART, allnativefidelity, genuine contexts and final admission remain unreviewed.',limits=['Not a generic security review of arbitrary untrusted CLI recipes/output paths: exact bound private recipes and intended new private output directories reviewed.','Fine donor variation may be subtle in very dark classes; generated material contribution must be measured in actual output and material readability independently reviewed.','Prepared candidate source/detail fields are bound; no real derivedoutput exists or is approved by this receipt.','Genuine Source opaque black/functional retention is Original material, no generatedHD detail credit.'],new_real_calls=dict(cleanup=0,G2=0,World=0,imagegen=0,compositor=0),canonical_mutations=0)
|
||
p=O/'PASS-DIFFERENT-NIGHT5-CODE-AND-ACTUAL-BINDINGS-NO-REAL-CLEANUP.json';p.write_text(json.dumps(report,indent=2)+'\n');guard=O/'CLOSING-TOOL-RECIPE-SOURCE-AND-PREPARED-FRAME-BINDINGS.json';guard.write_text(json.dumps(dict(status='PASS_CLOSING_EXACT_BOUND_AUTHORITY',report=pin(p),authorities=[pin(request),pin(tool),pin(dep)]+inputpins+[x[k]for x in rows for k in ['recipe','candidate']]),indent=2)+'\n');print('report',sha(p),'closure',sha(guard));print([(x['cohort'],x['frame_bindings_sha256'])for x in rows])
|