from core.context.project_context import build_project_context def _sample_project(): return { "id": "proj-1", "title": "Wdrożenie platformy cyberbezpieczeństwa", "description": "Projekt B+R w obszarze wykrywania zagrożeń.", "program_name": "FENG Ścieżka SMART", "program_type": "SMART", "estimated_value": "5 000 000 PLN", "external_context": { "company_data": { "name": "Start-ups Are Us Sp. z o.o.", "nip": "5213641211", "regon": "123456789", "krs": "0000123456", "address": "ul. Testowa 1, Warszawa", "region": "Mazowieckie", "legal_form": "Sp. z o.o.", "size": "mikro", "msp_status": "mikro", "msp_verified": True, "pkd_codes": ["62.01.Z", "Zweryfikowano przez GUS (Brak PKD)"], "financials": {"revenue": 0, "employment": 8}, "sudop": {"configured": True, "de_minimis_total_eur": 15000}, "krs_graph": {"wspolnicy": 3, "zarzad": 2}, }, "gaps": ["Brak danych finansowych (przychody)."], "risk_hints": ["SUDOP: ręczna weryfikacja de minimis zalecana."], }, } def test_build_context_extracts_known_facts(): ctx = build_project_context(_sample_project()) assert ctx.company.name == "Start-ups Are Us Sp. z o.o." assert ctx.company.nip == "5213641211" assert ctx.company.is_grounded is True # invalid PKD placeholder is filtered out, valid one kept assert ctx.company.pkd_codes == ["62.01.Z"] # revenue 0 dropped, employment kept assert ctx.company.revenue == "" assert ctx.company.employment == "8" assert ctx.company.krs_shareholders == 3 assert ctx.company.de_minimis_total_eur == "15000" def test_prompt_block_is_structured_not_json(): ctx = build_project_context(_sample_project()) block = ctx.to_prompt_block() assert "KONTEKST PROJEKTU" in block assert "DANE WNIOSKODAWCY" in block assert "Start-ups Are Us" in block assert "LUKI DANYCH" in block assert "[DO WERYFIKACJI" in block # must not be a raw JSON dump assert '"company_data"' not in block def test_empty_project_is_not_grounded(): ctx = build_project_context({"external_context": {}}) assert ctx.company.is_grounded is False assert ctx.company.known_facts() == {} def test_prompt_block_respects_max_chars(): proj = _sample_project() proj["description"] = "x" * 5000 ctx = build_project_context(proj) block = ctx.to_prompt_block(max_chars=500) assert len(block) <= 560