"""Standalone simulated reviewer. Does not import Member 1's code.""" import argparse import ast import difflib import json from pathlib import Path import re def main(): p = argparse.ArgumentParser(description=__doc__) p.add_argument('--input', required=True) p.add_argument('--source-commit', required=True) p.add_argument('--out-dir', required=True) p.add_argument('--case', choices=['good', 'rejected', 'error', 'runtime'], default='good') a = p.parse_args() out = Path(a.out_dir) try: out.mkdir(parents=True, exist_ok=False) except OSError: p.exit(3, 'A fresh writable output directory is required\n') data = dict(source_commit=a.source_commit, model_id='fixture-model', mode='fixture', status='error', summary='', diff='', input_tokens=24, output_tokens=8) result = 3 try: if not re.fullmatch('[0-9a-f]{40}', a.source_commit): raise ValueError('Full SHA required') source = Path(a.input).read_text(encoding='utf-8') if a.case == 'error': raise RuntimeError('Simulated operational error') if a.case == 'rejected': data.update(status='rejected', summary='Simulated rejected proposal') result = 2 else: if a.case == 'runtime': candidate = 'raise RuntimeError("fixture")\n' status = 'corrected' else: try: ast.parse(source) candidate, status = source, 'unchanged' data.update(input_tokens=None, output_tokens=None) except SyntaxError: if source not in ['print("hello"', 'print("hello"\n']: data.update(status='rejected', summary='Unsupported fixture') (out / 'review.json').write_text(json.dumps(data, indent=2)+'\n') return 2 candidate = source.rstrip('\n') + ')' + ('\n' if source.endswith('\n') else '') status = 'corrected' data.update(status=status, summary=f'SIMULATED {a.case} fixture; not live AI evidence', diff=''.join(difflib.unified_diff(source.splitlines(True), candidate.splitlines(True), fromfile='original.py', tofile='reviewed.py'))) (out / 'reviewed.py').write_text(candidate, encoding='utf-8') result = 0 except Exception as exc: data['summary'] = f'Simulated fixture failure: {type(exc).__name__}' (out / 'reviewed.py').unlink(missing_ok=True) (out / 'review.json').write_text(json.dumps(data, indent=2)+'\n', encoding='utf-8') return result if __name__ == '__main__': raise SystemExit(main())