#!/usr/bin/env python3 """Explicit 27-file scope. Execution requires Sage's focused CLEAR.""" import argparse import hashlib import importlib.util import json import os from pathlib import Path import subprocess import sys sys.dont_write_bytecode = True HERE=Path(__file__).resolve().parent spec=importlib.util.spec_from_file_location('row253_driver',HERE/'driver.py') driver=importlib.util.module_from_spec(spec) spec.loader.exec_module(driver) def main(): ap=argparse.ArgumentParser() ap.add_argument('--grant',required=True) ap.add_argument('--out',type=Path,required=True) args=ap.parse_args() if not os.environ.get('TMPDIR','').startswith('/mnt/storage/scratch/tmp/g'): raise RuntimeError('use the granted scratch TMPDIR') expected=json.loads((HERE/'CANDIDATE-SHAS.json').read_text()) def verify(): for name,sha in expected.items(): assert hashlib.sha256((driver.REPO/name).read_bytes()).hexdigest()==sha,name verify() files=json.loads((HERE/'integration-aca1/whole-test-union.json').read_text()) limits=json.loads((HERE/'integration-aca1/FILE-LIMITS.json').read_text()) assert len(files)==27 and set(files)==set(limits) args.out.mkdir(parents=True,exist_ok=True) result=dict(grant=args.grant,head=subprocess.check_output(['git','rev-parse','HEAD'],cwd=driver.REPO,text=True).strip(),manifest=hashlib.sha256((HERE/'MANIFEST.sha256').read_bytes()).hexdigest(),steps=[]) print(json.dumps({k:result[k] for k in ['grant','head','manifest']}),flush=True) print(json.dumps(dict(authority='sage-2709',file_limits=limits)),flush=True) (args.out/'results.json').write_text(json.dumps(result,indent=2)+'\n') for index,name in enumerate(files): limit=limits[name] command=['timeout','-k',str(limit['kill_after_seconds']),str(limit['timeout_seconds']),'node','--test','--test-reporter=tap',name] step=driver.run(command,args.out/(str(index+1).zfill(2)+'.log'),seconds=limit['outer_harness_seconds']) text=Path(step['log']).read_text(errors='replace') counts={} for line in text.splitlines(): for key in ['tests','pass','fail','skipped']: prefix='# '+key+' ' if line.startswith(prefix) and line[len(prefix):].isdigit():counts[key]=int(line[len(prefix):]) step.update(file=name,counts=counts,named_skips=[line for line in text.splitlines() if '# SKIP' in line]) result['steps'].append(step) (args.out/'results.json').write_text(json.dumps(result,indent=2)+'\n') verify() if step['timeout']:raise RuntimeError('timeout: stop, report unplaced, do not retry') if step['code']!=0:raise RuntimeError('unexpected failure: stop, report unplaced, do not retry') print(json.dumps(result,indent=2),flush=True) if __name__=='__main__':main()