97 lines
3.1 KiB
Python
97 lines
3.1 KiB
Python
from __future__ import annotations
|
|
|
|
from dataclasses import replace
|
|
|
|
import pytest
|
|
from fastapi.testclient import TestClient
|
|
|
|
from ploop.api.app import create_app
|
|
from ploop.application.catalog_queries import CapabilityRangeProjection, PublicSutProjection
|
|
from ploop.application.control_plane_queries import PublicRunProjection
|
|
from ploop.domain.catalog.models import PublicDatasetProjection
|
|
from ploop.domain.evidence.models import PublicArtifactProjection
|
|
|
|
DATASET_ONE = {
|
|
"id": "dataset-1",
|
|
"dataset_key": "ploop-dev-synthetic",
|
|
"language": "en",
|
|
"case_count": 2,
|
|
"source_digest": "1" * 64,
|
|
"public_requests_digest": "2" * 64,
|
|
"manifest_digest": "3" * 64,
|
|
}
|
|
SUT_ONE = {"id": "sut-1", "adapter_key": "demo-keyword-rag", "status": "enabled"}
|
|
RUN_ONE = {
|
|
"id": "run-1",
|
|
"dataset_version_id": "dataset-1",
|
|
"sut_version_id": "sut-1",
|
|
"phase": "executing",
|
|
"status": "active",
|
|
"shard_count": 3,
|
|
"terminal_shard_count": 2,
|
|
"failed_shard_count": 1,
|
|
}
|
|
|
|
|
|
class FakeReadPort:
|
|
"""只替换外部数据存储,保留真实的路由、映射和分页逻辑供测试验证。"""
|
|
|
|
def __init__(self, count: int = 2, *, fail: bool = False) -> None:
|
|
self.fail = fail
|
|
dataset = PublicDatasetProjection(
|
|
"dataset-1", "ploop-dev-synthetic", "en", 2, "1" * 64, "2" * 64, "3" * 64
|
|
)
|
|
sut = PublicSutProjection(
|
|
"sut-1",
|
|
"demo-keyword-rag",
|
|
"enabled",
|
|
30,
|
|
1,
|
|
(CapabilityRangeProjection("top_k", 1, 3),),
|
|
)
|
|
run = PublicRunProjection("run-1", "dataset-1", "sut-1", "executing", "active", 3, 2, 1)
|
|
self.datasets = tuple(replace(dataset, id=f"dataset-{i}") for i in range(1, count + 1))
|
|
self.suts = tuple(replace(sut, id=f"sut-{i}") for i in range(1, count + 1))
|
|
self.runs = tuple(replace(run, id=f"run-{i}") for i in range(1, count + 1))
|
|
|
|
def _check(self) -> None:
|
|
if self.fail:
|
|
raise RuntimeError("secret /host/path")
|
|
|
|
def list_datasets(self) -> tuple[PublicDatasetProjection, ...]:
|
|
self._check()
|
|
return self.datasets
|
|
|
|
def get_dataset(self, dataset_version_id: str) -> PublicDatasetProjection:
|
|
self._check()
|
|
for item in self.datasets:
|
|
if item.id == dataset_version_id:
|
|
return item
|
|
raise KeyError("secret /host/path")
|
|
|
|
def list_dataset_public_artifacts(
|
|
self, dataset_version_id: str
|
|
) -> tuple[PublicArtifactProjection, ...]:
|
|
self.get_dataset(dataset_version_id)
|
|
return (PublicArtifactProjection("artifact-1", "public_request", "4" * 64, 42),)
|
|
|
|
def list_suts(self) -> tuple[PublicSutProjection, ...]:
|
|
self._check()
|
|
return self.suts
|
|
|
|
def get_sut(self, sut_version_id: str) -> PublicSutProjection:
|
|
self._check()
|
|
for item in self.suts:
|
|
if item.id == sut_version_id:
|
|
return item
|
|
raise KeyError("secret /host/path")
|
|
|
|
def list_runs(self) -> tuple[PublicRunProjection, ...]:
|
|
self._check()
|
|
return self.runs
|
|
|
|
|
|
@pytest.fixture
|
|
def client() -> TestClient:
|
|
return TestClient(create_app(FakeReadPort()))
|