"""Bounded original-source mutation controls, Codespace only, no provider case.""" import datetime,hashlib,json,os,pathlib,platform,re,subprocess,sys assert platform.system()=='Linux' root=pathlib.Path('/workspaces/symitar-mutation');project=root/'examples/jack-henry-symitar';out=root/'matrix';out.mkdir(exist_ok=True) sha=lambda b:hashlib.sha256(b).hexdigest() files=['journal.py','host.py','lib/conversation_policy.py','lib/reply_policy.py'];original={f:(project/f).read_bytes() for f in files} write=lambda p,d:p.write_text(json.dumps(d,indent=2)+'\n') env=os.environ.copy() for k in list(env): if any(v in k for v in ['API_KEY','TOKEN','RASA_LICENSE','CLIENT_SECRET']):env.pop(k,None) tmp=root/'tmp';tmp.mkdir(exist_ok=True,mode=0o700) env.update(TMPDIR=str(tmp),PYTHONDONTWRITEBYTECODE='1',PYTHONHASHSEED='0',DEMO_SEED='295185') python=str(project/'.venv/bin/python') suites=['test_journal','test_host','test_conversation_policy','test_reply_policy'] def run(label,selected): cmd=[python,'-B','-m','unittest','discover','-s','tests','-p',selected+'.py','-v'] # Separate invocation per real module, preserving unittest provenance. start=datetime.datetime.now(datetime.timezone.utc).isoformat() proc=subprocess.run(cmd,cwd=project,env=env,capture_output=True,timeout=180) (out/(label+'.stdout')).write_bytes(proc.stdout);(out/(label+'.stderr')).write_bytes(proc.stderr) text=proc.stderr.decode(); summary=re.search(r'Ran (\d+) tests? in ([0-9.]+)s',text) return dict(label=label,suite=selected,exit=proc.returncode,tests=int(summary[1]) if summary else 0,seconds=float(summary[2]) if summary else None,failures=re.findall(r'^(?:FAIL|ERROR): (test_\w+) \(([^)]+)\)',text,re.M),skips=re.findall(r'^.*\.\.\. skipped.*$',text,re.M),stdoutSha256=sha(proc.stdout),stderrSha256=sha(proc.stderr),start=start) results={'revision':'0e90ad8f3083c697d000913b9d4a54cf559a87c9','projectTree':'b9d39063491270736a6d3252547d460d8e2d2de4','seed':295185,'scope':'Existing targeted journal, host and presentation suites; not the full make-test suite or a live/model case.','originals':{f:sha(b) for f,b in original.items()},'baseline':[],'mutations':[]} for s in suites: r=run('baseline-'+s,s);results['baseline'].append(r);write(out/'RESULTS.json',results);print(json.dumps(r),flush=True) assert r['exit']==0 and r['tests']>0 and not r['skips'],r variants=[ ('recovery-pending-to-unknown','journal.py',' self._db.execute("UPDATE operations SET state=\'unknown\' WHERE state=\'pending\'")',' pass','test_journal'), ('reserve-principal-held','journal.py',' if self.held(principal):\n raise JournalRefused("principal_held")\n','','test_journal'), ('reserve-epoch','journal.py',' if epoch != self.epoch:\n raise JournalRefused("fixture_epoch_changed")\n','','test_journal'), ('result-pending-only','journal.py'," WHERE operation=? AND state='pending'"," WHERE operation=?",'test_journal'), ('held-without-unknown','journal.py',"state IN ('pending','unknown')","state IN ('pending')",'test_journal'), ('held-without-pending','journal.py',"state IN ('pending','unknown')","state IN ('unknown')",'test_journal'), ('host-next-turn','host.py',' if user_turn != pending.user_turn + 1:\n raise Refused("next_turn_required")\n','','test_host'), ('conversation-turn-reset','lib/conversation_policy.py',' if seen_turn is not native.turn:\n seen = set()\n','','test_conversation_policy'), ('reply-turn-binding','lib/reply_policy.py',' or saved[0] is not native.turn','','test_reply_policy'), ('reply-delivery-age','lib/reply_policy.py',' or time.monotonic()-saved[1] > _MAX_AGE','','test_reply_policy'), ] try: for label,file,old,new,suite in variants: text=original[file].decode();assert text.count(old)==1,(label,text.count(old));mutant=text.replace(old,new);(project/file).write_text(mutant) try:r=run(label,suite) finally:(project/file).write_bytes(original[file]) r.update(file=file,line=text[:text.index(old)].count('\n')+1,removed=old,replacement=new,mutantSha256=sha(mutant.encode()),restoredSha256=sha((project/file).read_bytes()),failingTests=len(r['failures'])) results['mutations'].append(r);write(out/'RESULTS.json',results);print(json.dumps(r),flush=True) finally: for file,data in original.items():(project/file).write_bytes(data) results['restoration']={f:sha((project/f).read_bytes())==sha(b) for f,b in original.items()};write(out/'RESULTS.json',results) assert all(results['restoration'].values()) print('MATRIX_COMPLETE',flush=True)