Add the scoped PostgreSQL/pgvector schema, independent ingestion settings and ports, embedding profile checks, and trusted administrator bootstrap. Include repository contracts and guidance, organized provider-free and PostgreSQL tests, deployment setup, and byte-preserving migration attributes. Validation: 163 tests passed; all 48 PostgreSQL cases passed with pgvector Python 0.5.0 and 0.3.6. No production schema or historical metadata was changed.
51 lines
2.2 KiB
Python
51 lines
2.2 KiB
Python
"""Test isolation and explicit PostgreSQL acceptance requirements."""
|
|
import os
|
|
from app.modules.documents.settings import IngestionSettings
|
|
|
|
import subprocess
|
|
import sys
|
|
|
|
|
|
def test_acceptance_mode_requires_database_configuration(monkeypatch):
|
|
environment = {k: v for k, v in os.environ.items() if k != "TEST_DATABASE_URL"}
|
|
result = subprocess.run(
|
|
[sys.executable, "-m", "pytest", "--require-postgres",
|
|
"tests/integration/test_migrations.py::test_empty_migration_tables_and_pinned_profile"],
|
|
env=environment, capture_output=True, text=True,
|
|
)
|
|
assert result.returncode != 0
|
|
assert "TEST_DATABASE_URL is required" in result.stdout
|
|
assert "1 error" in result.stdout
|
|
|
|
|
|
def test_baseline_settings_use_defaults_and_preserve_database_acceptance(settings):
|
|
assert settings.max_original_bytes == 20 * 1024 * 1024
|
|
assert settings.max_staged_bytes == 128 * 1024 * 1024
|
|
assert settings.poll_seconds == 2
|
|
assert settings.heartbeat_seconds == 20
|
|
assert settings.lease_seconds == 120
|
|
|
|
|
|
def test_explicit_environment_loading_is_preserved(settings, monkeypatch):
|
|
monkeypatch.setenv("INGEST_POLL_SECONDS", "7")
|
|
values = settings.model_dump()
|
|
values.pop("poll_seconds")
|
|
assert IngestionSettings(_env_file=None, **values).poll_seconds == 7
|
|
|
|
|
|
def test_ordinary_suite_ignores_ambient_ingestion_configuration():
|
|
# Re-run the complete ordinary suite once, excluding this recursion driver.
|
|
environment = dict(os.environ, INGEST_MAX_ORIGINAL_BYTES="1024",
|
|
INGEST_MAX_STAGED_BYTES="4096", INGEST_MAX_CHUNKS="10",
|
|
INGEST_POLL_SECONDS="5", INGEST_HEARTBEAT_SECONDS="10",
|
|
INGEST_LEASE_SECONDS="60", INGEST_RETRY_BASE_SECONDS="1",
|
|
INGEST_RETRY_CAP_SECONDS="10", INGEST_EMBEDDING_TIMEOUT_SECONDS="15")
|
|
result = subprocess.run(
|
|
[sys.executable, "-m", "pytest", "-m", "not postgres", "-q",
|
|
"-k", "not test_ordinary_suite_ignores_ambient_ingestion_configuration"],
|
|
env=environment, capture_output=True, text=True,
|
|
)
|
|
assert result.returncode == 0, result.stdout + result.stderr
|
|
assert "failed" not in result.stdout
|
|
assert "passed" in result.stdout
|