import subprocess, sys, os, shutil W=os.path.expanduser('~/dewey-scratch/r136/wt') src=os.path.join(W,'packages/bus/src/broker.mjs') orig=open(src).read() shutil.copy(src, os.path.expanduser('~/dewey-scratch/r136/mut/broker.orig.mjs')) M={ 'M1-authority-thread': (" this.#raisedThread(d) !== s.thread ||\n", ""), 'M2-supersede-role': ("if (old.raised_by_role !== s.role || this.#raisedThread(old)", "if (this.#raisedThread(old)"), 'M3-supersede-thread': (" || this.#raisedThread(old) !== s.thread || this.#closed(old.id))", " || this.#closed(old.id))"), 'M4-authority-role': (" d.raised_by_role !== s.role ||\n this.#raisedThread(d)", " this.#raisedThread(d)"), 'M5-authority-null-any-thread': (" this.#raisedThread(d) !== s.thread ||\n", " (this.#raisedThread(d) ?? s.thread) !== s.thread ||\n"), 'M6-supersede-null-any-thread': (" || this.#raisedThread(old) !== s.thread || ", " || (this.#raisedThread(old) ?? s.thread) !== s.thread || "), } files=['packages/bus/tests/approval-binding.test.mjs','packages/bus/tests/single-use.test.mjs','packages/bus/tests/broker.test.mjs'] env=dict(os.environ, TMPDIR=os.path.expanduser('~/dewey-scratch/tmp')) try: for name,(a,b) in M.items(): assert orig.count(a)==1, name open(src,'w').write(orig.replace(a,b)) r=subprocess.run(['node','--test',*files],cwd=W,env=env,capture_output=True,text=True,timeout=300) fails=[l for l in r.stdout.splitlines() if l.startswith('✖') and 'failing tests' not in l] print(name, 'KILLED' if r.returncode!=0 else 'SURVIVED', 'rc=%d'%r.returncode, '| '+' | '.join(sorted(set(fails)))[:400]) open(os.path.expanduser(f'~/dewey-scratch/r136/mut/{name}.log'),'w').write(r.stdout+r.stderr) finally: open(src,'w').write(orig) print('restored', open(src).read()==orig)