"""Shared test fixtures. PostgreSQL integration tests are gated on TREX_POSTGRESQL_TEST_DSN; when it is unset they are skipped (unit/API tests still run via in-memory adapters). """ from __future__ import annotations import os import pytest _PG_TABLES = ( "ledger_outbox", "intent_log", "slot_transition_log", "daily_symbol_entries", "daily_slot", ) @pytest.fixture def pg_dsn() -> str: dsn = os.environ.get("TREX_POSTGRESQL_TEST_DSN") if not dsn: pytest.skip("TREX_POSTGRESQL_TEST_DSN not set; skipping PostgreSQL integration test") return dsn @pytest.fixture def pg_clean(pg_dsn: str): """Apply migrations and truncate slot-core tables before each PG test.""" import psycopg from trex_core.adapters.persistence.migrate import apply_migrations apply_migrations(pg_dsn) with psycopg.connect(pg_dsn, autocommit=True) as conn: with conn.cursor() as cur: cur.execute(f"TRUNCATE {', '.join(_PG_TABLES)}") return pg_dsn