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.
74 lines
2.7 KiB
Python
74 lines
2.7 KiB
Python
"""Ingestion defaults, limits and explicit deployment inputs."""
|
|
import json
|
|
import os
|
|
import pytest
|
|
from pydantic import ValidationError
|
|
from app.modules.documents.settings import IngestionSettings
|
|
|
|
|
|
def test_explicit_profile_and_no_secrets_in_snapshot(settings):
|
|
profile = settings.processing_profile()
|
|
assert profile["size_unit"] == "characters"
|
|
assert profile["embedding"]["model"] == "deterministic-test"
|
|
assert profile["embedding"]["dimensions"] == 3
|
|
assert "api_key" not in json.dumps(profile)
|
|
assert settings.max_original_bytes == 20 * 1024 * 1024
|
|
assert settings.max_staged_bytes == 128 * 1024 * 1024
|
|
with pytest.raises(ValueError):
|
|
settings.require_embedding_credentials()
|
|
|
|
|
|
@pytest.mark.parametrize("override", [
|
|
{"chunk_overlap_characters": 1000}, {"max_pdf_pages": 0},
|
|
{"heartbeat_seconds": 120}, {"worker_concurrency": 2},
|
|
{"accepted_formats": (".exe",)}, {"retry_base_seconds": 301},
|
|
{"embedding_model": " "}, {"embedding_dimensions": 0},
|
|
{"database_url": "sqlite://"},
|
|
])
|
|
def test_invalid_configuration(settings, override):
|
|
values = settings.model_dump()
|
|
values.update(override)
|
|
with pytest.raises(ValidationError):
|
|
IngestionSettings(_env_file=None, **values)
|
|
|
|
|
|
def test_model_dimension_are_required(monkeypatch):
|
|
for key in tuple(os.environ):
|
|
if key.startswith("INGEST_"):
|
|
monkeypatch.delenv(key)
|
|
with pytest.raises(ValidationError) as exc:
|
|
IngestionSettings(_env_file=None)
|
|
missing = {error["loc"][0] for error in exc.value.errors()}
|
|
assert {"embedding_model", "embedding_dimensions"} <= missing
|
|
|
|
|
|
def test_environment_limits_override(monkeypatch, settings):
|
|
monkeypatch.setenv("INGEST_MAX_CHUNKS", "12")
|
|
monkeypatch.setenv("INGEST_ACCEPTED_FORMATS", '[".md"]')
|
|
values = settings.model_dump()
|
|
values.pop("max_chunks")
|
|
values.pop("accepted_formats")
|
|
configured = IngestionSettings(_env_file=None, **values)
|
|
assert configured.max_chunks == 12
|
|
assert configured.accepted_formats == (".md",)
|
|
|
|
|
|
DURATIONS = (
|
|
"embedding_timeout_seconds", "poll_seconds", "heartbeat_seconds",
|
|
"lease_seconds", "retry_base_seconds", "retry_cap_seconds",
|
|
)
|
|
|
|
|
|
@pytest.mark.parametrize("field", DURATIONS)
|
|
@pytest.mark.parametrize("value", [float("nan"), float("inf"), float("-inf")])
|
|
@pytest.mark.parametrize("source", ["direct", "environment"])
|
|
def test_nonfinite_durations_rejected(settings, monkeypatch, field, value, source):
|
|
values = settings.model_dump()
|
|
if source == "environment":
|
|
values.pop(field)
|
|
monkeypatch.setenv("INGEST_" + field.upper(), str(value))
|
|
else:
|
|
values[field] = value
|
|
with pytest.raises(ValidationError):
|
|
IngestionSettings(_env_file=None, **values)
|