Files
next-tjwater-server/tests/unit/test_peripheral_provenance.py
T
jiang 05183aff93
Generic Container CI/CD / test-build-publish (push) Successful in 3m53s
Server CI/CD v2 / build-test-publish-and-deploy (push) Successful in 3m52s
feat: extend operational investigation workflows
2026-10-30 17:30:19 +08:00

43 lines
1.9 KiB
Python

from types import SimpleNamespace
from uuid import uuid4
import httpx
import pytest
from app.auth.project_dependencies import ProjectContext
from app.domain.schemas.operational_data import TaskDataQuery
from app.infra.integrations.operational_data import TaskDataSettings, read_task_data
from app.mcp import peripheral
@pytest.fixture
def anyio_backend():
return "asyncio"
@pytest.mark.anyio
@pytest.mark.parametrize("origins", [
[], ["system_data"], ["synthetic"], ["system_data", "synthetic"], [None], ["unverified"],
])
async def test_http_and_mcp_normalize_work_orders_as_system_data(monkeypatch, origins):
project_id = uuid4()
items = [{"work_order_id": str(uuid4()), "project_id": str(project_id), "origin": origin} for origin in origins]
async def rows(*_args, **_kwargs):
return [{"document": item} for item in items]
monkeypatch.setattr(peripheral, "read_rows", rows)
query = TaskDataQuery(source="peripheral_work_orders")
context = ProjectContext(project_id=project_id, user_id=uuid4(), project_code="test", project_role="member")
kwargs = dict(context=context, credential="Bearer TEST_ONLY", query=query,
settings=TaskDataSettings(_env_file=None, peripheral_url="http://peripheral.test"),
transport=httpx.MockTransport(lambda _: httpx.Response(200, json={"items": items})))
scope = SimpleNamespace(connection=object(), project=SimpleNamespace(project_id=project_id))
args = SimpleNamespace(source=query.source, limit=20, offset=0)
snapshots = [await read_task_data(**kwargs), await peripheral.read_peripheral_query(scope, args)]
for snapshot in snapshots:
assert snapshot.origin == "system_data"
assert [item["origin"] for item in snapshot.data["items"]] == ["system_data"] * len(origins)
assert "provenance_scope" not in snapshot.data
assert "source_origins" not in snapshot.data