|
| 1 | +#!/usr/bin/env python3 |
| 2 | +"""Quick demo: run every contaminated case through the naive executor. |
| 3 | +
|
| 4 | +Usage: |
| 5 | + python run_demo.py |
| 6 | +
|
| 7 | +This shows what happens when action bundles are executed without a gate. |
| 8 | +Every contaminated case produces state corruption — that is the point. |
| 9 | +""" |
| 10 | + |
| 11 | +import json |
| 12 | +import pathlib |
| 13 | +import sys |
| 14 | + |
| 15 | +from sim.executor import Executor |
| 16 | +from sim.resources import ResourceManager |
| 17 | +from sim.logger import TraceLogger |
| 18 | + |
| 19 | + |
| 20 | +CASES_DIR = pathlib.Path(__file__).resolve().parent / "cases" |
| 21 | + |
| 22 | +DIVIDER = "-" * 60 |
| 23 | + |
| 24 | + |
| 25 | +def load_case(name: str) -> dict: |
| 26 | + with open(CASES_DIR / name) as f: |
| 27 | + return json.load(f) |
| 28 | + |
| 29 | + |
| 30 | +def run_one(name: str, bundle: dict) -> None: |
| 31 | + """Execute a single bundle with a fresh naive executor and print results.""" |
| 32 | + resources = ResourceManager() |
| 33 | + logger = TraceLogger() |
| 34 | + executor = Executor(resources=resources, logger=logger, gate=None) |
| 35 | + |
| 36 | + print(f"\n{DIVIDER}") |
| 37 | + print(f"CASE: {name}") |
| 38 | + print(f" operation : {bundle.get('operation_type')}") |
| 39 | + print(f" target : {bundle.get('target_resource')}") |
| 40 | + print(DIVIDER) |
| 41 | + |
| 42 | + result = executor.execute(bundle) |
| 43 | + |
| 44 | + print(f" result : {result}") |
| 45 | + print(f" trace len : {len(logger.get_trace())} events") |
| 46 | + |
| 47 | + # Show corruption indicators |
| 48 | + fs = resources.fs.snapshot() |
| 49 | + db = resources.db.snapshot() |
| 50 | + if fs: |
| 51 | + print(f" fs state : {json.dumps(fs, indent=2)[:200]}") |
| 52 | + if db: |
| 53 | + print(f" db state : {json.dumps(db, indent=2)[:200]}") |
| 54 | + |
| 55 | + |
| 56 | +def main(): |
| 57 | + print("=" * 60) |
| 58 | + print("EXECUTION BOUNDARY LAB — Naive Executor Demo") |
| 59 | + print("=" * 60) |
| 60 | + print() |
| 61 | + print("Running all contaminated cases WITHOUT a gate.") |
| 62 | + print("Each case demonstrates a different pre-positioning failure.") |
| 63 | + |
| 64 | + cases = sorted(CASES_DIR.glob("contaminated_case_*.json")) |
| 65 | + if not cases: |
| 66 | + print("ERROR: No contaminated case files found.", file=sys.stderr) |
| 67 | + sys.exit(1) |
| 68 | + |
| 69 | + for path in cases: |
| 70 | + bundle = load_case(path.name) |
| 71 | + run_one(path.stem, bundle) |
| 72 | + |
| 73 | + # Also run the clean case for comparison |
| 74 | + clean = CASES_DIR / "clean_case_1.json" |
| 75 | + if clean.exists(): |
| 76 | + bundle = load_case("clean_case_1.json") |
| 77 | + run_one("clean_case_1 (control)", bundle) |
| 78 | + |
| 79 | + print(f"\n{'=' * 60}") |
| 80 | + print("DONE. All cases above executed without gate intervention.") |
| 81 | + print("A conformant gate would HOLD or DENY the contaminated cases.") |
| 82 | + print(f"{'=' * 60}") |
| 83 | + |
| 84 | + |
| 85 | +if __name__ == "__main__": |
| 86 | + main() |
0 commit comments