aee0f09db8
- Datafabrik: Dockerfile fix, agentorkestrering fungerar - Vision: Identify-modell, FAISS, OCR alla testade - API: Alla 7 integrationstester passerade - Upplösare: Entitetsupplösning verifierad
79 lines
2.6 KiB
Python
79 lines
2.6 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Chaos Testing - Testa hela kedjan med simulerade scenarion
|
|
"""
|
|
import sys
|
|
sys.path.insert(0, '/home/bernt/.openclaw/workspace/life-weather')
|
|
|
|
from pipeline_v2 import WeatherPipelineV2
|
|
from state_engine import StateEngine, RealityState
|
|
|
|
class ChaosProvider:
|
|
"""Simulerad väderprovider för testing"""
|
|
|
|
SCENARIOS = {
|
|
"NORMAL": {"temp": 22, "precip": 0, "wind": 5},
|
|
"HEAVY_RAIN": {"temp": 15, "precip": 25, "wind": 10},
|
|
"STORM": {"temp": 12, "precip": 15, "wind": 25},
|
|
"SNOW": {"temp": -3, "precip": 5, "wind": 8},
|
|
"ICE": {"temp": -5, "precip": 0, "wind": 5},
|
|
"HEAT": {"temp": 35, "precip": 0, "wind": 3},
|
|
"FLOOD": {"temp": 18, "precip": 50, "wind": 15},
|
|
}
|
|
|
|
def __init__(self, scenario="NORMAL"):
|
|
self.scenario = scenario
|
|
self.data = self.SCENARIOS.get(scenario, self.SCENARIOS["NORMAL"])
|
|
|
|
def get_current_weather(self):
|
|
return {
|
|
"timestamp": "2026-07-04T15:00:00",
|
|
"station_id": "TEST",
|
|
"temperature": {"value": self.data["temp"], "unit": "celsius"},
|
|
"precipitation": {"value": self.data["precip"], "unit": "mm"},
|
|
"wind": {"value": self.data["wind"], "unit": "m/s"}
|
|
}
|
|
|
|
def run_chaos_test():
|
|
"""Kör alla scenarion"""
|
|
print("="*60)
|
|
print("CHAOS TESTING")
|
|
print("="*60)
|
|
|
|
state_engine = StateEngine()
|
|
|
|
for scenario_name, data in ChaosProvider.SCENARIOS.items():
|
|
print(f"\n--- Scenario: {scenario_name} ---")
|
|
|
|
# Skapa pipeline med test-provider
|
|
pipeline = WeatherPipelineV2()
|
|
pipeline.provider = ChaosProvider(scenario_name)
|
|
|
|
# Kör för väg 1
|
|
result = pipeline.run_for_road(road_id=1, road_type="primary")
|
|
|
|
# Beräkna state
|
|
risks = result["profile"]["risks"]
|
|
state = state_engine.calculate_state(risks)
|
|
|
|
print(f" Temp: {data['temp']}°C, Precip: {data['precip']}mm, Wind: {data['wind']}m/s")
|
|
print(f" Risker: {len(risks)}")
|
|
for risk in risks:
|
|
print(f" - {risk['type']}: {risk['severity']}")
|
|
print(f" State: {state.value}")
|
|
print(f" Events: {len(result['events'])}")
|
|
print(f" Missions: {len(result['missions'])}")
|
|
|
|
# Verifiera state-övergång
|
|
if risks:
|
|
assert state != RealityState.NORMAL, f"{scenario_name} ska inte vara NORMAL"
|
|
|
|
print(f" ✅ {scenario_name} OK")
|
|
|
|
print("\n" + "="*60)
|
|
print("ALLA CHAOS TESTER KLARA")
|
|
print("="*60)
|
|
|
|
if __name__ == "__main__":
|
|
run_chaos_test()
|