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.
125 lines
5.0 KiB
Python
125 lines
5.0 KiB
Python
#!/usr/bin/env python3
|
|
"""Row 105 (#1599) mutants, r1. Written in phase A; NOT RUN in phase A.
|
|
|
|
Run only after Sage sends "slot clear" and phase-b.sh has passed:
|
|
python3 -I agents/researcher/work/queue-105/r1/mutants.py <worktree-root>
|
|
Optional: <worktree-root> --only <id> runs one mutant after the baseline.
|
|
|
|
Each mutant is one exact text replacement that must match exactly once. The killer
|
|
command runs with the mutant in place. The file is restored in a finally block and
|
|
its bytes are checked against the original. Each run has its own process group, and
|
|
the group is killed on exit and on timeout. A timeout is reported as a gate failure,
|
|
never as a kill. Baseline: every killer must pass unmutated, or nothing runs.
|
|
|
|
README.md has no test. Its review.request row is documentation, so it has no mutant.
|
|
"""
|
|
import hashlib
|
|
import os
|
|
import pathlib
|
|
import signal
|
|
import subprocess
|
|
import sys
|
|
|
|
BUS_REVIEW = ['node', '--test', 'tests/review.test.mjs']
|
|
HARNESS_TOOLS = ['node', '--test', 'tests/tools.test.mjs']
|
|
TIMEOUT = 600
|
|
|
|
MUTANTS = [
|
|
dict(id='M1', file='packages/bus/src/broker.mjs',
|
|
old='commit: a.commit, ref: push.ref, held };',
|
|
new='commit: a.commit, ref: push.ref };',
|
|
cwd='packages/bus', argv=BUS_REVIEW, why='reply no longer carries held'),
|
|
dict(id='M2', file='packages/bus/src/broker.mjs',
|
|
old='to: a.to, message: mid, held },',
|
|
new='to: a.to, message: mid },',
|
|
cwd='packages/bus', argv=BUS_REVIEW, why='review.requested body no longer records held'),
|
|
dict(id='M3', file='packages/bus/src/broker.mjs',
|
|
old="const held = h?.op === 'claim' ? h.holder_run : null;",
|
|
new='const held = h ? h.holder_run : null;',
|
|
cwd='packages/bus', argv=BUS_REVIEW, why='a released reviewer role counted as held'),
|
|
dict(id='M4', file='packages/bus/src/broker.mjs',
|
|
old='to: a.to, message: mid, held },',
|
|
new='to: a.to, message: mid, held: null },',
|
|
cwd='packages/bus', argv=BUS_REVIEW, why='event records null while the reply carries the holder'),
|
|
dict(id='M5', file='packages/harness/src/tools.mjs',
|
|
old=" The reply's held names the run holding the reviewer role, or is null when no reviewer is running. A null request waits until a reviewer launches, so tell whoever launches roles that a review is waiting.",
|
|
new='',
|
|
cwd='packages/harness', argv=HARNESS_TOOLS, why='request_review description drops what held and null mean'),
|
|
dict(id='M6', file='packages/harness/src/tools.mjs',
|
|
old=', so tell whoever launches roles that a review is waiting.',
|
|
new='.',
|
|
cwd='packages/harness', argv=HARNESS_TOOLS, why='request_review description drops the requester instruction'),
|
|
]
|
|
|
|
|
|
def sha(data):
|
|
return hashlib.sha256(data).hexdigest()
|
|
|
|
|
|
def run(argv, cwd, timeout):
|
|
proc = subprocess.Popen(argv, cwd=cwd, start_new_session=True,
|
|
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
|
try:
|
|
out, _ = proc.communicate(timeout=timeout)
|
|
return proc.returncode, out.decode(errors='replace')
|
|
except subprocess.TimeoutExpired:
|
|
os.killpg(proc.pid, signal.SIGKILL)
|
|
out, _ = proc.communicate()
|
|
return 'timeout', out.decode(errors='replace')
|
|
finally:
|
|
try:
|
|
os.killpg(proc.pid, signal.SIGKILL)
|
|
except ProcessLookupError:
|
|
pass
|
|
|
|
|
|
def main():
|
|
root = pathlib.Path(sys.argv[1]).resolve()
|
|
only = sys.argv[3] if len(sys.argv) > 3 and sys.argv[2] == '--only' else None
|
|
seen = set()
|
|
for m in MUTANTS:
|
|
key = (m['cwd'], tuple(m['argv']))
|
|
if key in seen:
|
|
continue
|
|
seen.add(key)
|
|
rc, _ = run(m['argv'], root / m['cwd'], TIMEOUT)
|
|
if rc != 0:
|
|
print(f"BASELINE FAILED {m['cwd']} {' '.join(m['argv'])} rc={rc}; no mutant was run")
|
|
return 2
|
|
print(f"baseline ok {m['cwd']} {' '.join(m['argv'])}")
|
|
results = []
|
|
for m in MUTANTS:
|
|
if only and m['id'] != only:
|
|
continue
|
|
path = root / m['file']
|
|
orig = path.read_bytes()
|
|
text = orig.decode()
|
|
if text.count(m['old']) != 1:
|
|
results.append((m['id'], 'ANCHOR', f"old text matches {text.count(m['old'])} times"))
|
|
print(f"{m['id']}: ANCHOR (old text matches {text.count(m['old'])} times); not run")
|
|
continue
|
|
path.write_bytes(text.replace(m['old'], m['new'], 1).encode())
|
|
try:
|
|
rc, _ = run(m['argv'], root / m['cwd'], TIMEOUT)
|
|
finally:
|
|
path.write_bytes(orig)
|
|
if sha(path.read_bytes()) != sha(orig):
|
|
print(f"RESTORE FAILED {m['file']}; stop and report")
|
|
return 3
|
|
if rc == 'timeout':
|
|
verdict = 'TIMEOUT (gate failure, not a kill)'
|
|
elif rc == 0:
|
|
verdict = 'SURVIVED'
|
|
else:
|
|
verdict = 'KILLED'
|
|
results.append((m['id'], verdict, m['why']))
|
|
print(f"{m['id']}: {verdict} ({m['why']})")
|
|
print('---')
|
|
for r in results:
|
|
print(*r)
|
|
return 0
|
|
|
|
|
|
if __name__ == '__main__':
|
|
sys.exit(main())
|