接入 Cloudflare 免费能力并修正跑道日高

This commit is contained in:
2569718930@qq.com
2026-06-16 03:59:01 +08:00
parent 7756b137a2
commit f9d3fc2d96
12 changed files with 342 additions and 5 deletions
+34
View File
@@ -18,6 +18,13 @@ def test_frontend_dockerfile_uses_standalone_multistage_runtime():
assert "CMD [\"node\", \"server.js\"]" in dockerfile
def test_frontend_dockerfile_accepts_turnstile_site_key_build_arg():
dockerfile = (ROOT / "frontend" / "Dockerfile").read_text(encoding="utf-8")
assert "ARG NEXT_PUBLIC_TURNSTILE_SITE_KEY" in dockerfile
assert "ENV NEXT_PUBLIC_TURNSTILE_SITE_KEY=$NEXT_PUBLIC_TURNSTILE_SITE_KEY" in dockerfile
def test_nginx_proxy_buffers_cover_supabase_auth_cookies():
nginx_conf = (ROOT / "deploy" / "nginx" / "polyweather.conf").read_text(
encoding="utf-8"
@@ -136,6 +143,26 @@ def test_docker_compose_isolates_collector_from_web_and_bot_services():
assert "POLYWEATHER_OBSERVATION_COLLECTOR_MADIS_SEC: ${POLYWEATHER_OBSERVATION_COLLECTOR_MADIS_SEC:-300}" in collector_block
def test_docker_compose_exposes_cloudflare_free_runtime_env():
compose = (ROOT / "docker-compose.yml").read_text(encoding="utf-8")
frontend_block = compose.split(" polyweather_frontend:", 1)[1].split(
"\n polyweather_web:",
1,
)[0]
web_block = compose.split(" polyweather_web:", 1)[1].split(
"\n polyweather_collector:",
1,
)[0]
assert "NEXT_PUBLIC_TURNSTILE_SITE_KEY: ${NEXT_PUBLIC_TURNSTILE_SITE_KEY:-}" in frontend_block
assert "POLYWEATHER_TURNSTILE_SECRET_KEY: ${POLYWEATHER_TURNSTILE_SECRET_KEY:-}" in frontend_block
assert "POLYWEATHER_TURNSTILE_BYPASS: ${POLYWEATHER_TURNSTILE_BYPASS:-false}" in frontend_block
assert "POLYWEATHER_R2_ACCOUNT_ID: ${POLYWEATHER_R2_ACCOUNT_ID:-}" in web_block
assert "POLYWEATHER_R2_BUCKET: ${POLYWEATHER_R2_BUCKET:-}" in web_block
assert "POLYWEATHER_R2_ACCESS_KEY_ID: ${POLYWEATHER_R2_ACCESS_KEY_ID:-}" in web_block
assert "POLYWEATHER_R2_SECRET_ACCESS_KEY: ${POLYWEATHER_R2_SECRET_ACCESS_KEY:-}" in web_block
def test_scan_terminal_backend_timeout_returns_before_next_proxy_abort():
import web.services.scan_terminal_config as scan_terminal_config
@@ -172,6 +199,13 @@ def test_deploy_workflow_applies_cloudflare_rules_when_token_is_available():
assert workflow.index("cloudflare-cache-rules:") < workflow.index("deploy:")
def test_deploy_workflow_passes_turnstile_site_key_to_frontend_build():
workflow = (ROOT / ".github" / "workflows" / "ci.yml").read_text(encoding="utf-8")
assert "NEXT_PUBLIC_TURNSTILE_SITE_KEY: ${{ secrets.NEXT_PUBLIC_TURNSTILE_SITE_KEY || '' }}" in workflow
assert '--build-arg "NEXT_PUBLIC_TURNSTILE_SITE_KEY=${NEXT_PUBLIC_TURNSTILE_SITE_KEY}"' in workflow
def test_probability_engine_uses_enriched_multi_model_snapshot():
source = (ROOT / "web" / "analysis_service.py").read_text(encoding="utf-8")
+35
View File
@@ -177,6 +177,41 @@ def test_wuhan_runway_high_uses_local_today_not_rolling_24h_history():
assert "Today's runway high / 今日跑道高点: 34.4°C" not in text
def test_runway_high_infers_local_today_when_payload_lacks_local_date():
text = _build_airport_status_message(
"shanghai",
{
"city": "shanghai",
"current": {"temp": 24.6},
"airport_current": {"max_so_far": 35.0, "max_temp_time": "15:00"},
"runway_plate_history": {
"17L/35R": [
{"time": "2026-06-15T07:00:00Z", "temp": 35.0},
{"time": "2026-06-15T19:43:00Z", "temp": 24.6},
],
},
"amos": {
"source": "amsc_awos",
"icao": "ZSPD",
"observation_time": "2026-06-15T19:43:00Z",
"runway_obs": {
"runway_pairs": [("17L", "35R")],
"temperatures": [(24.6, None)],
"point_temperatures": [
{"runway": "17L/35R", "tdz_temp": 24.2, "mid_temp": None, "end_temp": 24.6, "target_runway_max": 24.6},
],
},
},
},
28.0,
"03:43",
language="both",
)
assert "Today's runway high / 今日跑道高点: 24.6°C" in text
assert "Today's runway high / 今日跑道高点: 35.0°C" not in text
def test_telegram_slope_uses_settlement_endpoint_not_runway_max(monkeypatch):
import src.utils.telegram_push as telegram_push