"""Test bootstrap — runs before any test module imports config.

Points the SQLite DB at a throwaway temp file and sets a known dev token, so
tests never touch the real _cache/fourier.db. Starts from a clean slate.
"""
import os
import sys
import tempfile
from pathlib import Path

_DB = Path(tempfile.gettempdir()) / "fourier_test.db"
os.environ["FOURIER_DB"] = str(_DB)
os.environ.setdefault("FOURIER_DEV_TOKEN", "test-secret")
# keep the artifact store (#27) out of the repo's _cache during tests
_ART = Path(tempfile.gettempdir()) / "fourier_test_artifacts"
os.environ["FOURIER_ARTIFACTS"] = str(_ART)

sys.path.insert(0, str(Path(__file__).resolve().parent.parent))

# fresh DB each run (drop WAL/shm siblings too)
for p in (_DB, Path(str(_DB) + "-wal"), Path(str(_DB) + "-shm")):
    if p.exists():
        p.unlink()
