from repo_registry.candidate_graph.generator import CandidateGraphGenerator from repo_registry.core.models import ContentChunk, ObservedFact, Repository def fact(id, kind, name, path="", value=""): return ObservedFact( id=id, repository_id=1, analysis_run_id=1, snapshot_id=1, kind=kind, path=path, name=name, value=value, metadata={}, ) def chunk(id, kind, path, text, start_line=1, end_line=1): return ContentChunk( id=id, repository_id=1, analysis_run_id=1, snapshot_id=1, path=path, kind=kind, start_line=start_line, end_line=end_line, text=text, ) def test_candidate_generator_builds_review_seed_from_observed_facts(): repository = Repository( id=1, name="MailRouter", url="/tmp/mail-router", description=None, branch="main", status="analyzed", ) facts = [ fact(1, "documentation", "README", "README.md"), fact(2, "interface", "python route decorator", "app.py", '@app.post("/classify")'), fact(3, "test", "test_app.py", "tests/test_app.py"), fact(4, "framework", "FastAPI", "requirements.txt"), ] graph = CandidateGraphGenerator().generate(repository, facts) assert len(graph) == 1 ability = graph[0] assert ability.name == "Review MailRouter Repository Usefulness" assert ability.source_refs[0].path == "README.md" interface_capability = ability.capabilities[0] assert interface_capability.name == "Expose Repository Interface" assert interface_capability.features[0].type == "API" assert interface_capability.features[0].location == "app.py" assert interface_capability.evidence[0].strength == "strong" def test_candidate_generator_enriches_descriptions_from_content_chunks(): repository = Repository( id=1, name="MailRouter", url="/tmp/mail-router", description=None, branch="main", status="analyzed", ) facts = [ fact(1, "documentation", "README", "README.md"), fact(2, "interface", "python route decorator", "app.py", '@app.post("/classify")'), ] chunks = [ chunk( 1, "documentation", "README.md", "# MailRouter\nRoutes incoming customer email to the right team.", end_line=2, ), chunk( 2, "interface", "app.py", '@app.post("/classify")\ndef classify_email():\n return {}', start_line=5, end_line=7, ), ] graph = CandidateGraphGenerator().generate(repository, facts, chunks) assert "MailRouter. Routes incoming customer email" in graph[0].description assert '@app.post("/classify")' in graph[0].capabilities[0].description