rebuild(migration): validate local legacy cutover

This commit is contained in:
leefer
2026-07-30 17:26:15 +08:00
parent 37bd9fea85
commit 198806c1bd
23 changed files with 418 additions and 27 deletions
+31
View File
@@ -21,6 +21,7 @@ from backend.database.connection import Database
from backend.database.migrations import MIGRATIONS, MigrationRunner
from backend.features.market.events import MarketEventService, apply_event_revisions
from backend.features.market.snapshot import build_realtime_inputs, build_snapshot
from backend.http.errors import AppError
from backend.jobs.repository import JobRepository
from backend.jobs.service import JobAlreadyRunning, JobService
from tests.support import run_scenario
@@ -108,6 +109,36 @@ def test_job_service_records_success_failure_attempts_and_exclusion(tmp_path) ->
)
def test_job_service_exposes_app_error_message_without_internal_tuple(tmp_path) -> None:
database = Database(tmp_path / "jobs.db")
MigrationRunner(database).upgrade(MIGRATIONS)
jobs = JobService(database, JobRepository())
with pytest.raises(AppError):
jobs.execute(
kind="market.refresh",
run_key="2026-07-30:failed",
requested_date="2026-07-30",
trigger="administrator",
operation=lambda: (_ for _ in ()).throw(
AppError("market_data_unavailable", "收盘行情读取失败,已保留原有快照", 503)
),
stale_after_seconds=120,
)
assert jobs.latest()[0]["error_message"] == "收盘行情读取失败,已保留原有快照"
with database.transaction() as connection:
connection.execute(
"UPDATE job_runs SET error_message = ? WHERE id = ?",
(
"('market_data_unavailable', '收盘行情读取失败,已保留原有快照', 503)",
jobs.latest()[0]["id"],
),
)
assert jobs.latest()[0]["error_message"] == "收盘行情读取失败,已保留原有快照"
class EventGateway:
reason = "银行板块走强"