This commit is contained in:
Team3
2026-07-05 13:07:12 +02:00
parent 6a765b7d89
commit fb3e967fdb
7 changed files with 122 additions and 57 deletions

View File

@@ -25,7 +25,7 @@ async def test_hedge_zwilling_rettet_stall(monkeypatch):
monkeypatch.setattr(pipeline, "run_agent", fake_agent)
monkeypatch.setattr(pipeline, "kill_process", lambda k: killed.append(k))
monkeypatch.setattr(pipeline, "_HEDGE_NACH_S", 0.05)
res = await pipeline._race("t", "Test", [_slot()], 1, 60, "claude")
res = await pipeline._race("t", "Test", [_slot()], 1, 0.1, "claude")
assert res == ["zwilling"]
assert calls == ["k1", "k1-h"]
assert "k1" in killed # das hängende Original läuft nicht weiter
@@ -43,7 +43,7 @@ async def test_hedge_original_gewinnt_zwilling_wird_gekillt(monkeypatch):
monkeypatch.setattr(pipeline, "run_agent", fake_agent)
monkeypatch.setattr(pipeline, "kill_process", lambda k: killed.append(k))
monkeypatch.setattr(pipeline, "_HEDGE_NACH_S", 0.05)
res = await pipeline._race("t", "Test", [_slot()], 1, 60, "claude")
res = await pipeline._race("t", "Test", [_slot()], 1, 0.1, "claude")
assert res == ["k1"]
assert "k1-h" in killed
@@ -59,7 +59,25 @@ async def test_hedge_aus_bei_null(monkeypatch):
monkeypatch.setattr(pipeline, "run_agent", fake_agent)
monkeypatch.setattr(pipeline, "_HEDGE_NACH_S", 0)
res = await pipeline._race("t", "Test", [_slot()], 1, 60, "claude")
res = await pipeline._race("t", "Test", [_slot()], 1, 0.1, "claude")
assert res == ["ok"]
assert calls == ["k1"]
async def test_hedge_schwelle_skaliert_mit_timeout(monkeypatch):
"""Die Schwelle ist max(HEDGE_NACH_S, timeout/2): ein gesunder Call, der länger als
die Untergrenze, aber kürzer als das halbe Timeout läuft, bekommt KEINEN Zwilling
(pauschale 90 s hedgten jeden normalen Fix-Call)."""
calls = []
async def fake_agent(key, prompt, timeout, **kw):
calls.append(key)
await asyncio.sleep(0.15) # > Untergrenze 0.05, < timeout/2 = 0.5
return (0, "ok", "")
monkeypatch.setattr(pipeline, "run_agent", fake_agent)
monkeypatch.setattr(pipeline, "_HEDGE_NACH_S", 0.05)
res = await pipeline._race("t", "Test", [_slot()], 1, 1.0, "claude")
assert res == ["ok"]
assert calls == ["k1"]
@@ -133,6 +151,6 @@ async def test_hedge_zwilling_ersetzt_restart(monkeypatch):
monkeypatch.setattr(pipeline, "run_agent", fake_agent)
monkeypatch.setattr(pipeline, "kill_process", lambda k: None)
monkeypatch.setattr(pipeline, "_HEDGE_NACH_S", 0.05)
res = await pipeline._race("t", "Test", [_slot()], 1, 60, "claude")
res = await pipeline._race("t", "Test", [_slot()], 1, 0.1, "claude")
assert res == ["zwilling"]
assert calls == ["k1", "k1-h"] # kein dritter Spawn