fix(consult): race a bounded VedAstro gateway on the chat path
Independent Staging Quality Gate / validate (push) Successful in 10m15s
Independent Staging Quality Gate / publish (push) Successful in 10m2s

Foreground still skips the heavy overview stack, but overlaps a timed
gateway so official evidence can merge when it finishes in budget.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Jesse_Chen
2026-08-19 17:51:27 +08:00
parent 0eedf92992
commit bffc74efc5
9 changed files with 321 additions and 11 deletions
+99 -4
View File
@@ -2395,7 +2395,7 @@ 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:
def test_consultation_foreground_skips_vedastro_main_entry_overview(monkeypatch) -> None:
handler = _handler()
seen = {}
fake_chart = {
@@ -2432,7 +2432,17 @@ def test_consultation_foreground_defers_optional_vedastro_calls(monkeypatch) ->
monkeypatch.setattr(
handler,
'_compute_vedastro_gateway_run',
lambda body: pytest.fail('foreground consultation must not call VedAstro gateway'),
lambda body: {
'scope': 'vedastro_gateway_run',
'status': 'official_verified',
'official_closure_state': 'official_verified',
'official_raw_response': {
'request_id': 'fg-ok',
'natal': {'sun': 'Leo', 'moon': 'Taurus', 'ascendant': 'Cancer'},
'lat': 25.03,
'lon': 121.56,
},
},
)
result = handler._compute_consultation_workflow({
@@ -2452,10 +2462,95 @@ def test_consultation_foreground_defers_optional_vedastro_calls(monkeypatch) ->
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['vedastro_gateway']['official_closure_state'] == 'official_verified'
assert result['vedastro_official']['official_closure_state'] == 'official_verified'
assert result['consumer_context']['vedastro_cross_check']['status'] == 'executed'
assert result['consumer_context']['vedastro_cross_check']['natal'] == {
'sun': 'Leo',
'moon': 'Taurus',
'ascendant': 'Cancer',
}
assert 'lat' not in result['consumer_context']['vedastro_cross_check']
assert 'lon' not in result['consumer_context']['vedastro_cross_check']
assert result['consumer_context']['answer_policy']['can_answer_direction'] is True
assert result['consumer_context']['answer_policy']['provider_unavailable_is_fatal'] is False
audit = {
row['technique']: row['status']
for row in result['consumer_context']['technique_audit_table']
if isinstance(row, dict)
}
assert audit.get('VedAstro Cloud State') == 'executed'
assert audit.get('MEVG / Global Web Evidence') == 'blocked'
def test_consultation_foreground_times_out_vedastro_without_failing_local(monkeypatch) -> None:
handler = _handler()
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'},
}
monkeypatch.setenv('JYOTISH_FOREGROUND_VEDASTRO_JOIN_SECONDS', '0.05')
monkeypatch.setenv('JYOTISH_FOREGROUND_VEDASTRO_BUDGET_SECONDS', '2')
monkeypatch.setattr(handler, '_compute_chart', lambda body: fake_chart)
monkeypatch.setattr(handler, '_compute_rectification_gate', lambda body: {
'success': True,
'summary': {'recommended_events': [], 'warned': [], 'disabled': []},
})
monkeypatch.setattr(handler, '_compute_thematic_report', lambda body: {
'success': True,
'endpoint': 'thematic_report',
'themes': {},
})
def slow_gateway(body):
time.sleep(0.4)
return {
'scope': 'vedastro_gateway_run',
'status': 'official_verified',
'official_closure_state': 'official_verified',
'official_raw_response': {'request_id': 'too-late'},
}
monkeypatch.setattr(handler, '_compute_vedastro_gateway_run', slow_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 result['success'] is True
assert result['vedastro_gateway']['official_closure_reason'] == 'foreground_optional_evidence_timeout'
assert result['consumer_context']['vedastro_cross_check']['status'] == 'blocked'
assert result['consumer_context']['answer_policy']['can_answer_direction'] is True
audit = {
row['technique']: row['status']
for row in result['consumer_context']['technique_audit_table']
if isinstance(row, dict)
}
assert audit.get('VedAstro Cloud State') == 'blocked'
assert audit.get('MEVG / Global Web Evidence') == 'blocked'
def test_consultation_workflow_accepts_western_oracle_payload(monkeypatch) -> None:
@@ -20,6 +20,7 @@ from jyotish_api_server import ( # noqa: E402
JyotishAPIHandler,
_attach_local_consultation_layers,
_build_consumer_context,
_compact_vedastro_cross_check,
)
from unified_consultation_orchestrator import UnifiedConsultationOrchestrator # noqa: E402
@@ -700,3 +701,35 @@ def test_failed_vedastro_raw_packet_is_not_marked_as_used() -> None:
)
assert packet['sections']['vedastro_official_raw_response']['status'] == 'received_unverified'
def test_compact_vedastro_cross_check_keeps_signs_and_drops_coordinates() -> None:
compact = _compact_vedastro_cross_check(
{'official_closure_state': 'official_verified', 'status': 'ok'},
{
'official_raw_response': {
'natal': {'sun': 'Leo', 'moon': 'Taurus', 'ascendant': 'Cancer'},
'lat': 25.03,
'lon': 121.56,
'hour': 3,
'minute': 4,
},
},
)
assert compact['status'] == 'executed'
assert compact['natal'] == {'sun': 'Leo', 'moon': 'Taurus', 'ascendant': 'Cancer'}
assert 'lat' not in compact
assert 'lon' not in compact
assert 'hour' not in compact
def test_compact_vedastro_cross_check_marks_timeout_blocked() -> None:
compact = _compact_vedastro_cross_check(
{},
{
'official_closure_state': 'official_blocked',
'official_closure_reason': 'foreground_optional_evidence_timeout',
},
)
assert compact['status'] == 'blocked'
assert compact['official_closure_reason'] == 'foreground_optional_evidence_timeout'
@@ -53,6 +53,16 @@ def _stub_consultation_runtime(monkeypatch, handler: JyotishAPIHandler) -> None:
"_compute_muhurta_panchanga",
lambda body: {"status": "ok", "scope": "muhurta_panchanga"},
)
monkeypatch.setattr(
handler,
"_compute_vedastro_gateway_run",
lambda body: {
"scope": "vedastro_gateway_run",
"status": "official_blocked",
"official_closure_state": "official_blocked",
"official_closure_reason": "test_stub",
},
)
@pytest.mark.parametrize("domain", CANONICAL_DOMAINS)