32 lines
1.5 KiB
Python
32 lines
1.5 KiB
Python
"""Reproduce shape counterexamples and their correction in the actual producer."""
|
|
from pathlib import Path
|
|
import hashlib
|
|
import json
|
|
import shutil
|
|
import subprocess
|
|
import sys
|
|
import time
|
|
|
|
HERE = Path(__file__).resolve().parent
|
|
label = sys.argv[1]
|
|
assert label in ['shapes-before', 'shapes-after']
|
|
prior = json.loads((HERE / 'producer-all-result.json').read_text())
|
|
assert prior['returncode'] != 0 # Completed initial full run with missing fixtures.
|
|
source = Path(prior['workspace']) / 'source'
|
|
overlay = HERE / 'access-engine-source'
|
|
pins = {}
|
|
for item in overlay.rglob('*'):
|
|
if item.is_file():
|
|
target = source / item.relative_to(overlay)
|
|
target.parent.mkdir(parents=True, exist_ok=True)
|
|
shutil.copyfile(item, target)
|
|
pins[str(item.relative_to(overlay))] = hashlib.sha256(item.read_bytes()).hexdigest()
|
|
argv = prior['argv'][:prior['argv'].index('--') + 1] + ['go', 'test', '-p', '4', '-json', './cmd/access-engine', '-run', '^TestForgejoActualPolicySignedLosslessAndLegacy$', '-count=1']
|
|
log = HERE / (label + '.jsonl')
|
|
assert not log.exists()
|
|
start = time.monotonic()
|
|
with log.open('xb') as output:
|
|
run = subprocess.run(argv, stdout=output, stderr=subprocess.STDOUT, timeout=180)
|
|
(HERE / (label + '.json')).write_text(json.dumps({'returncode': run.returncode, 'seconds': round(time.monotonic() - start, 2), 'argv': argv, 'source_pins': pins, 'network': 'disabled', 'pid_namespace': 'private'}, indent=2) + '\n')
|
|
print(json.dumps({'phase': label, 'returncode': run.returncode}))
|
|
raise SystemExit(run.returncode)
|