Files
ARCADIA-Studio/harness/experiments/source-alias-rename-preparation-20260911/in-process/archive-helper.py
T

57 lines
3.1 KiB
Python

"""Archive the completed historical Document experiment without rerunning it."""
from pathlib import Path
import datetime
import hashlib
import json
import shutil
root = Path(__file__).resolve().parents[2]
source = root / '.local/source-alias-rename-preparation-20260911/in-process'
target = root / 'harness/experiments/source-alias-rename-preparation-20260911/in-process'
def sha(path):
return hashlib.sha256(path.read_bytes()).hexdigest()
def write(path, value):
with path.open('x', encoding='utf-8', newline='\n') as out:
json.dump(value, out, ensure_ascii=False, indent=2)
out.write('\n')
inputs = json.loads((source / 'inputs.json').read_text(encoding='utf-8'))
assert len(inputs['files']) == 43
for item in inputs['files']:
path = (source / item['path']).resolve()
assert path.is_relative_to(source) and path.stat().st_size == item['bytes']
assert sha(path) == item['sha256'], item['path']
run = source / 'runs/accepted-snapshot-01'
result = json.loads((run / 'result.json').read_text(encoding='utf-8'))
assert result['compiled'] and result['probeExecuted'] and result['allFrozenInputsUnchanged']
binary = run / 'alias-document-probe.exe'
assert sha(binary) == result['binarySha256'] == '4cfcf5d1725f843beae10652350e9c4d30ac345baf5cf91c3ebc995ab09ae254'
assert sha(run / 'probe.stdout.log') == '0bc605eff97cc9fb8e3d09bd8cc51ccd7ec5a2b4d728a52fd8869234eb2c33d7'
evaluation = source.parent / 'in-process-evaluation.md'
assert sha(evaluation) == 'aeab6a2ad8243cec536662d2dc79fd854d7ead7f65af5fad285ce143cae2f450'
target.mkdir(exist_ok=False)
for path in sorted(source.rglob('*')):
assert not path.is_symlink() and not (getattr(path.lstat(), 'st_file_attributes', 0) & 0x400)
if not path.is_file() or path == binary:
continue
assert path.suffix.lower() not in {'.exe', '.dll', '.rlib', '.pdb'}
destination = target / 'raw' / path.relative_to(source)
destination.parent.mkdir(parents=True, exist_ok=True)
shutil.copy2(path, destination)
assert destination.read_bytes() == path.read_bytes()
shutil.copy2(evaluation, target / 'evaluation.md')
shutil.copy2(Path(__file__), target / 'archive-helper.py')
shutil.copy2(source.parent / 'archive_in_process.failed_pin.py', target / 'archive-helper-failed-pin.py')
write(target / 'probe-binary-identity.json', {'path': str(binary), 'sha256': sha(binary),
'bytes': binary.stat().st_size, 'included': False})
files = [{'path': path.relative_to(target).as_posix(), 'bytes': path.stat().st_size, 'sha256': sha(path)}
for path in sorted(target.rglob('*')) if path.is_file()]
write(target / 'manifest.json', {'archivedUtc': datetime.datetime.now(datetime.timezone.utc).isoformat(),
'scope': 'Actual copied-Document debug experiment; historical eeeaa126 GUI core binding, no UI or prepared-capability benchmark',
'payloads': len(files), 'bytes': sum(item['bytes'] for item in files), 'files': files})
(target / '.gitattributes').write_bytes(b'* -text\n** -text\n')
print(json.dumps({'payloads': len(files), 'bytes': sum(item['bytes'] for item in files),
'manifestSha256': sha(target / 'manifest.json')}))