fix(i-c): BUG-036 behoben — Workflow-Instances GET lieferte 500 auf jeden Aufruf (Route übergab user_id/is_system_admin die die Service-Signatur nicht akzeptierte → TypeError); Service um optionale User-Filterung erweitert (Nicht-Admins sehen nur eigene Instanzen via initiated_by, Admins alle); Beweistest test_bug036_instances.py 2/2 grün

This commit is contained in:
Agent Zero
2026-08-24 21:16:08 +02:00
parent d9aed519f2
commit 84a30d85c2
3 changed files with 48 additions and 2 deletions
+12 -1
View File
@@ -401,14 +401,25 @@ async def list_instances(
page: int = 1, page: int = 1,
page_size: int = 20, page_size: int = 20,
status_filter: str | None = None, status_filter: str | None = None,
user_id: uuid.UUID | None = None,
is_system_admin: bool = False,
) -> dict[str, Any]: ) -> dict[str, Any]:
"""List workflow instances with optional status filter.""" """List workflow instances with optional status filter.
BUG-036 fix: the route passed ``user_id``/``is_system_admin`` which this
signature did not accept -> TypeError -> 500 on every call.
Non-admin users see only instances they initiated; admins/system admins
see all instances of the tenant.
"""
page = max(1, page) page = max(1, page)
page_size = max(1, min(100, page_size)) page_size = max(1, min(100, page_size))
base = select(WorkflowInstance).where(WorkflowInstance.tenant_id == tenant_id) base = select(WorkflowInstance).where(WorkflowInstance.tenant_id == tenant_id)
if status_filter: if status_filter:
base = base.where(WorkflowInstance.status == status_filter) base = base.where(WorkflowInstance.status == status_filter)
if not is_system_admin and user_id is not None:
base = base.where(WorkflowInstance.initiated_by == user_id)
count_q = select(func.count()).select_from(base.subquery()) count_q = select(func.count()).select_from(base.subquery())
total_result = await db.execute(count_q) total_result = await db.execute(count_q)
+1 -1
View File
@@ -353,7 +353,7 @@ Jeder Bug wird wie folgt dokumentiert:
- **Response:** `{"code":"internal_error","detail":"Internal server error","trace_id":"bbdf0698"}` - **Response:** `{"code":"internal_error","detail":"Internal server error","trace_id":"bbdf0698"}`
- **Schweregrad:** High - **Schweregrad:** High
- **Ursache:** Unbekannt — muss Backend-Log prüfen - **Ursache:** Unbekannt — muss Backend-Log prüfen
- **Status:** ⏳ Nicht gefixt - **Status:** ✅ Gefixt 2026-08-24 (Block E/I-C): Root-Cause bewiesen — Route übergab user_id/is_system_admin an list_instances, Service-Signatur akzeptierte beide nicht → TypeError → 500 auf JEDEN Aufruf. Fix: Service-Signatur erweitert um optionale user_id/is_system_admin; Nicht-Admins sehen nur eigene Instanzen (initiated_by-Filter), Admins alle; agent_runner-Caller bleibt kompatibel. Beweistest test_bug036_instances.py 2/2 grün (200 plain + 200 mit status-filter); ruff clean.
### BUG-037: Compliance Incident POST gibt 500 Internal Server Error ### BUG-037: Compliance Incident POST gibt 500 Internal Server Error
- **Kategorie:** API - **Kategorie:** API
+35
View File
@@ -0,0 +1,35 @@
"""Tests for BUG-036 fix — GET /api/v1/workflows/instances returned 500.
Root cause: the route passed ``user_id``/``is_system_admin`` which the service
signature did not accept -> TypeError -> 500 on every call.
"""
from __future__ import annotations
import pytest
from tests.conftest import ORIGIN_HEADER, login_client, seed_tenant_and_users
@pytest.mark.asyncio
async def test_list_instances_returns_200(client, db_session):
"""GET /api/v1/workflows/instances must return 200 (was 500 before fix)."""
await seed_tenant_and_users(db_session)
await login_client(client, "admin@tenanta.com")
resp = await client.get("/api/v1/workflows/instances", headers=ORIGIN_HEADER)
assert resp.status_code == 200, resp.text
data = resp.json()
assert "items" in data and "total" in data
@pytest.mark.asyncio
async def test_list_instances_status_filter_returns_200(client, db_session):
"""Status filter variant also works after the signature fix."""
await seed_tenant_and_users(db_session)
await login_client(client, "admin@tenanta.com")
resp = await client.get(
"/api/v1/workflows/instances?status=running", headers=ORIGIN_HEADER
)
assert resp.status_code == 200, resp.text