"""Execute actual opt-in parsing, admission and flag emission without native launch.""" import argparse, ast, contextlib, io, os from pathlib import Path ROOT = Path(__file__).resolve().parents[1] p = Path(os.environ.get('ERR_RANDOM_RADIUS_RUNNER', ROOT / 'tools/headless_workbench.py')) tree = ast.parse(p.read_text()) declarations = [n for n in tree.body if isinstance(n, ast.Expr) and isinstance(n.value, ast.Call) and isinstance(n.value.func, ast.Attribute) and isinstance(n.value.func.value, ast.Name) and n.value.func.value.id == 'p' and n.value.func.attr == 'add_argument'] selected = [n for n in tree.body if isinstance(n, ast.If) and any(isinstance(v, ast.Attribute) and v.attr == 'trace_random_radius' for v in ast.walk(n.test))] guards = [n for n in selected if any(isinstance(v, ast.Call) and isinstance(v.func, ast.Attribute) and v.func.attr == 'error' for v in ast.walk(n))] emissions = [n for n in selected if isinstance(n.body[0], ast.AugAssign)] assert len(guards) == len(emissions) == 1 # Refusal must precede file-system/process setup. resolve = next(n.lineno for n in tree.body if isinstance(n, ast.Assign) and isinstance(n.targets[0], ast.Tuple) and any(isinstance(v, ast.Name) and v.id == 'compat' for v in ast.walk(n.targets[0]))) assert guards[0].lineno < resolve parser = argparse.ArgumentParser() exec(compile(ast.Module(body=declarations, type_ignores=[]), str(p), 'exec'), {'p': parser, 'Path': Path}) base = ['--compat','/tmp/erri-unused-radius-prefix','--profile','/tmp/erri-unused-radius-profile'] assert not parser.parse_args(base).trace_random_radius validate = compile(ast.Module(body=guards, type_ignores=[]), str(p), 'exec') emit = compile(ast.Module(body=emissions, type_ignores=[]), str(p), 'exec') def check(enabled=True, smoke='normal-escape-route', project='chat', rounds=1, timeout=420): a = parser.parse_args(base + ['--smoke',smoke,'--project',project,'--rounds',str(rounds),'--timeout',str(timeout)] + (['--trace-random-radius'] if enabled else [])) try: with contextlib.redirect_stderr(io.StringIO()): exec(validate, {'a': a, 'p': parser}) except SystemExit as e: assert e.code == 2 return False command = ['existing','-errSmokeOutcome',smoke] exec(emit, {'a': a, 'command': command}) assert command == ['existing','-errSmokeOutcome',smoke] + (['-errTraceRandomRadius','1'] if enabled else []) return True assert check() and check(timeout=600) for changes in [dict(smoke='victory'),dict(project='core'),dict(rounds=0),dict(rounds=2),dict(timeout=419)]: assert not check(**changes), changes assert check(enabled=False,smoke='victory',project='core',rounds=2,timeout=60) print('PASS: zero-radius trace disabled by default, scoped before setup, exact opt-in emission; no native launch')