generated from coulomb/repo-seed
Milestone 3: candidate graph generation
This commit is contained in:
45
tests/test_candidate_graph.py
Normal file
45
tests/test_candidate_graph.py
Normal file
@@ -0,0 +1,45 @@
|
||||
from repo_registry.candidate_graph.generator import CandidateGraphGenerator
|
||||
from repo_registry.core.models import 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 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"
|
||||
@@ -133,6 +133,16 @@ def test_analyze_repository_records_snapshot_and_observed_facts(tmp_path):
|
||||
assert ("framework", "FastAPI", "requirements.txt") in fact_names
|
||||
assert ("interface", "python route decorator", "app.py") in fact_names
|
||||
|
||||
candidate_graph = service.candidate_graph(repository.id, summary.analysis_run.id)
|
||||
assert candidate_graph.repository.name == "Example"
|
||||
assert candidate_graph.abilities
|
||||
capability_names = {
|
||||
capability.name
|
||||
for ability in candidate_graph.abilities
|
||||
for capability in ability.capabilities
|
||||
}
|
||||
assert "Expose Repository Interface" in capability_names
|
||||
|
||||
|
||||
def test_analyze_repository_failure_is_recorded(tmp_path):
|
||||
service = make_service(tmp_path)
|
||||
|
||||
@@ -102,6 +102,16 @@ def test_api_analysis_run_loop(tmp_path):
|
||||
assert run["analysis_run"]["status"] == "completed"
|
||||
assert run["snapshot"]["file_count"] == 2
|
||||
|
||||
candidate_response = client.get(
|
||||
f"/repos/{repository_id}/analysis-runs/"
|
||||
f"{run['analysis_run']['id']}/candidate-graph"
|
||||
)
|
||||
assert candidate_response.status_code == 200
|
||||
candidate_graph = candidate_response.json()
|
||||
assert candidate_graph["abilities"][0]["name"] == (
|
||||
"Review Frontend Repository Usefulness"
|
||||
)
|
||||
|
||||
facts_response = client.get(f"/repos/{repository_id}/observed-facts")
|
||||
assert facts_response.status_code == 200
|
||||
fact_names = {
|
||||
|
||||
Reference in New Issue
Block a user