Scenarios
Scenarios (spx_core/system/scenarios.py) let you script temporary changes to your simulation: inject noise, disconnect protocols, or override values for a limited time. They are essential for fault-injection tests and QA workflows.
Configuration Example
scenarios:
voltage_spike:
enabled: true
duration: 2.0
actions:
- override:
target: "#attr(voltage)"
value: 400.0
run_limit: 1
ascii_disconnect:
enabled: true
schedule:
period: 30.0
jitter: 5.0
call:
path: communication.ascii.detach
stop_path: communication.ascii.attach{
"scenarios": {
"voltage_spike": {
"enabled": true,
"duration": 2.0,
"actions": [
{
"override": {
"target": "#attr(voltage)",
"value": 400.0
}
}
],
"run_limit": 1
},
"ascii_disconnect": {
"enabled": true,
"schedule": {
"period": 30.0,
"jitter": 5.0
},
"call": {
"path": "communication.ascii.detach",
"stop_path": "communication.ascii.attach"
}
}
}
}
Configuration fields
enabled
Scenario must be enabled to run.
duration
Seconds to stay active. Negative or null means run until stopped manually.
period
When set, the scenario schedules its own run loop independent of the model tick.
jitter
Random variation added to the period.
run_limit
Number of times the scenario can activate before disabling itself.
actions
Child actions to execute while active.
call.path
Method to call when the scenario starts.
call.stop_path
Method to call when the scenario stops (optional).
overrides
Mapping of attribute/protocol values to apply temporarily.
You can also nest a schedule block; fields inside it mirror top-level keys and are merged for backward compatibility.
Lifecycle
start()prepares children, sets timers, and, ifperiodis defined, spawns a dedicated scheduler thread.run()executes child components each model tick when no custom period is set.stop()cancels timers, cleans up overrides, and deactivates the scenario.
Common patterns
Protocol chaos: Use
call.pathto detach or attach communication adapters.Signal overrides: Apply transient
overrideactions to attributes and let them revert automatically when the scenario stops.Scheduled disturbances: Combine
periodandjitterfor recurring events (e.g., every 30 ±5 seconds).
Tips for junior engineers / QA
Start with small durations (1–2 s) to verify behavior, then scale up.
Watch the server logs; scenarios emit lifecycle messages and diagnostics for easier troubleshooting.
Combine scenarios with snapshots: capture the baseline, run scenarios, restore to baseline.
Document test cases alongside the scenario YAML so teammates know why each disturbance exists.
Last updated

