FastAPI + Celery + Next.js + Postgres/Redis app with company monitoring, source collection, LLM-based change analysis, enrichment, and account security (Turnstile, escalating lockout, email verification).
70 lines
2.1 KiB
Python
70 lines
2.1 KiB
Python
"""generate_report(): the company_enrichment evidence block reaches the
|
|
prompt exactly like company_profile does, and is an honest empty dict
|
|
when no enrichment data is available - never fabricated."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import pytest
|
|
|
|
from app.prompts.base import extract_evidence_block
|
|
from app.prompts.report_generation import ReportContent, SwotAnalysis, generate_report
|
|
|
|
|
|
class _CapturingLLMProvider:
|
|
provider_name = "capturing"
|
|
|
|
def __init__(self) -> None:
|
|
self.last_user_prompt: str | None = None
|
|
|
|
async def generate_structured(self, system_prompt, user_prompt, response_model):
|
|
self.last_user_prompt = user_prompt
|
|
return ReportContent(
|
|
executive_summary="",
|
|
company_overview="",
|
|
market_positioning="",
|
|
customer_sentiment="",
|
|
competitor_comparison="",
|
|
swot=SwotAnalysis(),
|
|
methodology="",
|
|
limitations="",
|
|
)
|
|
|
|
async def generate_text(self, system_prompt, user_prompt) -> str:
|
|
return ""
|
|
|
|
|
|
async def _generate(llm: _CapturingLLMProvider, **kwargs) -> None:
|
|
await generate_report(
|
|
llm,
|
|
company_name="Acme Corp",
|
|
company_aliases=[],
|
|
competitors=[],
|
|
monitoring_focus=None,
|
|
industry=None,
|
|
documents=[],
|
|
detected_changes=[],
|
|
sources_failed=[],
|
|
**kwargs,
|
|
)
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_enrichment_data_reaches_the_prompt_as_a_named_evidence_block():
|
|
llm = _CapturingLLMProvider()
|
|
await _generate(
|
|
llm, enrichment={"employee_count": "1001-5000", "funding": {"total_raised": "$1M"}}
|
|
)
|
|
|
|
evidence = extract_evidence_block(llm.last_user_prompt)
|
|
assert evidence["company_enrichment"]["employee_count"] == "1001-5000"
|
|
assert evidence["company_enrichment"]["funding"]["total_raised"] == "$1M"
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_no_enrichment_data_is_an_honest_empty_block_not_fabricated():
|
|
llm = _CapturingLLMProvider()
|
|
await _generate(llm) # enrichment defaults to None
|
|
|
|
evidence = extract_evidence_block(llm.last_user_prompt)
|
|
assert evidence["company_enrichment"] == {}
|