"""Test bootstrap — Windows shim for fcntl (used by src/init_db.py on POSIX).

Allows running tests on Windows even though the production app targets Linux.
Mirrors the stub used by serve_marketing.py for local preview.
"""
import os
import sys
import types

# Stub fcntl BEFORE pytest collects any test that imports src.app
if sys.platform.startswith('win') and 'fcntl' not in sys.modules:
    fcntl_stub = types.ModuleType('fcntl')
    fcntl_stub.LOCK_EX = 2
    fcntl_stub.LOCK_NB = 4
    fcntl_stub.LOCK_UN = 8
    fcntl_stub.LOCK_SH = 1
    fcntl_stub.flock = lambda *_a, **_kw: None
    fcntl_stub.fcntl = lambda *_a, **_kw: 0
    sys.modules['fcntl'] = fcntl_stub

# Minimal env so src/config/app_config.py doesn't sys.exit on missing config
os.environ.setdefault('SQLALCHEMY_DATABASE_URI', 'sqlite:///:memory:')
os.environ.setdefault('SECRET_KEY', 'test-secret-key')
os.environ.setdefault('TRANSCRIPTION_BASE_URL', 'http://local-stub')
os.environ.setdefault('TRANSCRIPTION_API_KEY', 'local-stub')
