refactor(backend)!: separate algorithm and data layers
Reorganize algorithm packages by business responsibility, move orchestration into services, and keep database access behind pooled repositories. Harden analysis API validation, remove unsafe legacy simulation endpoints, and add regression and architecture boundary coverage. BREAKING CHANGE: legacy algorithm module paths and obsolete simulation endpoints are removed.
This commit is contained in:
@@ -8,7 +8,7 @@ import pytest
|
||||
from fastapi import HTTPException
|
||||
|
||||
from app.api.v1.endpoints.timeseries import composite as composite_endpoint
|
||||
from app.infra.db.timescaledb import composite_queries
|
||||
from app.services import timeseries_analysis as composite_queries
|
||||
|
||||
|
||||
class _FakeTimescaleConnection:
|
||||
@@ -57,7 +57,7 @@ def test_clean_scada_uses_current_project_metadata(monkeypatch):
|
||||
)
|
||||
|
||||
result = asyncio.run(
|
||||
composite_queries.CompositeQueries.clean_scada_data(
|
||||
composite_queries.TimeseriesAnalysisService.clean_scada_data(
|
||||
_FakeTimescaleConnection(),
|
||||
object(),
|
||||
["fengyang-pressure-1"],
|
||||
@@ -85,7 +85,7 @@ def test_clean_scada_rejects_devices_missing_from_project_metadata(monkeypatch):
|
||||
|
||||
with pytest.raises(ValueError, match="缺少元数据"):
|
||||
asyncio.run(
|
||||
composite_queries.CompositeQueries.clean_scada_data(
|
||||
composite_queries.TimeseriesAnalysisService.clean_scada_data(
|
||||
_FakeTimescaleConnection(),
|
||||
_FakeTimescaleConnection(),
|
||||
["fengyang-pressure-1"],
|
||||
@@ -132,7 +132,7 @@ def test_clean_scada_rejects_zero_database_updates(monkeypatch):
|
||||
|
||||
with pytest.raises(ValueError, match="未产生任何数据库更新"):
|
||||
asyncio.run(
|
||||
composite_queries.CompositeQueries.clean_scada_data(
|
||||
composite_queries.TimeseriesAnalysisService.clean_scada_data(
|
||||
_FakeTimescaleConnection(),
|
||||
object(),
|
||||
["fengyang-pressure-1"],
|
||||
@@ -176,7 +176,7 @@ def test_clean_scada_propagates_write_failures(monkeypatch):
|
||||
|
||||
with pytest.raises(RuntimeError, match="database write failed"):
|
||||
asyncio.run(
|
||||
composite_queries.CompositeQueries.clean_scada_data(
|
||||
composite_queries.TimeseriesAnalysisService.clean_scada_data(
|
||||
_FakeTimescaleConnection(),
|
||||
object(),
|
||||
["fengyang-pressure-1"],
|
||||
@@ -188,7 +188,7 @@ def test_clean_scada_propagates_write_failures(monkeypatch):
|
||||
|
||||
def test_clean_scada_endpoint_returns_http_400_for_validation_error(monkeypatch):
|
||||
monkeypatch.setattr(
|
||||
composite_endpoint.CompositeQueries,
|
||||
composite_endpoint.TimeseriesAnalysisService,
|
||||
"clean_scada_data",
|
||||
AsyncMock(side_effect=ValueError("当前项目没有可清洗的 SCADA 设备")),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user