Files
Jyotisha/tests/conftest.py
T
Jesse_ChenandClaude Opus 5.5 b9a5415e71
Independent Staging Quality Gate / publish (push) Canceled after 0s
Independent Staging Quality Gate / validate (push) Canceled after 2m17s
VedAstro failures are remembered for the day; the rectification check fits the frontend's wait (issue #130, BUG-1479)
- Foreground gateway: a run that ended without official data is written to
  the existing same-day negative snapshot store; later turns that day answer
  from it without starting the gateway (second call <= 0.15 s, same fields).
  Success still goes to the positive cache first; a consult-gate deferral and
  a join timeout are not failures.
- /v5/vedastro-validate: a result blocked by VedAstro itself is kept in memory
  for a day per (evidence fingerprint, candidate pair); evidence-decided
  results are not. The whole check has 11 s (frontend waits 12 s); calls with
  time to spare keep the adapter timeout, so normal output is unchanged.
- conftest also isolates the negative store and clears the check memory.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-28 12:38:17 +08:00

68 lines
2.1 KiB
Python

"""Pytest import guardrails for local project modules."""
from __future__ import annotations
import sys
from pathlib import Path
import pytest
# Deliberately fictional birth data; not a real person or an oracle golden.
FIXTURE_BIRTH_DATE = "1990-06-15"
FIXTURE_BIRTH_TIME = "10:20"
FIXTURE_BIRTH_LAT = 31.2
FIXTURE_BIRTH_LON = 121.5
ROOT = Path(__file__).resolve().parents[1]
SCRIPTS = str(ROOT / "scripts")
WORKBUDDY_SKILL_SCRIPTS = ".workbuddy/skills/jyotish-vedic-astrology/scripts"
SLOW_API_SECURITY_PREFIXES = (
"test_vedastro_",
"test_high_rigor_",
"test_professional_reading",
"test_api_prompt_pack",
"test_consultation_workflow",
"test_thematic_report",
"test_capability_audit",
"test_technique_catalog",
)
def ensure_project_scripts_first() -> None:
if SCRIPTS in sys.path:
sys.path.remove(SCRIPTS)
sys.path.insert(0, SCRIPTS)
def remove_workbuddy_shadow_modules() -> None:
for name, module in list(sys.modules.items()):
module_file = getattr(module, "__file__", "") or ""
if WORKBUDDY_SKILL_SCRIPTS in module_file:
del sys.modules[name]
def pytest_runtest_setup() -> None:
remove_workbuddy_shadow_modules()
ensure_project_scripts_first()
@pytest.fixture(autouse=True)
def _isolate_vedastro_snapshot_cache(tmp_path_factory, monkeypatch) -> None:
cache_dir = tmp_path_factory.mktemp("vedastro_snapshot_cache")
monkeypatch.setenv("JYOTISH_VEDASTRO_SNAPSHOT_CACHE_DIR", str(cache_dir))
# Foreground failures are remembered for the day there too (issue #130).
negative_dir = tmp_path_factory.mktemp("vedastro_snapshot_negative_cache")
monkeypatch.setenv("JYOTISH_VEDASTRO_SNAPSHOT_NEGATIVE_CACHE_DIR", str(negative_dir))
from scripts.rectification.vedastro_validate_cache import clear as clear_validate_memory
clear_validate_memory()
def pytest_collection_modifyitems(items) -> None:
for item in items:
if item.fspath.basename == "test_api_server_security.py" and item.name.startswith(SLOW_API_SECURITY_PREFIXES):
item.add_marker("slow")
ensure_project_scripts_first()