"""Run row-322 expected-red proofs, always restoring installer bytes.""" import hashlib import os from pathlib import Path import subprocess root = Path(__file__).resolve().parents[4] installer = root / 'scripts/case2-install.sh' logs = Path(__file__).resolve().parent fixed = installer.read_bytes() baseline = subprocess.check_output(['git', 'show', '094124b4e:scripts/case2-install.sh'], cwd=root) f8 = fixed.replace(b'$COPIES/$COMMIT/scripts/case2-persona-import.mjs', b'$REPO/scripts/case2-persona-import.mjs') assert f8 != fixed old_error = baseline.splitlines()[185] new_error = fixed.splitlines()[185] f9 = fixed.replace(new_error, old_error) assert f9 != fixed try: for label, source, pattern, failures in [ ('baseline-094124b4e', baseline, 'row 322', 2), ('mutant-F8', f8, 'row 322 F8', 1), ('mutant-F9', f9, 'row 322 F9', 1), ]: installer.write_bytes(source) result = subprocess.run([ 'timeout', '-k', '10', '90', 'node', '--test', '--test-reporter=tap', f'--test-name-pattern={pattern}', 'packages/cli/tests/case2-install.test.mjs', ], cwd=root, env=os.environ, text=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) (logs / f'{label}.log').write_text(result.stdout) print(f'{label}: exit {result.returncode}, expected failures {failures}', flush=True) assert result.returncode == 1, result.stdout assert f'# fail {failures}\n' in result.stdout, result.stdout assert 'ERR_MODULE_NOT_FOUND' in result.stdout, result.stdout installer.write_bytes(fixed) assert installer.read_bytes() == fixed print('restored sha256 ' + hashlib.sha256(fixed).hexdigest(), flush=True) finally: installer.write_bytes(fixed) assert installer.read_bytes() == fixed