62 lines
2.1 KiB
Python
62 lines
2.1 KiB
Python
"""Integration: el estado HITL sobrevive a un reinicio del proceso (checkpointing SQLite).
|
|
|
|
Tras una pausa ``awaiting_approval`` se descarta el ``TestClient`` (y con él las caches
|
|
DI en memoria) y se crea otro apuntando al mismo ``DATA_DIR``. El ``/approve`` posterior
|
|
debe encontrar la ejecución vía ``execution_index.json`` + ``checkpoints.sqlite`` y
|
|
reanudarla hasta ``completed``.
|
|
"""
|
|
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
EXAMPLES = (
|
|
Path(__file__).parent.parent.parent / "agents" / "incident_analyzer" / "examples"
|
|
)
|
|
|
|
|
|
@pytest.mark.integration
|
|
def test_resume_tras_recreacion_del_app(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
|
|
from fastapi.testclient import TestClient
|
|
|
|
from forja_core.api import deps
|
|
from forja_core.main import create_app
|
|
|
|
repo_root = Path(__file__).parent.parent.parent
|
|
monkeypatch.setenv("DATA_DIR", str(tmp_path))
|
|
monkeypatch.setenv("AGENTS_DIR", str(repo_root / "agents"))
|
|
monkeypatch.setenv("POLICIES_DIR", str(repo_root / "policies"))
|
|
monkeypatch.setenv("LLM_PROVIDER", "mock")
|
|
|
|
def _fresh() -> TestClient:
|
|
for fn in (
|
|
deps.get_settings,
|
|
deps.get_registry,
|
|
deps.get_policy_store,
|
|
deps.get_orchestrator,
|
|
deps.get_llm_provider,
|
|
deps.get_guardrail_engine,
|
|
):
|
|
fn.cache_clear()
|
|
return TestClient(create_app())
|
|
|
|
payload = (EXAMPLES / "01_sip_registration_drop.txt").read_text(encoding="utf-8")
|
|
|
|
# 1) Primera "ejecución" del core: invoca y queda en awaiting_approval.
|
|
client_a = _fresh()
|
|
r = client_a.post("/api/agents/incident_analyzer/invoke", json={"input": payload})
|
|
body = r.json()
|
|
assert body["status"] == "awaiting_approval"
|
|
trace_id = body["trace_id"]
|
|
pending = [a["id"] for a in body["needs_human_for"]]
|
|
client_a.close()
|
|
|
|
# 2) Recreamos el app (simula restart del contenedor) — DATA_DIR persiste.
|
|
client_b = _fresh()
|
|
r2 = client_b.post(
|
|
f"/api/executions/{trace_id}/approve",
|
|
json={"approved_action_ids": pending},
|
|
)
|
|
assert r2.status_code == 200
|
|
assert r2.json()["status"] == "completed"
|