Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.
Python aicode-complexitycode-healthcode-intelligencecode-qualitydead-codedeveloper-toolsdocumentationgit-analyticsmcpopen-sourcepythonrefactoringstatic-analysistechnical-debt
fix(health): scope finding status updates to the requested repository (#4725)
Jon7c129f7651e0
diff --git a/packages/server/src/repowise/server/routers/code_health/findings_routes.py b/packages/server/src/repowise/server/routers/code_health/findings_routes.pyindex 147d4ec4f..1c90202ff 100644--- a/packages/server/src/repowise/server/routers/code_health/findings_routes.py+++ b/packages/server/src/repowise/server/routers/code_health/findings_routes.py@@ -4,7 +4,7 @@ from __future__ import annotationsimport json-from fastapi import Depends, HTTPException, Query, Request, Response+from fastapi import Depends, HTTPException, Query, Responsefrom pydantic import BaseModel, Fieldfrom sqlalchemy.ext.asyncio import AsyncSession@@ -13,7 +13,8 @@ from repowise.core.analysis.health.models import split_by_originfrom repowise.core.analysis.health.scope import parse_scopefrom repowise.core.analysis.health.scoring import ZERO_IMPACT_DIMENSIONSfrom repowise.core.persistence import crud-from repowise.server.deps import get_db_session, scoped_repo_id+from repowise.core.persistence.models import HealthFinding+from repowise.server.deps import get_db_sessionfrom repowise.server.schemas import (HealthFindingResponse,HealthFindingWithSymbolResponse,@@ -149,19 +150,15 @@ async def update_finding_status(repo_id: str,finding_id: str,payload: FindingStatusUpdate,- request: Request,session: AsyncSession = Depends(get_db_session),) -> dict:if payload.status not in ALLOWED_STATUSES:raise HTTPException(status_code=400, detail=f"status must be one of {sorted(ALLOWED_STATUSES)}")- if scoped_repo_id(request) is not None:- from repowise.core.persistence.models import HealthFinding-- existing = await session.get(HealthFinding, finding_id)- if existing is None or existing.repository_id != repo_id:- raise HTTPException(status_code=404, detail="Finding not found")+ existing = await session.get(HealthFinding, finding_id)+ if existing is None or existing.repository_id != repo_id:+ raise HTTPException(status_code=404, detail="Finding not found")f = await crud.update_health_finding_status(session, finding_id, payload.status)if f is None:raise HTTPException(status_code=404, detail="Finding not found")diff --git a/tests/unit/server/test_finding_repository_scope.py b/tests/unit/server/test_finding_repository_scope.pynew file mode 100644index 000000000..8aefacd06--- /dev/null+++ b/tests/unit/server/test_finding_repository_scope.py@@ -0,0 +1,37 @@+"""Finding status updates stay within the repository in the URL."""++from __future__ import annotations++import pytest++from repowise.core.persistence.models import HealthFinding, Repository++[email protected]("repo_id", ["other", "missing"])+async def test_status_update_refuses_another_repository(client, session_factory, tmp_path, repo_id):+ async with session_factory() as session:+ session.add_all(+ [+ Repository(id=name, name=name, local_path=str(tmp_path / name))+ for name in ("owner", "other")+ ]+ )+ await session.flush()+ finding = HealthFinding(+ repository_id="owner",+ file_path="a.py",+ biomarker_type="complex_method",+ severity="high",+ health_impact=2.5,+ )+ session.add(finding)+ await session.commit()+ finding_id = finding.id++ response = await client.patch(+ f"/api/repos/{repo_id}/health/findings/{finding_id}", json={"status": "resolved"}+ )+ assert response.status_code == 404+ async with session_factory() as session:+ finding = await session.get(HealthFinding, finding_id)+ assert finding.status == "open"