74 lines
3.0 KiB
Python
74 lines
3.0 KiB
Python
from __future__ import annotations
|
|
|
|
|
|
def test_gateway_status_defaults_to_local_first_cn_safe(monkeypatch):
|
|
from scripts import vedastro_gateway
|
|
|
|
monkeypatch.delenv("VEDASTRO_GATEWAY_MODE", raising=False)
|
|
monkeypatch.delenv("VEDASTRO_SELF_HOST_ENDPOINT", raising=False)
|
|
monkeypatch.delenv("VEDASTRO_API_ENDPOINT", raising=False)
|
|
monkeypatch.delenv("VEDASTRO_CACHE_TTL_SECONDS", raising=False)
|
|
monkeypatch.delenv("VEDASTRO_GATEWAY_QUEUE_ENABLED", raising=False)
|
|
monkeypatch.delenv("VEDASTRO_QUEUE_ENABLED", raising=False)
|
|
|
|
status = vedastro_gateway.gateway_status()
|
|
|
|
assert status["scope"] == "vedastro_gateway"
|
|
assert status["mode"] == "local_first"
|
|
assert status["direct_browser_access_allowed"] is False
|
|
assert status["frontend_secret_safe"] is True
|
|
assert status["backend_priority"] == ["self_host", "official", "cache", "queue", "local_fallback"]
|
|
assert status["active_backend"] == "local_fallback"
|
|
assert status["boundary"] == "Users never call VedAstro directly; backend gateway owns cache, queue, and fallback."
|
|
|
|
|
|
def test_gateway_status_reports_cn_gateway_self_host(monkeypatch):
|
|
from scripts import vedastro_gateway
|
|
|
|
monkeypatch.setenv("VEDASTRO_GATEWAY_MODE", "cn_gateway")
|
|
monkeypatch.setenv("VEDASTRO_SELF_HOST_ENDPOINT", "https://jyotish-gateway.example.com/vedastro")
|
|
monkeypatch.setenv("VEDASTRO_CACHE_TTL_SECONDS", "604800")
|
|
monkeypatch.setenv("VEDASTRO_GATEWAY_QUEUE_ENABLED", "1")
|
|
|
|
status = vedastro_gateway.gateway_status()
|
|
|
|
assert status["mode"] == "cn_gateway"
|
|
assert status["self_host_configured"] is True
|
|
assert status["active_backend"] == "self_host"
|
|
assert status["cache_ttl_seconds"] == 604800
|
|
assert status["queue_enabled"] is True
|
|
|
|
|
|
def test_gateway_run_packet_uses_user_entrypoint_and_marks_not_all_641(monkeypatch):
|
|
from scripts import vedastro_gateway
|
|
|
|
monkeypatch.setenv("JYOTISH_SKIP_LOCAL_ENV", "1")
|
|
monkeypatch.setenv("VEDASTRO_GATEWAY_MODE", "cn_gateway")
|
|
monkeypatch.setenv("VEDASTRO_CACHE_TTL_SECONDS", "604800")
|
|
monkeypatch.setenv("VEDASTRO_GATEWAY_QUEUE_ENABLED", "1")
|
|
monkeypatch.setenv("VEDASTRO_FULL_CATALOG_SAMPLE_LIMIT", "0")
|
|
|
|
packet = vedastro_gateway.run_gateway_packet(
|
|
{
|
|
"year": REDACTED_YEAR,
|
|
"month": 4,
|
|
"day": 17,
|
|
"hour": 14,
|
|
"minute": 49,
|
|
"second": 0,
|
|
"lat": 36.42,
|
|
"lon": 114.2,
|
|
"tz": 8,
|
|
},
|
|
question="事业机会什么时候出现",
|
|
themes=["career", "health"],
|
|
reference_date="2026-07-02",
|
|
)
|
|
|
|
assert packet["scope"] == "vedastro_gateway_run"
|
|
assert packet["status"] in {"ok", "partial", "queued", "blocked", "cached", "local_fallback"}
|
|
assert packet["gateway_status"]["mode"] == "cn_gateway"
|
|
assert packet["official_capability_catalog"]["summary"]["catalog_method_count"] >= 0
|
|
assert packet["honesty_boundary"]["all_641_methods_executed"] is False
|
|
assert packet["user_visibility"]["mainland_cn_safe"] is True
|