Files
stack/agents/darkwing/work/slice1-s2-review/mutations-dw.py
T
2026-10-04 23:13:35 -05:00

23 lines
1.4 KiB
Python

#!/usr/bin/env python3
# Rocko's 11 cases, run in the repository layout, each compared against an unmutated baseline.
import pathlib,tempfile,shutil,subprocess,json,re,sys,importlib.util
spec=importlib.util.spec_from_file_location('m',sys.argv[1]);src=open(sys.argv[1]).read()
cases=eval(src[src.index('cases=')+6:src.index(']\nresults')+1])
source=pathlib.Path(sys.argv[2])
def run(dest):
r=subprocess.run(['node','--test',*[str(p) for p in sorted((dest/'tests').glob('*.test.mjs'))]],capture_output=True,text=True,timeout=120)
tests=set(l[2:].rsplit(' (',1)[0] for l in r.stdout.splitlines() if l.startswith('✖ ') and not l.startswith('✖ failing tests'))
return r.returncode,tests
with tempfile.TemporaryDirectory(prefix='dw-bus-mut-') as root:
dest=pathlib.Path(root)/'packages'/'bus';shutil.copytree(source,dest,ignore=shutil.ignore_patterns('dw'))
code,base=run(dest);print(json.dumps({'baseline_exit':code,'baseline_failures':sorted(base)}))
out=[]
for name,file,old,new in cases:
p=dest/'src'/file;b=p.read_text();pat=r'\s*'.join(re.escape(c) for c in old if not c.isspace());assert len(re.findall(pat,b))==1,name
p.write_text(re.sub(pat,lambda m:new,b,count=1))
try: code,f=run(dest)
finally: p.write_text(b)
extra=sorted(f-base);out.append({'mutation':name,'exit':code,'killed':bool(extra),'new_failures':extra})
print(json.dumps(out[-1]))
print('killed',sum(x['killed'] for x in out),'of',len(out))