Download src/oncallenv/simulation/scenario_compiler.py from NeerjaK/OnCallEnv: direct link, hf CLI and curl.
- Browser
- Download file 1.2 kB
-
https://huggingface.co/spaces/NeerjaK/OnCallEnv/resolve/main/src/oncallenv/simulation/scenario_compiler.py
- Command line
-
hf download hf://spaces/NeerjaK/OnCallEnv/src/oncallenv/simulation/scenario_compiler.py
-
curl -L -o scenario_compiler.py https://huggingface.co/spaces/NeerjaK/OnCallEnv/resolve/main/src/oncallenv/simulation/scenario_compiler.py
1.2 kB
| """Compile ScenarioSpec objects into simulator graphs.""" | |
| from __future__ import annotations | |
| from oncallenv.core.types import ScenarioSpec | |
| from oncallenv.simulation.faults import FAULTS | |
| from oncallenv.simulation.graph import MicroserviceGraph | |
| def compile_scenario(spec: ScenarioSpec) -> MicroserviceGraph: | |
| graph = MicroserviceGraph.topology(spec.topology) | |
| inject_service = spec.inject_service if spec.inject_service in graph.services else "payment-service" | |
| FAULTS[spec.fault_primary].apply(graph, inject_service) | |
| graph.get(inject_service).latency_p99 = max(graph.get(inject_service).latency_p99, float(spec.latency_ms)) | |
| if spec.fault_secondary: | |
| secondary_service = "redis-cache" if inject_service != "redis-cache" else "postgres-primary" | |
| FAULTS[spec.fault_secondary].apply(graph, secondary_service) | |
| if spec.red_herring: | |
| graph.get("user-service").logs.append(f"benign warning: {spec.red_herring}") | |
| if spec.deploy_window and spec.deploy_window != "none": | |
| graph.get(inject_service).deploy_history.append( | |
| {"version": "v3.3.0", "date": "2026-04-24", "status": "current", "notes": spec.deploy_window} | |
| ) | |
| return graph | |