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(mcp): reject option-like revspecs in get_change_risk (#3893)
Raghav Chamadiyae229cb0cf731
diff --git a/packages/core/src/repowise/core/analysis/change_risk/service.py b/packages/core/src/repowise/core/analysis/change_risk/service.pyindex 96692a8d5..b36112522 100644--- a/packages/core/src/repowise/core/analysis/change_risk/service.py+++ b/packages/core/src/repowise/core/analysis/change_risk/service.py@@ -185,6 +185,10 @@ def score_live_change("""if baseline < 0:raise ValueError("baseline must be non-negative")+ # A ref reaches git as an argument; one that reads as an option (--output=f)+ # would run as a git flag instead of being looked up as a revision.+ if revspec and any(p.startswith("-") for p in (split_revspec(revspec) or (revspec,))):+ raise ValueError(f"Invalid revspec {revspec!r}: a ref cannot start with '-'.")extensions = normalize_extensions(extensions)from_riskignore = riskignore_patterns(repo_path)diff --git a/tests/unit/analysis/test_change_risk_facade.py b/tests/unit/analysis/test_change_risk_facade.pyindex 5c93b4b0e..a02d06602 100644--- a/tests/unit/analysis/test_change_risk_facade.py+++ b/tests/unit/analysis/test_change_risk_facade.py@@ -164,3 +164,11 @@ def test_author_experience_is_excluded_from_the_ranking_score():# ...but the repo-relative ranking is about the change, so it does not.assert ranked_novice.percentile == ranked_veteran.percentileassert ranked_novice.priority == ranked_veteran.priority++[email protected]("revspec", ["--output=leak.txt", "HEAD..--output=leak.txt", "-n1"])+def test_option_like_revspec_is_rejected_before_git(make_repo, revspec):+ repo = make_repo()+ with pytest.raises(ValueError, match="cannot start with"):+ score_live_change(str(repo.path), revspec)+ assert not (repo.path / "leak.txt").exists()