Files
stack/agents/rocko/work/queue-280/run-mutants-phase1.py
jason.woltje 068d868a99 lead: commit rocko's untracked evidence (4471 files: queue-124 queue-129 queue-171 queue-178 queue-280 queue-31 queue-84 queue-85 queue-94)
Unclaimed files left in the canonical checkout. Inventory: canonical-cleanup-inventory.md (commit-as-evidence groups). detect-secrets scan clean on 2026-11-02: hits are sha256 pins, git object ids, test sentinels already in tracked tests and unit-file lines.
2026-11-02 15:05:15 -06:00

30 lines
1.8 KiB
Python

from pathlib import Path
import subprocess,os,json,hashlib
root=Path(__file__).resolve().parents[4]
packet=Path(__file__).resolve().parent
p=root/'packages/bus/tests/scratch-sshd.mjs';good=p.read_text()
accept=""" if (await listening(port) && daemon.exitCode === null && daemon.signalCode === null &&
readFileSync(lastLog, 'utf8').split('\\n').some(line =>
(line === `Server listening on 127.0.0.1 port ${port}.` ||
line === `Server listening on 127.0.0.1 port ${port}.\\r`))) return port;"""
a=good.index('export function pickPort(');b=good.index('\n}\n',a)+3
picker=good[a:b]
sites=[{'id':'M1','old':accept,'new':' if (await listening(port)) return port;','pattern':'row 280: an occupied TCP port'},
{'id':'M2','old':picker,'new':'export function pickPort(rand = Math.random) {\n return 20000 + Math.floor(rand() * 20000);\n}\n','pattern':'row 280: every injected picker sample'}]
(packet/'mutants.json').write_text(json.dumps(sites,indent=2)+'\n')
try:
for site in sites:
assert good.count(site['old'])==1,site['id']
for file in ['grant-executor','host-run']:
p.write_text(good.replace(site['old'],site['new']))
try:
cmd=['python3',str(packet/'run-step.py'),site['id']+'-'+file,'node','--test','--test-reporter=tap','--test-name-pattern='+site['pattern'],'packages/bus/tests/'+file+'.test.mjs']
r=subprocess.run(cmd,cwd=root,env=os.environ.copy())
assert r.returncode==0,(site['id'],file)
log=(packet/'logs'/(site['id']+'-'+file+'.log')).read_text()
assert 'not ok 1 - '+site['pattern'] in log
finally: p.write_text(good)
finally:
p.write_text(good)
(packet/'mutant-restore.json').write_text(json.dumps({'helper_sha256':hashlib.sha256(p.read_bytes()).hexdigest(),'restored':p.read_text()==good},indent=2)+'\n')