Owner decision 2026-11-26: the product stops using VedAstro. - scripts/vedastro_switch: VEDASTRO_ENABLED=1 turns it on; default off. - Adapter, gateway, foreground session, consult gate, orchestrator, user entrypoint, REST/MCP/SDK bridges answer "disabled" at once: no network, no subprocess, no wait, no cache writes. - vedastro_priority: a disabled snapshot leaves the local chart as is; an official chart replaces it only when every chart/house answer echoes the requested time, place and ayanamsa. - Model input drops VedAstro audit rows, cross-check and must-use layer; privacy policy drops the VedAstro data line. - VEDASTRO_API_KEY optional and unused; env examples, deploy/README, AGENTS.md updated. Frozen files untouched. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DbBXoyn7Hj3LCW3BUs5bZ8
156 lines
6.1 KiB
Python
156 lines
6.1 KiB
Python
"""Pytest import guardrails for local project modules."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
import time
|
|
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))
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def _vedastro_switch(request, monkeypatch) -> None:
|
|
"""BUG-2427: VedAstro is off unless a test is marked ``vedastro_enabled``.
|
|
|
|
Modules named ``*vedastro*`` test the archived integration (bridges, adapter,
|
|
gateway, caches) and run with the switch on; every other test sees the
|
|
product default, off.
|
|
"""
|
|
if request.node.get_closest_marker("vedastro_enabled") is not None:
|
|
monkeypatch.setenv("VEDASTRO_ENABLED", "1")
|
|
# The API chart cache key (frozen jyotish_api_server) does not carry the switch,
|
|
# so a chart cached by a switched-off test would be served here.
|
|
monkeypatch.setenv("JYOTISH_API_CHART_CACHE_TTL_SECONDS", "0")
|
|
else:
|
|
monkeypatch.delenv("VEDASTRO_ENABLED", raising=False)
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def _isolate_annual_motion_cache(tmp_path_factory, monkeypatch) -> None:
|
|
"""BUG-2315: the report's per-year motion cache stays out of the repository's scratch/local.
|
|
|
|
One directory per test session, so the public charts are scanned once per session.
|
|
"""
|
|
monkeypatch.setenv("JYOTISH_ANNUAL_MOTION_CACHE_DIR", str(tmp_path_factory.getbasetemp() / "annual_motion_timeline"))
|
|
# BUG-2321: no background prewarm thread in tests that warm a consult packet; its own tests drive it directly.
|
|
monkeypatch.setenv("JYOTISH_ANNUAL_MOTION_PREWARM", "0")
|
|
|
|
|
|
_FOREGROUND_EXECUTOR_MODULES = (
|
|
"scripts.vedastro_foreground",
|
|
"vedastro_foreground",
|
|
"scripts.jyotish_api_server",
|
|
"jyotish_api_server",
|
|
)
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def _isolate_foreground_vedastro_executor(monkeypatch):
|
|
"""A fresh foreground pool per test, drained at teardown (BUG-1498).
|
|
|
|
A task left running stores its outcome under whatever cache directory the
|
|
environment names when it finishes, which would be the next test's.
|
|
"""
|
|
from concurrent.futures import ThreadPoolExecutor
|
|
|
|
from scripts import vedastro_foreground
|
|
|
|
executor = ThreadPoolExecutor(
|
|
max_workers=vedastro_foreground._FOREGROUND_VEDASTRO_WORKERS,
|
|
thread_name_prefix="jyotish-vedastro-fg-test",
|
|
)
|
|
for name in _FOREGROUND_EXECUTOR_MODULES:
|
|
module = sys.modules.get(name)
|
|
if module is not None and hasattr(module, "_FOREGROUND_VEDASTRO_EXECUTOR"):
|
|
monkeypatch.setattr(module, "_FOREGROUND_VEDASTRO_EXECUTOR", executor)
|
|
yield
|
|
# Queued work is dropped; running work gets a bounded wait so a stuck stub cannot hang the run.
|
|
executor.shutdown(wait=False, cancel_futures=True)
|
|
deadline = time.monotonic() + 10
|
|
for thread in list(getattr(executor, "_threads", ())):
|
|
thread.join(max(deadline - time.monotonic(), 0))
|
|
|
|
|
|
def pytest_configure(config) -> None:
|
|
config.addinivalue_line("markers", "vedastro_enabled: run with VEDASTRO_ENABLED=1 (archived VedAstro integration, BUG-2427)")
|
|
config.addinivalue_line("markers", "vedastro_off: keep the product default (VedAstro off) in a *vedastro* test module")
|
|
|
|
|
|
# BUG-2427: tests outside *vedastro* modules that exercise the archived integration with the switch on.
|
|
_VEDASTRO_ENABLED_TESTS = frozenset({
|
|
"test_full_reading_reports_ayanamsa_metadata_and_ai_prompt_pack",
|
|
"test_full_reading_auto_attaches_vedastro_main_entry_boundary",
|
|
"test_vedastro_range_scan_endpoint_uses_user_birth_and_returns_controlled_blocked_state",
|
|
"test_vedastro_gateway_status_route_is_cn_safe",
|
|
"test_vedastro_gateway_run_route_returns_gateway_packet",
|
|
"test_vedastro_gateway_enqueue_and_poll_routes",
|
|
"test_vedastro_gateway_archive_manifest_route",
|
|
"test_vedastro_gateway_job_run_route_executes_worker",
|
|
"test_consultation_workflow_uses_unified_orchestrator_contract",
|
|
"test_consultation_foreground_skips_vedastro_main_entry_overview",
|
|
"test_consultation_foreground_times_out_vedastro_without_failing_local",
|
|
"test_chart_ai_prompt_pack_exposes_functional_benefic_malefic_layer",
|
|
"test_chart_auto_attaches_vedastro_main_entry_boundary",
|
|
"test_failed_snapshot_expires_before_success",
|
|
"test_gateway_status_reports_cache_ttl_fallback",
|
|
})
|
|
|
|
|
|
def pytest_collection_modifyitems(items) -> None:
|
|
for item in items:
|
|
if "vedastro" in item.fspath.basename or item.originalname in _VEDASTRO_ENABLED_TESTS:
|
|
item.add_marker("vedastro_enabled")
|
|
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()
|