fix: keep foreground consultations responsive

This commit is contained in:
Jesse_Chen
2026-08-11 11:59:14 +08:00
parent 8eed0603f9
commit 620131d6a8
9 changed files with 191 additions and 36 deletions
+87
View File
@@ -2384,6 +2384,69 @@ def test_consultation_workflow_uses_unified_orchestrator_contract(monkeypatch) -
assert result['reference_transparency']['similar_public_cases']['does_not_predict_user_outcome'] is True
def test_consultation_foreground_defers_optional_vedastro_calls(monkeypatch) -> None:
handler = _handler()
seen = {}
fake_chart = {
'success': True,
'birth_info': {'date': '1997-08-08', 'time': '05:00', 'tz': 8},
'ascendant': {'lon': 92.0, 'sign': 'Cancer', 'sign_idx': 3},
'planets': _sample_planets(),
'dasha': {'periods': [{'lord': 'Sun', 'start': '2026-01-01', 'end': '2027-01-01'}]},
'modules': {
'varga_full': {'D9': {}, 'D10': {}},
'arudha_padas': {'A10': {}, 'UL': {}},
'narayana_dasha': {'periods': []},
'ashtakavarga': {'sav': []},
'kp_cusps': {'houses': []},
},
'special_lagnas': {'precision': 'sunrise_correct'},
}
def fake_chart_compute(body):
seen['chart_body'] = dict(body)
return fake_chart
monkeypatch.setattr(handler, '_compute_chart', fake_chart_compute)
monkeypatch.setattr(handler, '_compute_rectification_gate', lambda body: {
'success': True,
'summary': {'recommended_events': [], 'warned': [], 'disabled': []},
})
monkeypatch.setattr(handler, '_compute_muhurta_panchanga', lambda body: {'status': 'ok'})
monkeypatch.setattr(handler, '_compute_thematic_report', lambda body: {
'success': True,
'endpoint': 'thematic_report',
'themes': {},
})
monkeypatch.setattr(
handler,
'_compute_vedastro_gateway_run',
lambda body: pytest.fail('foreground consultation must not call VedAstro gateway'),
)
result = handler._compute_consultation_workflow({
'entry_mode': 'direct_chart',
'question': '应期与阶段问题:深入看今日',
'theme': ['career'],
'year': 1997,
'month': 8,
'day': 8,
'hour': 5,
'minute': 0,
'lat': 36.420487,
'lon': 114.209936,
'tz': 8,
'defer_optional_external_evidence': True,
})
assert seen['chart_body']['skip_vedastro_main_entry_overview'] is True
assert result['success'] is True
assert result['vedastro_gateway']['status'] == 'local_fallback'
assert result['vedastro_gateway']['official_closure_reason'] == 'foreground_optional_evidence_deferred'
assert result['consumer_context']['answer_policy']['can_answer_direction'] is True
assert result['consumer_context']['answer_policy']['provider_unavailable_is_fatal'] is False
def test_consultation_workflow_accepts_western_oracle_payload(monkeypatch) -> None:
handler = _handler()
fake_chart = {
@@ -3286,6 +3349,30 @@ def test_chart_auto_attaches_vedastro_main_entry_boundary(monkeypatch: pytest.Mo
assert vedastro["status"] == "network_execution_disabled"
def test_chart_foreground_mode_skips_vedastro_main_entry(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setenv("JYOTISH_API_CHART_CACHE_TTL_SECONDS", "0")
monkeypatch.setattr(
jyotish_api_server,
"_attach_vedastro_main_entry_overview",
lambda *_args, **_kwargs: pytest.fail("foreground chart must not run VedAstro overview"),
)
result = _handler()._compute_chart({
'year': 1990,
'month': 6,
'day': 15,
'hour': 12,
'minute': 0,
'lat': 39.9,
'lon': 116.4,
'tz': 8,
'skip_vedastro_main_entry_overview': True,
})
assert result['success'] is True
assert 'vedastro_range_scan_result' not in result.get('modules', {})
def test_api_chart_response_cache_reuses_cached_value(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setenv("JYOTISH_API_CHART_CACHE_TTL_SECONDS", "600")
monkeypatch.delenv("VEDASTRO_API_ENDPOINT", raising=False)