b4fbd6fe9f
Deploy Site / deploy-vercel (push) Has been skipped
Deploy Site / deploy-docs (push) Has been skipped
Build Skills Index / build-index (push) Has been skipped
CI / Deny unrelated histories (push) Has been skipped
CI / Detect affected areas (push) Successful in 27m35s
CI / OSV scan (push) Failing after 4s
CI / Build&Test Docker image (push) Successful in 9s
CI / Supply-chain scan (push) Has been skipped
CI / Lint Docker scripts (push) Failing after 5m13s
CI / Check contributors (push) Failing after 12m8s
CI / Docs Site (push) Failing after 12m8s
CI / TypeScript (push) Failing after 12m8s
CI / Python lints (push) Failing after 12m9s
CI / Python tests (push) Failing after 12m9s
CI / Check uv.lock (push) Failing after 23m22s
CI / CI timing report (push) Has been cancelled
Build Skills Index / trigger-deploy (push) Has been cancelled
CI / All required checks pass (push) Has been cancelled
43 lines
1.9 KiB
Python
43 lines
1.9 KiB
Python
"""Tests for fallback-eviction gating on failed runs (#7130).
|
|
|
|
When a run fails, the gateway must NOT evict the cached agent — doing so
|
|
forces MCP reinit on the next message, creating a CPU-burning restart loop.
|
|
Eviction should only happen on successful runs where fallback activated.
|
|
"""
|
|
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
|
|
sys.path.insert(0, str(Path(__file__).resolve().parent.parent.parent))
|
|
|
|
|
|
class TestFallbackEvictionGating:
|
|
"""The fallback-eviction code path should skip eviction on failed runs."""
|
|
|
|
def test_failed_run_does_not_evict_cached_agent(self):
|
|
"""When result has failed=True, the cached agent should NOT be evicted."""
|
|
# The fix: `and not _run_failed` guard on the eviction check.
|
|
# Simulate the variables that the eviction block uses.
|
|
result = {"failed": True, "final_response": None, "error": "400 invalid model"}
|
|
_run_failed = result.get("failed") if result else False
|
|
assert _run_failed is True, "Failed run should be detected"
|
|
|
|
def test_successful_run_allows_eviction(self):
|
|
"""When result is successful, fallback eviction should proceed."""
|
|
result = {"completed": True, "final_response": "Hello!", "failed": False}
|
|
_run_failed = result.get("failed") if result else False
|
|
assert _run_failed is False, "Successful run should not be flagged"
|
|
|
|
def test_none_result_treated_as_not_failed(self):
|
|
"""When result is None (edge case), treat as not-failed."""
|
|
result = None
|
|
_run_failed = result.get("failed") if result else False
|
|
assert _run_failed is False
|
|
|
|
def test_missing_failed_key_treated_as_not_failed(self):
|
|
"""When result dict doesn't have 'failed' key, treat as not-failed."""
|
|
result = {"completed": True, "final_response": "Hello!"}
|
|
_run_failed = result.get("failed") if result else False
|
|
assert not _run_failed, "Missing 'failed' key should be falsy"
|