Files

34 lines
2.2 KiB
Python

"""이전 모든 증거·voice·source·구간의 불변성과 새 dist 바이트를 검증한다."""
import hashlib
import json
from pathlib import Path
ROOT=Path(__file__).resolve().parents[3]
EVIDENCE=Path(__file__).resolve().parent
def sha(path): return hashlib.sha256(path.read_bytes()).hexdigest()
history=json.loads((EVIDENCE/'history-sha256.json').read_text())
baseline=json.loads((ROOT/'.agent/evidence-v0.2.5/baseline.json').read_text())
for path,expected in {**history,**baseline['immutable'],**baseline['voiceWavs']}.items():
assert sha(ROOT/path)==expected,path
plan=json.loads((ROOT/'.agent/AMBIENCE-SOURCES-v0.2.3.json').read_text())
current=json.loads((ROOT/'public/ambience/manifest.json').read_text())
rejected=json.loads((EVIDENCE/'rejected-loudnorm-bundle/manifest.json').read_text())
sources=[]
for asset,entry,old in zip(plan['assets'],current['files'],rejected['files']):
assert all(entry[key]==value for key,value in asset.items())
assert entry['sha256']!=old['sha256']
assert entry['conversion']['startSeconds']==asset['selectedSegmentStartSeconds']
environment=asset['environmentId']
ext='.mp3' if environment in ('theater','department') else '.flac' if environment=='rain' else '.ogg'
path=Path('/tmp/findword-ambience-sources')/(environment+ext)
assert path.stat().st_size==asset['sourceBytes'] and sha(path)==asset['expectedSourceSha256']
sources.append({'environmentId':environment,'sourceSha256':sha(path),'sourceBytes':path.stat().st_size,'startSeconds':asset['selectedSegmentStartSeconds']})
public=list((ROOT/'public').rglob('*'))
for path in public:
if path.is_file(): assert path.read_bytes()==(ROOT/'dist'/path.relative_to(ROOT/'public')).read_bytes(),path
report={'historicalV025FilesPreserved':len(history),'earlierImmutableFilesPreserved':len(baseline['immutable']),
'voiceWavsPreserved':len(baseline['voiceWavs']),'sourcePlanSha256':sha(ROOT/'.agent/AMBIENCE-SOURCES-v0.2.3.json'),
'sourceAndSegmentsPreserved':sources,'newAmbienceCount':8,'allPublicFilesMatchDist':True}
with (EVIDENCE/'preservation.json').open('x') as stream: stream.write(json.dumps(report,indent=2)+'\n')
print(json.dumps(report,indent=2))