Some checks failed
verify / verify (push) Has been cancelled
The Stage 1 foundation now proves provider contracts with mocks and validates PostgreSQL/pgvector ingestion, approval binding, retrieval, reranking, and idempotency using only synthetic data. Live Bailian validation remains gated on rotating the exposed key. Constraint: The key shown in chat is compromised and cannot be used or committed Rejected: Mark Stage 1 complete from mock and offline results | real three-model smoke is still required Confidence: high Scope-risk: moderate Reversibility: clean Directive: Do not enable real-data ingestion until Stage 3 cloud approval and outbound manifest controls are enforced end to end Tested: make verify; 41 pytest tests; strict mypy; Ruff; Compose config; pinned image build; empty-volume migration; role denial; two idempotent 20-vector seeds; database restart persistence Not-tested: Live Bailian calls require a newly rotated key; React product UI is not implemented
55 lines
1.8 KiB
Python
55 lines
1.8 KiB
Python
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
from app.adapters.fake import FakeEmbeddingProvider
|
|
from app.core.config import Settings
|
|
from app.tools.seed_demo import (
|
|
embed_in_batches,
|
|
embedding_profile_hash,
|
|
load_documents,
|
|
prepare_chunks,
|
|
)
|
|
|
|
PROJECT_ROOT = Path(__file__).resolve().parents[3]
|
|
DOCUMENTS_PATH = PROJECT_ROOT / "data" / "samples" / "public" / "demo_documents.jsonl"
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_seed_preparation_batches_and_hash_binds_twenty_documents() -> None:
|
|
documents = load_documents(DOCUMENTS_PATH)
|
|
settings = Settings()
|
|
provider = FakeEmbeddingProvider()
|
|
texts = [
|
|
f"标题:{item.title}\n地区:{item.region}\n矿种:{item.mineral}\n正文:{item.content}"
|
|
for item in documents
|
|
]
|
|
|
|
vectors, model = await embed_in_batches(provider, texts)
|
|
chunks = prepare_chunks(
|
|
documents,
|
|
vectors,
|
|
profile_hash=embedding_profile_hash(settings, "fake"),
|
|
embedding_model=model,
|
|
)
|
|
|
|
assert len(chunks) == 20
|
|
assert all(len(item.vector) == 1024 for item in chunks)
|
|
assert all(item.embedding_text == item.embedding_prefix + item.cloud_text for item in chunks)
|
|
assert len({item.chunk_id for item in chunks}) == 20
|
|
assert all(len(item.outbound_manifest_sha256) == 64 for item in chunks)
|
|
|
|
|
|
def test_seed_rejects_fixture_not_explicitly_marked_synthetic(tmp_path: Path) -> None:
|
|
path = tmp_path / "documents.jsonl"
|
|
path.write_text(
|
|
'{"doc_id":"x","title":"x","content":"x","region":"x",'
|
|
'"mineral":"x","page_no":1,"source_type":"unknown",'
|
|
'"review_state":"LOCAL_PARSED_PENDING_CLOUD_REVIEW",'
|
|
'"cloud_policy_id":"synthetic-demo-v1"}\n',
|
|
encoding="utf-8",
|
|
)
|
|
|
|
with pytest.raises(ValueError, match="non_synthetic_document"):
|
|
load_documents(path)
|