generated from coulomb/repo-seed
Added rejection support for the rest of the candidate graph
This commit is contained in:
@@ -293,6 +293,85 @@ def test_edit_candidate_graph_values_before_approval(tmp_path):
|
||||
assert ability_map.abilities[0].capabilities[0].confidence == 0.87
|
||||
|
||||
|
||||
def test_reject_candidate_capability_excludes_it_from_approval(tmp_path):
|
||||
source = tmp_path / "repo"
|
||||
source.mkdir()
|
||||
(source / "README.md").write_text("# Capability Reject\n", encoding="utf-8")
|
||||
(source / "app.py").write_text(
|
||||
"from fastapi import FastAPI\n"
|
||||
"app = FastAPI()\n"
|
||||
'@app.get("/health")\n'
|
||||
"def health():\n"
|
||||
" return {}\n",
|
||||
encoding="utf-8",
|
||||
)
|
||||
|
||||
service = make_service(tmp_path)
|
||||
repository = service.register_repository(name="Capability Reject", url=str(source))
|
||||
summary = service.analyze_repository(repository.id)
|
||||
graph = service.candidate_graph(repository.id, summary.analysis_run.id)
|
||||
candidate_capability = graph.abilities[0].capabilities[0]
|
||||
|
||||
rejected_graph = service.reject_candidate_capability(
|
||||
repository.id,
|
||||
summary.analysis_run.id,
|
||||
candidate_capability.id,
|
||||
notes="Interface is not relevant.",
|
||||
)
|
||||
ability_map = service.approve_candidate_graph(repository.id, summary.analysis_run.id)
|
||||
|
||||
assert rejected_graph.abilities[0].capabilities[0].status == "rejected"
|
||||
assert rejected_graph.abilities[0].capabilities[0].features[0].status == "rejected"
|
||||
approved_capability_names = {
|
||||
capability.name for capability in ability_map.abilities[0].capabilities
|
||||
}
|
||||
assert candidate_capability.name not in approved_capability_names
|
||||
|
||||
|
||||
def test_reject_candidate_feature_and_evidence_excludes_only_those_leaves(tmp_path):
|
||||
source = tmp_path / "repo"
|
||||
source.mkdir()
|
||||
(source / "README.md").write_text("# Leaf Reject\n", encoding="utf-8")
|
||||
(source / "tests").mkdir()
|
||||
(source / "tests" / "test_health.py").write_text(
|
||||
"def test_health(): pass\n",
|
||||
encoding="utf-8",
|
||||
)
|
||||
(source / "app.py").write_text(
|
||||
"from fastapi import FastAPI\n"
|
||||
"app = FastAPI()\n"
|
||||
'@app.get("/health")\n'
|
||||
"def health():\n"
|
||||
" return {}\n",
|
||||
encoding="utf-8",
|
||||
)
|
||||
|
||||
service = make_service(tmp_path)
|
||||
repository = service.register_repository(name="Leaf Reject", url=str(source))
|
||||
summary = service.analyze_repository(repository.id)
|
||||
graph = service.candidate_graph(repository.id, summary.analysis_run.id)
|
||||
capability = graph.abilities[0].capabilities[0]
|
||||
|
||||
service.reject_candidate_feature(
|
||||
repository.id,
|
||||
summary.analysis_run.id,
|
||||
capability.features[0].id,
|
||||
notes="Feature is incidental.",
|
||||
)
|
||||
service.reject_candidate_evidence(
|
||||
repository.id,
|
||||
summary.analysis_run.id,
|
||||
capability.evidence[0].id,
|
||||
notes="Evidence is too weak.",
|
||||
)
|
||||
ability_map = service.approve_candidate_graph(repository.id, summary.analysis_run.id)
|
||||
|
||||
approved_capability = ability_map.abilities[0].capabilities[0]
|
||||
assert approved_capability.name == capability.name
|
||||
assert approved_capability.features == []
|
||||
assert len(approved_capability.evidence) == len(capability.evidence) - 1
|
||||
|
||||
|
||||
def test_analyze_repository_failure_is_recorded(tmp_path):
|
||||
service = make_service(tmp_path)
|
||||
repository = service.register_repository(
|
||||
|
||||
@@ -284,3 +284,90 @@ def test_ui_register_analyze_and_approve_loop(tmp_path):
|
||||
assert "Review UI Repo Repository Usefulness" in approved_detail.text
|
||||
finally:
|
||||
app.dependency_overrides.clear()
|
||||
|
||||
|
||||
def test_api_rejects_candidate_capability_feature_and_evidence(tmp_path):
|
||||
source = tmp_path / "repo"
|
||||
source.mkdir()
|
||||
(source / "README.md").write_text("# API Reject Leaves\n", encoding="utf-8")
|
||||
(source / "tests").mkdir()
|
||||
(source / "tests" / "test_status.py").write_text(
|
||||
"def test_status(): pass\n",
|
||||
encoding="utf-8",
|
||||
)
|
||||
(source / "app.py").write_text(
|
||||
"from fastapi import FastAPI\n"
|
||||
"app = FastAPI()\n"
|
||||
'@app.get("/status")\n'
|
||||
"def status():\n"
|
||||
" return {}\n",
|
||||
encoding="utf-8",
|
||||
)
|
||||
|
||||
def override_settings():
|
||||
return Settings(
|
||||
database_path=str(tmp_path / "api-reject.sqlite3"),
|
||||
checkout_root=str(tmp_path / "api-reject-checkouts"),
|
||||
)
|
||||
|
||||
app.dependency_overrides[get_settings] = override_settings
|
||||
client = TestClient(app)
|
||||
try:
|
||||
repository_response = client.post(
|
||||
"/repos",
|
||||
json={"name": "API Reject Leaves", "url": str(source)},
|
||||
)
|
||||
repository_id = repository_response.json()["id"]
|
||||
run_response = client.post(f"/repos/{repository_id}/analysis-runs", json={})
|
||||
run_id = run_response.json()["analysis_run"]["id"]
|
||||
graph_response = client.get(
|
||||
f"/repos/{repository_id}/analysis-runs/{run_id}/candidate-graph"
|
||||
)
|
||||
capability = graph_response.json()["abilities"][0]["capabilities"][0]
|
||||
feature_id = capability["features"][0]["id"]
|
||||
evidence_id = capability["evidence"][0]["id"]
|
||||
|
||||
feature_response = client.post(
|
||||
f"/repos/{repository_id}/analysis-runs/{run_id}"
|
||||
f"/candidate-features/{feature_id}/reject",
|
||||
json={"notes": "Noisy interface"},
|
||||
)
|
||||
assert feature_response.status_code == 200
|
||||
assert (
|
||||
feature_response.json()["abilities"][0]["capabilities"][0]["features"][0][
|
||||
"status"
|
||||
]
|
||||
== "rejected"
|
||||
)
|
||||
|
||||
evidence_response = client.post(
|
||||
f"/repos/{repository_id}/analysis-runs/{run_id}"
|
||||
f"/candidate-evidence/{evidence_id}/reject",
|
||||
json={"notes": "Weak evidence"},
|
||||
)
|
||||
assert evidence_response.status_code == 200
|
||||
assert (
|
||||
evidence_response.json()["abilities"][0]["capabilities"][0]["evidence"][0][
|
||||
"status"
|
||||
]
|
||||
== "rejected"
|
||||
)
|
||||
|
||||
run_response = client.post(f"/repos/{repository_id}/analysis-runs", json={})
|
||||
run_id = run_response.json()["analysis_run"]["id"]
|
||||
graph_response = client.get(
|
||||
f"/repos/{repository_id}/analysis-runs/{run_id}/candidate-graph"
|
||||
)
|
||||
capability_id = graph_response.json()["abilities"][0]["capabilities"][0]["id"]
|
||||
capability_response = client.post(
|
||||
f"/repos/{repository_id}/analysis-runs/{run_id}"
|
||||
f"/candidate-capabilities/{capability_id}/reject",
|
||||
json={"notes": "Reject whole capability"},
|
||||
)
|
||||
assert capability_response.status_code == 200
|
||||
assert (
|
||||
capability_response.json()["abilities"][0]["capabilities"][0]["status"]
|
||||
== "rejected"
|
||||
)
|
||||
finally:
|
||||
app.dependency_overrides.clear()
|
||||
|
||||
Reference in New Issue
Block a user