cambios profundos
This commit is contained in:
@@ -12,7 +12,7 @@ EXAMPLES = (
|
||||
@pytest.mark.integration
|
||||
def test_happy_path_completa_sin_hitl(integration_client) -> None: # type: ignore[no-untyped-def]
|
||||
payload = (EXAMPLES / "02_mos_degradation_pool_sbc.txt").read_text(encoding="utf-8")
|
||||
r = integration_client.post("/agents/incident_analyzer/invoke", json={"input": payload})
|
||||
r = integration_client.post("/api/agents/incident_analyzer/invoke", json={"input": payload})
|
||||
assert r.status_code == 200
|
||||
body = r.json()
|
||||
assert body["status"] == "completed"
|
||||
|
||||
@@ -12,7 +12,7 @@ EXAMPLES = (
|
||||
@pytest.mark.integration
|
||||
def test_hitl_approve_completa(integration_client) -> None: # type: ignore[no-untyped-def]
|
||||
payload = (EXAMPLES / "01_sip_registration_drop.txt").read_text(encoding="utf-8")
|
||||
r = integration_client.post("/agents/incident_analyzer/invoke", json={"input": payload})
|
||||
r = integration_client.post("/api/agents/incident_analyzer/invoke", json={"input": payload})
|
||||
body = r.json()
|
||||
assert body["status"] == "awaiting_approval"
|
||||
assert body["needs_human_for"]
|
||||
@@ -20,7 +20,7 @@ def test_hitl_approve_completa(integration_client) -> None: # type: ignore[no-u
|
||||
pending = [a["id"] for a in body["needs_human_for"]]
|
||||
|
||||
r2 = integration_client.post(
|
||||
f"/executions/{trace_id}/approve",
|
||||
f"/api/executions/{trace_id}/approve",
|
||||
json={"approved_action_ids": pending, "comment": "OK rollback"},
|
||||
)
|
||||
assert r2.status_code == 200
|
||||
@@ -31,10 +31,10 @@ def test_hitl_approve_completa(integration_client) -> None: # type: ignore[no-u
|
||||
@pytest.mark.integration
|
||||
def test_hitl_reject_marca_failed(integration_client) -> None: # type: ignore[no-untyped-def]
|
||||
payload = (EXAMPLES / "01_sip_registration_drop.txt").read_text(encoding="utf-8")
|
||||
r = integration_client.post("/agents/incident_analyzer/invoke", json={"input": payload})
|
||||
r = integration_client.post("/api/agents/incident_analyzer/invoke", json={"input": payload})
|
||||
trace_id = r.json()["trace_id"]
|
||||
r2 = integration_client.post(
|
||||
f"/executions/{trace_id}/reject", json={"reason": "rollback no procede"}
|
||||
f"/api/executions/{trace_id}/reject", json={"reason": "rollback no procede"}
|
||||
)
|
||||
assert r2.status_code == 200
|
||||
assert r2.json()["status"] == "failed"
|
||||
|
||||
@@ -6,7 +6,7 @@ import pytest
|
||||
@pytest.mark.integration
|
||||
def test_pii_es_nif_bloquea(integration_client) -> None: # type: ignore[no-untyped-def]
|
||||
pii_input = "El cliente con NIF 12345678Z reporta caída de servicio. Email juan@example.com"
|
||||
r = integration_client.post("/agents/incident_analyzer/invoke", json={"input": pii_input})
|
||||
r = integration_client.post("/api/agents/incident_analyzer/invoke", json={"input": pii_input})
|
||||
assert r.status_code == 200
|
||||
body = r.json()
|
||||
assert body["status"] == "blocked_by_guardrail"
|
||||
|
||||
@@ -44,7 +44,7 @@ def test_resume_tras_recreacion_del_app(tmp_path: Path, monkeypatch: pytest.Monk
|
||||
|
||||
# 1) Primera "ejecución" del core: invoca y queda en awaiting_approval.
|
||||
client_a = _fresh()
|
||||
r = client_a.post("/agents/incident_analyzer/invoke", json={"input": payload})
|
||||
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"]
|
||||
@@ -54,7 +54,7 @@ def test_resume_tras_recreacion_del_app(tmp_path: Path, monkeypatch: pytest.Monk
|
||||
# 2) Recreamos el app (simula restart del contenedor) — DATA_DIR persiste.
|
||||
client_b = _fresh()
|
||||
r2 = client_b.post(
|
||||
f"/executions/{trace_id}/approve",
|
||||
f"/api/executions/{trace_id}/approve",
|
||||
json={"approved_action_ids": pending},
|
||||
)
|
||||
assert r2.status_code == 200
|
||||
|
||||
@@ -28,41 +28,41 @@ def patch_settings(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
|
||||
|
||||
def test_list_agents_incluye_incident_analyzer() -> None:
|
||||
r = TestClient(create_app()).get("/agents")
|
||||
r = TestClient(create_app()).get("/api/agents")
|
||||
assert r.status_code == 200
|
||||
assert any(a["name"] == "incident_analyzer" for a in r.json())
|
||||
|
||||
|
||||
def test_get_agent_activo_devuelve_v1() -> None:
|
||||
r = TestClient(create_app()).get("/agents/incident_analyzer")
|
||||
r = TestClient(create_app()).get("/api/agents/incident_analyzer")
|
||||
assert r.status_code == 200
|
||||
assert r.json()["version"] == "v1"
|
||||
|
||||
|
||||
def test_get_agent_inexistente_404() -> None:
|
||||
r = TestClient(create_app()).get("/agents/inexistente")
|
||||
r = TestClient(create_app()).get("/api/agents/inexistente")
|
||||
assert r.status_code == 404
|
||||
|
||||
|
||||
def test_list_versions_devuelve_meta() -> None:
|
||||
r = TestClient(create_app()).get("/agents/incident_analyzer/versions")
|
||||
r = TestClient(create_app()).get("/api/agents/incident_analyzer/versions")
|
||||
assert r.status_code == 200
|
||||
assert r.json()[0]["id"] == "v1"
|
||||
|
||||
|
||||
def test_get_version_concreta() -> None:
|
||||
r = TestClient(create_app()).get("/agents/incident_analyzer/versions/v1")
|
||||
r = TestClient(create_app()).get("/api/agents/incident_analyzer/versions/v1")
|
||||
assert r.status_code == 200
|
||||
assert r.json()["name"] == "incident_analyzer"
|
||||
|
||||
|
||||
def test_get_version_inexistente_404() -> None:
|
||||
r = TestClient(create_app()).get("/agents/incident_analyzer/versions/v999")
|
||||
r = TestClient(create_app()).get("/api/agents/incident_analyzer/versions/v999")
|
||||
assert r.status_code == 404
|
||||
|
||||
|
||||
def test_diff_misma_version_da_diff_vacio() -> None:
|
||||
r = TestClient(create_app()).get("/agents/incident_analyzer/versions/v1/diff/v1")
|
||||
r = TestClient(create_app()).get("/api/agents/incident_analyzer/versions/v1/diff/v1")
|
||||
assert r.status_code == 200
|
||||
body = r.json()
|
||||
assert body["from_version"] == "v1"
|
||||
|
||||
@@ -34,7 +34,7 @@ def client() -> TestClient:
|
||||
|
||||
|
||||
def test_invoke_devuelve_execution_completada(client: TestClient) -> None:
|
||||
r = client.post("/agents/incident_analyzer/invoke", json={"input": "degradación MOS pool SBC"})
|
||||
r = client.post("/api/agents/incident_analyzer/invoke", json={"input": "degradación MOS pool SBC"})
|
||||
assert r.status_code == 200
|
||||
body = r.json()
|
||||
assert body["status"] == "completed"
|
||||
@@ -44,12 +44,12 @@ def test_invoke_devuelve_execution_completada(client: TestClient) -> None:
|
||||
|
||||
|
||||
def test_invoke_agente_inexistente_404(client: TestClient) -> None:
|
||||
r = client.post("/agents/inexistente/invoke", json={"input": "x"})
|
||||
r = client.post("/api/agents/inexistente/invoke", json={"input": "x"})
|
||||
assert r.status_code == 404
|
||||
|
||||
|
||||
def test_invoke_riesgo_alto_pausa_hitl(client: TestClient) -> None:
|
||||
r = client.post("/agents/incident_analyzer/invoke", json={"input": "caída registros sip"})
|
||||
r = client.post("/api/agents/incident_analyzer/invoke", json={"input": "caída registros sip"})
|
||||
assert r.status_code == 200
|
||||
body = r.json()
|
||||
assert body["status"] == "awaiting_approval"
|
||||
@@ -59,21 +59,21 @@ def test_invoke_riesgo_alto_pausa_hitl(client: TestClient) -> None:
|
||||
|
||||
def test_get_execution_existe_tras_invoke(client: TestClient) -> None:
|
||||
trace_id = client.post(
|
||||
"/agents/incident_analyzer/invoke", json={"input": "degradación MOS pool SBC"}
|
||||
"/api/agents/incident_analyzer/invoke", json={"input": "degradación MOS pool SBC"}
|
||||
).json()["trace_id"]
|
||||
r = client.get(f"/executions/{trace_id}")
|
||||
r = client.get(f"/api/executions/{trace_id}")
|
||||
assert r.status_code == 200
|
||||
assert r.json()["trace_id"] == trace_id
|
||||
|
||||
|
||||
def test_get_execution_inexistente_404(client: TestClient) -> None:
|
||||
r = client.get("/executions/00000000-0000-0000-0000-000000000000")
|
||||
r = client.get("/api/executions/00000000-0000-0000-0000-000000000000")
|
||||
assert r.status_code == 404
|
||||
|
||||
|
||||
def test_list_executions_incluye_la_completada(client: TestClient) -> None:
|
||||
client.post("/agents/incident_analyzer/invoke", json={"input": "degradación MOS pool SBC"})
|
||||
r = client.get("/executions")
|
||||
client.post("/api/agents/incident_analyzer/invoke", json={"input": "degradación MOS pool SBC"})
|
||||
r = client.get("/api/executions")
|
||||
assert r.status_code == 200
|
||||
rows = r.json()
|
||||
assert len(rows) == 1
|
||||
@@ -85,9 +85,9 @@ def test_list_executions_incluye_la_awaiting(client: TestClient) -> None:
|
||||
"""Una ejecución pausada en HITL no se escribe en el JSONL; aún así debe listarse
|
||||
(la página de Aprobaciones del dashboard depende de ello)."""
|
||||
trace_id = client.post(
|
||||
"/agents/incident_analyzer/invoke", json={"input": "caída registros sip"}
|
||||
"/api/agents/incident_analyzer/invoke", json={"input": "caída registros sip"}
|
||||
).json()["trace_id"]
|
||||
rows = client.get("/executions").json()
|
||||
rows = client.get("/api/executions").json()
|
||||
awaiting = [r for r in rows if r["trace_id"] == trace_id]
|
||||
assert len(awaiting) == 1
|
||||
assert awaiting[0]["status"] == "awaiting_approval"
|
||||
@@ -95,12 +95,12 @@ def test_list_executions_incluye_la_awaiting(client: TestClient) -> None:
|
||||
|
||||
def test_approve_resume_completa_ejecucion(client: TestClient) -> None:
|
||||
invoked = client.post(
|
||||
"/agents/incident_analyzer/invoke", json={"input": "caída registros sip"}
|
||||
"/api/agents/incident_analyzer/invoke", json={"input": "caída registros sip"}
|
||||
).json()
|
||||
trace_id = invoked["trace_id"]
|
||||
action_ids = [a["id"] for a in invoked["needs_human_for"]]
|
||||
r = client.post(
|
||||
f"/executions/{trace_id}/approve",
|
||||
f"/api/executions/{trace_id}/approve",
|
||||
json={"approved_action_ids": action_ids, "comment": "OK adelante"},
|
||||
)
|
||||
assert r.status_code == 200
|
||||
@@ -111,9 +111,9 @@ def test_approve_resume_completa_ejecucion(client: TestClient) -> None:
|
||||
|
||||
def test_reject_marca_failed(client: TestClient) -> None:
|
||||
trace_id = client.post(
|
||||
"/agents/incident_analyzer/invoke", json={"input": "caída registros sip"}
|
||||
"/api/agents/incident_analyzer/invoke", json={"input": "caída registros sip"}
|
||||
).json()["trace_id"]
|
||||
r = client.post(f"/executions/{trace_id}/reject", json={"reason": "no procede ahora"})
|
||||
r = client.post(f"/api/executions/{trace_id}/reject", json={"reason": "no procede ahora"})
|
||||
assert r.status_code == 200
|
||||
body = r.json()
|
||||
assert body["status"] == "failed"
|
||||
@@ -122,15 +122,15 @@ def test_reject_marca_failed(client: TestClient) -> None:
|
||||
|
||||
def test_approve_sobre_estado_no_pausado_da_409(client: TestClient) -> None:
|
||||
trace_id = client.post(
|
||||
"/agents/incident_analyzer/invoke", json={"input": "degradación MOS pool SBC"}
|
||||
"/api/agents/incident_analyzer/invoke", json={"input": "degradación MOS pool SBC"}
|
||||
).json()["trace_id"]
|
||||
r = client.post(f"/executions/{trace_id}/approve", json={"approved_action_ids": []})
|
||||
r = client.post(f"/api/executions/{trace_id}/approve", json={"approved_action_ids": []})
|
||||
assert r.status_code == 409
|
||||
|
||||
|
||||
def test_approve_trace_id_desconocido_da_404(client: TestClient) -> None:
|
||||
r = client.post(
|
||||
"/executions/11111111-1111-1111-1111-111111111111/approve",
|
||||
"/api/executions/11111111-1111-1111-1111-111111111111/approve",
|
||||
json={"approved_action_ids": []},
|
||||
)
|
||||
assert r.status_code == 404
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
"""Tests de los routers /policies y /violations."""
|
||||
"""Tests de los routers /api/policies y /api/violations."""
|
||||
|
||||
from datetime import UTC, datetime
|
||||
from pathlib import Path
|
||||
@@ -37,24 +37,24 @@ def client() -> TestClient:
|
||||
|
||||
|
||||
def test_list_policies_incluye_default(client: TestClient) -> None:
|
||||
r = client.get("/policies")
|
||||
r = client.get("/api/policies")
|
||||
assert r.status_code == 200
|
||||
assert any(p["name"] == "default" for p in r.json())
|
||||
|
||||
|
||||
def test_list_policy_versions(client: TestClient) -> None:
|
||||
r = client.get("/policies/default/versions")
|
||||
r = client.get("/api/policies/default/versions")
|
||||
assert r.status_code == 200
|
||||
assert r.json()[0]["id"] == "v1"
|
||||
|
||||
|
||||
def test_list_policy_versions_inexistente_404(client: TestClient) -> None:
|
||||
r = client.get("/policies/inexistente/versions")
|
||||
r = client.get("/api/policies/inexistente/versions")
|
||||
assert r.status_code == 404
|
||||
|
||||
|
||||
def test_violations_vacio_si_no_hay(client: TestClient) -> None:
|
||||
r = client.get("/violations")
|
||||
r = client.get("/api/violations")
|
||||
assert r.status_code == 200
|
||||
assert r.json() == []
|
||||
|
||||
@@ -75,11 +75,11 @@ def test_violations_lista_y_filtra(client: TestClient, tmp_path: Path) -> None:
|
||||
tid = uuid4()
|
||||
append_violation(tmp_path, _violation(tid, "DetectPII", "block", blocked=True))
|
||||
append_violation(tmp_path, _violation(uuid4(), "Schema", "warning", blocked=False))
|
||||
assert len(client.get("/violations").json()) == 2
|
||||
assert len(client.get("/violations", params={"severity": "block"}).json()) == 1
|
||||
assert len(client.get("/violations", params={"trace_id": str(tid)}).json()) == 1
|
||||
assert len(client.get("/api/violations").json()) == 2
|
||||
assert len(client.get("/api/violations", params={"severity": "block"}).json()) == 1
|
||||
assert len(client.get("/api/violations", params={"trace_id": str(tid)}).json()) == 1
|
||||
|
||||
|
||||
def test_violations_severity_invalida_422(client: TestClient) -> None:
|
||||
r = client.get("/violations", params={"severity": "nope"})
|
||||
r = client.get("/api/violations", params={"severity": "nope"})
|
||||
assert r.status_code == 422
|
||||
|
||||
Reference in New Issue
Block a user