Files
ARCADIA-Studio/harness/experiments/source-alias-rename-preparation-20260911/measure_cli.py
T

56 lines
2.8 KiB
Python

"""Read-only CLI preview timing; process/IO overhead is NOT Document execution timing."""
import hashlib
import json
import os
import shutil
import subprocess
import time
from datetime import datetime, timezone
from pathlib import Path
root = Path(__file__).resolve().parents[2]
out = Path(__file__).resolve().parent / 'cli-preview'
fixture = root / '.local/text-navigation-native-20260911-preparation/release1-baseline'
binary = root / '.local/source-cli-20260911/verified/arcadia.exe'
binary_sha = 'bad169f8be78dcfa74b32714569c886dd2132727080684fc2ba618d5822e3559'
def sha(path):
return hashlib.sha256(path.read_bytes()).hexdigest()
def inventory(directory):
result = {}
for path in sorted(directory.rglob('*')):
assert not path.is_symlink()
if path.is_file():
result[path.relative_to(directory).as_posix()] = {'bytes': path.stat().st_size, 'sha256': sha(path)}
return result
assert root.name == 'ARCADIA-Studio' and sha(binary) == binary_sha
assert not out.exists()
before = inventory(fixture)
assert len(before) == 37
out.mkdir()
shutil.copytree(fixture, out / 'model')
assert inventory(out / 'model') == before
env = os.environ.copy()
env['PATH'] = str(binary.parent) + ';' + env.get('PATH', '')
results = []
for label, operation in [('check', ['check']), ('rename-preview-1', ['rename-alias']), ('rename-preview-2', ['rename-alias'])]:
command = [str(binary), *operation, str(out / 'model/project.arcadia')]
if operation[0] == 'rename-alias':
command += ['oa_restore_work', 'oa_restore_pressure']
command += ['--json']
started = datetime.now(timezone.utc).isoformat()
clock = time.perf_counter()
result = subprocess.run(command, capture_output=True, env=env, timeout=60)
elapsed = time.perf_counter() - clock
(out / (label + '.stdout.json')).write_bytes(result.stdout)
(out / (label + '.stderr.log')).write_bytes(result.stderr)
parsed = json.loads(result.stdout)
results.append({'label': label, 'startedAtUtc': started, 'command': command, 'exitCode': result.returncode,
'wallSeconds': elapsed, 'status': parsed.get('status'), 'stdoutSha256': hashlib.sha256(result.stdout).hexdigest()})
assert result.returncode == 0, label
assert inventory(out / 'model') == before
assert inventory(fixture) == before and sha(binary) == binary_sha
receipt = {'binarySha256': binary_sha, 'fixtureUnchanged': True, 'trialFilesUnchanged': True, 'files': before, 'results': results,
'scope': 'Existing debug CLI process startup, disk load, validation, rename preparation and JSON preview. Not current Document/UI latency, accepted-snapshot preview, or native acceptance.'}
(out / 'receipt.json').write_text(json.dumps(receipt, ensure_ascii=False, indent=2) + '\n', encoding='utf-8')
print(json.dumps({'results': results, 'unchanged': True}))