Include the current addon, terrain integrations, tools, regression tests and recorded development evidence.
59 lines
2.7 KiB
Python
59 lines
2.7 KiB
Python
"""Execute actual parser/guard/emission AST without launching any native process."""
|
|
import argparse
|
|
import ast
|
|
from pathlib import Path
|
|
from types import SimpleNamespace
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
tree = ast.parse((ROOT / 'tools/headless_workbench.py').read_text())
|
|
parser = argparse.ArgumentParser()
|
|
registration = [n for n in tree.body if isinstance(n, ast.Expr) and isinstance(n.value, ast.Call)
|
|
and n.value.args and isinstance(n.value.args[0], ast.Constant)
|
|
and n.value.args[0].value == '--mine-stock']
|
|
assert len(registration) == 1
|
|
exec(compile(ast.Module(body=registration, type_ignores=[]), '<mine option>', 'exec'), {'p': parser})
|
|
assert not parser.parse_args([]).mine_stock
|
|
assert parser.parse_args(['--mine-stock']).mine_stock
|
|
selected = [n for n in tree.body if isinstance(n, ast.If) and ast.unparse(n.test) == 'a.mine_stock']
|
|
assert len(selected) == 2
|
|
validation = [n for n in selected if isinstance(n.body[0], ast.If)]
|
|
emission = [n for n in selected if isinstance(n.body[0], ast.AugAssign)]
|
|
assert len(validation) == len(emission) == 1
|
|
validate = compile(ast.Module(body=validation, type_ignores=[]), '<mine guard>', 'exec')
|
|
emit = compile(ast.Module(body=emission, type_ignores=[]), '<mine flag>', 'exec')
|
|
|
|
class Refused(Exception):
|
|
pass
|
|
|
|
class Parser:
|
|
def error(self, reason):
|
|
raise Refused(reason)
|
|
|
|
def options(**changes):
|
|
values = dict(mine_stock=True, smoke='mounted-ammo', project='chat', rounds=1,
|
|
timeout=360, mounted_courier=False, mounted_swap_eligibility=False)
|
|
values.update(changes)
|
|
return SimpleNamespace(**values)
|
|
|
|
def accepted(a):
|
|
try:
|
|
exec(validate, {'a': a, 'p': Parser()})
|
|
return True
|
|
except Refused:
|
|
return False
|
|
|
|
assert accepted(options())
|
|
assert accepted(options(timeout=780))
|
|
for changes in (dict(smoke='victory'), dict(project='core'), dict(rounds=2), dict(rounds=0),
|
|
dict(timeout=359), dict(mounted_courier=True), dict(mounted_swap_eligibility=True),
|
|
dict(mounted_courier=True, mounted_swap_eligibility=True)):
|
|
assert not accepted(options(**changes)), changes
|
|
# The disabled observer must impose no new scope requirement on other tests.
|
|
assert accepted(options(mine_stock=False, smoke='victory', project='core', rounds=2, timeout=60,
|
|
mounted_courier=True, mounted_swap_eligibility=True))
|
|
for enabled in (False, True):
|
|
command = ['existing', '-errSmokeOutcome', 'mounted-ammo']
|
|
exec(emit, {'a': options(mine_stock=enabled), 'command': command})
|
|
assert command == ['existing', '-errSmokeOutcome', 'mounted-ammo'] + (['-errMineStock', '1'] if enabled else [])
|
|
print('Native finite mine-stock runner: parser, scope, exclusions and command pass')
|