fix(reboot): overlay live stockplatform freshness in slo scorecard
Some checks failed
CD Pipeline / workflow-shape (push) Successful in 0s
CD Pipeline / cancel-stale-cd (push) Has been skipped
CD Pipeline / tests (push) Successful in 59s
CD Pipeline / build-and-deploy (push) Successful in 4m37s
CD Pipeline / post-deploy-checks (push) Has been cancelled

This commit is contained in:
Your Name
2026-07-02 19:25:19 +08:00
parent 7aa196ba5a
commit dc32550f99
3 changed files with 252 additions and 1 deletions

View File

@@ -3,6 +3,7 @@ from __future__ import annotations
from fastapi import FastAPI
from fastapi.testclient import TestClient
from src.api.v1 import agents
from src.api.v1.agents import router
from src.services.reboot_auto_recovery_drill_preflight import (
load_latest_reboot_auto_recovery_drill_preflight,
@@ -45,7 +46,12 @@ def test_reboot_auto_recovery_slo_scorecard_loader_exposes_stockplatform_gate():
_assert_reboot_slo_payload(payload)
def test_reboot_auto_recovery_slo_scorecard_endpoint_returns_readback():
def test_reboot_auto_recovery_slo_scorecard_endpoint_returns_readback(monkeypatch):
monkeypatch.setattr(
agents,
"load_latest_stockplatform_public_api_runtime_readback",
_stockplatform_runtime_ready,
)
app = FastAPI()
app.include_router(router, prefix="/api/v1")
client = TestClient(app)
@@ -56,6 +62,59 @@ def test_reboot_auto_recovery_slo_scorecard_endpoint_returns_readback():
_assert_reboot_slo_payload(response.json())
def test_reboot_auto_recovery_slo_scorecard_endpoint_overlays_live_stockplatform_blocked(
monkeypatch,
):
monkeypatch.setattr(
agents,
"load_latest_stockplatform_public_api_runtime_readback",
_stockplatform_runtime_blocked,
)
app = FastAPI()
app.include_router(router, prefix="/api/v1")
client = TestClient(app)
response = client.get("/api/v1/agents/reboot-auto-recovery-slo-scorecard")
assert response.status_code == 200
payload = response.json()
assert payload["stockplatform_freshness_status"] == "blocked"
assert payload["stockplatform_ingestion_status"] == "blocked"
assert payload["stockplatform_data_freshness"]["latest_trading_date"] == (
"2026-07-02"
)
assert payload["stockplatform_data_freshness"]["freshness_sla_source_count"] == 9
assert payload["stockplatform_data_freshness"]["freshness_blockers"] == [
"core_margin_short_daily_missing",
"ai_recommendations_stale",
]
assert payload["stockplatform_data_freshness"]["ingestion_blockers"] == [
"core.margin_short_daily_incomplete"
]
assert payload["product_data_green"] is False
assert payload["required_checks"]["stockplatform_freshness_ok"] is False
assert payload["required_checks"]["stockplatform_ingestion_ok"] is False
assert payload["required_checks"]["product_data_green"] is False
assert payload["readiness_percent"] == 21
assert payload["active_blocker_count"] == 15
assert "product_data_green_not_1" in payload["active_blockers"]
assert "stockplatform_freshness_core_margin_short_daily_missing" in payload[
"active_blockers"
]
assert "stockplatform_ingestion_core.margin_short_daily_incomplete" in payload[
"active_blockers"
]
assert payload["rollups"]["stockplatform_freshness_status"] == "blocked"
assert payload["rollups"]["stockplatform_freshness_sla_source_count"] == 9
assert payload["controlled_service_data_backup_readback"][
"product_data_green"
] is False
assert "stockplatform_freshness_status" in payload[
"controlled_service_data_backup_readback"
]["blocking_fields"]
assert payload["rollups"]["controlled_service_data_backup_blocker_count"] == 7
def test_reboot_auto_recovery_drill_preflight_loader_returns_break_glass_package():
payload = load_latest_reboot_auto_recovery_drill_preflight()
@@ -439,3 +498,50 @@ def _assert_drill_preflight_payload(payload: dict):
assert boundaries["github_api_used"] is False
assert boundaries["runtime_write_allowed"] is False
assert "host_reboot" in payload["forbidden_without_separate_break_glass"]
def _stockplatform_runtime_ready() -> dict:
return {
"schema_version": "stockplatform_public_api_runtime_readback_v1",
"status": "stockplatform_public_api_runtime_ready",
"runtime_ready": True,
"active_blockers": [],
"readback": {
"freshness_status": "ok",
"ingestion_status": "ok",
"freshness_latest_trading_date": "2026-07-02",
"ingestion_latest_trading_date": "2026-07-02",
"freshness_blockers": [],
"ingestion_blockers": [],
"freshness_sla_source_count": 9,
"freshness_source_count": 9,
"freshness_non_ok_source_count": 0,
},
}
def _stockplatform_runtime_blocked() -> dict:
return {
"schema_version": "stockplatform_public_api_runtime_readback_v1",
"status": "blocked_stockplatform_public_api_runtime_drift",
"runtime_ready": False,
"active_blockers": [
"stockplatform_freshness_core_margin_short_daily_missing",
"stockplatform_freshness_ai_recommendations_stale",
"stockplatform_ingestion_core.margin_short_daily_incomplete",
],
"readback": {
"freshness_status": "blocked",
"ingestion_status": "blocked",
"freshness_latest_trading_date": "2026-07-02",
"ingestion_latest_trading_date": "2026-07-02",
"freshness_blockers": [
"core_margin_short_daily_missing",
"ai_recommendations_stale",
],
"ingestion_blockers": ["core.margin_short_daily_incomplete"],
"freshness_sla_source_count": 9,
"freshness_source_count": 9,
"freshness_non_ok_source_count": 3,
},
}