feat: add project-review workflow (whole-project / single-feature review)

Adds the project-review workflow for code review independent of the git
diff. The scope is parsed from the user instruction: 全面/整个项目 ->
whole-project (score every source file), otherwise feature + target
keyword (locate the code with semantic search + graph queries).

- scoring_tools.py: score_review_func gains all_files=True to score every
  source file in the graph via store.get_all_files()
- main.py: score_review_tool gains all_files param; registers the
  project_review MCP prompt (prompts 6->7)
- prompts.py: project_review_prompt(scope, target) with whole-project and
  feature branches (fixed a precedence bug that truncated the feature text)
- skills.py + skills/project-review/: new read-only project-review skill
  with shared checklists
- .opencode/command/code-review-graph-project-review.md: slash command
- tests: test_project_review.py (prompt rendering), TestProjectReviewPrompt,
  skill count assertions 5->6, all_files wiring checks
- docs: prompts (6->7) + project-review entries across COMMANDS, CLAUDE,
  README (+localized), INDEX, architecture, LLM-OPTIMIZED-REFERENCE,
  CHANGELOG
This commit is contained in:
dev
2026-08-06 13:56:54 +08:00
parent 6f0e6f0775
commit 307d2fd471
45 changed files with 1339 additions and 131 deletions
+111 -19
View File
@@ -1,4 +1,4 @@
"""Tests for the unified-review HTML report tool."""
"""Tests for the unified-review HTML/Markdown report tool."""
from __future__ import annotations
@@ -9,13 +9,14 @@ import pytest
sys.path.insert(0, str(Path(__file__).parent.parent))
from code_review_graph.scoring import build_report_data # noqa: E402
from code_review_graph.scoring import ( # noqa: E402
build_report_data,
render_markdown_report,
)
from code_review_graph.tools.scoring_tools import ( # noqa: E402
_load_report_template,
generate_report_func,
)
def _review_data() -> dict:
return {
"scope": "change-level",
@@ -24,6 +25,8 @@ def _review_data() -> dict:
"files": "app.py, main.py",
"baseline": "generic",
"verdict": "\u2705 PASS",
"quality_score": 7.0,
"counts": {"critical": 1, "informational": 2},
"metrics": {
"sql_risk": {"value": 0, "grade": "good", "note": "heuristic"},
"exception_coverage": {"value": 33.33, "grade": "warn", "note": "heuristic"},
@@ -44,6 +47,11 @@ def _review_data() -> dict:
}
def _mkroot(tmp_path: Path) -> Path:
Path(tmp_path, ".code-review-graph").mkdir(exist_ok=True)
return tmp_path
class TestBuildReportData:
def test_normalises_review_data(self):
data = build_report_data(_review_data())
@@ -55,6 +63,11 @@ class TestBuildReportData:
assert data["issues"][0]["location"] == "src/app.py:42"
assert "requirement_coverage" in data["llm_judged"]
def test_quality_score_and_counts_carried(self):
data = build_report_data(_review_data())
assert data["quality_score"] == 7.0
assert data["counts"] == {"critical": 1, "informational": 2}
def test_empty_findings(self):
rd = _review_data()
rd["findings"] = []
@@ -76,29 +89,108 @@ class TestLoadTemplate:
assert template.startswith("<!DOCTYPE html>")
class TestRenderMarkdownReport:
def test_renders_chinese_structure(self):
md = render_markdown_report(_review_data())
assert "# 代码审查报告" in md
assert "结论" in md
assert "PR 质量分" in md and "7.0/10" in md
assert "客观指标" in md
assert "SQL 注入风险" in md
assert "异常分支覆盖" in md
assert "问题清单" in md
assert "🟡 主要" in md
assert "置信度 7/10" in md
assert "修复建议" in md
assert "需要人工审查" in md
assert "Payment callback idempotency" in md
assert "需 LLM 判断的指标" in md
def test_grade_localisation(self):
rd = _review_data()
rd["metrics"] = {
"sql_risk": {"value": 0, "grade": "good"},
"vulnerability_risk": {"value": 2, "grade": "fail"},
"high_risk_density": {"value": None, "grade": "na"},
}
md = render_markdown_report(rd)
assert "良好" in md
assert "不合格" in md
assert "不适用" in md
def test_empty_report(self):
md = render_markdown_report({})
assert "# 代码审查报告" in md
assert "未发现问题" in md
class TestGenerateReport:
def test_writes_self_contained_html(self, tmp_path):
Path(tmp_path, ".code-review-graph").mkdir(exist_ok=True)
out = tmp_path / "sub" / "report.html"
def test_both_writes_html_and_md(self, tmp_path):
root = _mkroot(tmp_path)
result = generate_report_func(
_review_data(),
output_path=str(out),
repo_root=str(tmp_path),
output_path="sub/report",
repo_root=str(root),
)
assert result["status"] == "ok"
assert Path(result["output_path"]).is_file()
html = Path(result["output_path"]).read_text(encoding="utf-8")
assert "{{REPORT_DATA}}" not in html
assert "\u2705 PASS" in html
assert "N+1" in html
assert isinstance(result["output_path"], list)
assert len(result["files"]) == 2
html = root / "sub" / "report.html"
md = root / "sub" / "report.md"
assert html.is_file()
assert md.is_file()
html_text = html.read_text(encoding="utf-8")
md_text = md.read_text(encoding="utf-8")
assert "{{REPORT_DATA}}" not in html_text
assert "代码审查报告" in html_text
assert "\u2705 PASS" in html_text
assert "N+1" in html_text
assert "# 代码审查报告" in md_text
def test_markdown_only(self, tmp_path):
root = _mkroot(tmp_path)
result = generate_report_func(
_review_data(),
output_path="md-only",
repo_root=str(root),
format="markdown",
)
assert result["status"] == "ok"
assert len(result["files"]) == 1
assert str(result["output_path"]).endswith("md-only.md")
assert (root / "md-only.md").is_file()
assert not (root / "md-only.html").exists()
def test_html_only(self, tmp_path):
root = _mkroot(tmp_path)
result = generate_report_func(
_review_data(),
output_path="html-only",
repo_root=str(root),
format="html",
)
assert result["status"] == "ok"
assert len(result["files"]) == 1
assert str(result["output_path"]).endswith("html-only.html")
assert (root / "html-only.html").is_file()
assert not (root / "html-only.md").exists()
def test_default_output_path_is_repo_root(self, tmp_path):
# repo_root must look like a project root: create .code-review-graph.
Path(tmp_path, ".code-review-graph").mkdir(exist_ok=True)
result = generate_report_func(_review_data(), repo_root=str(tmp_path))
root = _mkroot(tmp_path)
result = generate_report_func(_review_data(), repo_root=str(root))
assert result["status"] == "ok"
assert result["output_path"].endswith("code-review-report.html")
assert Path(result["output_path"]).is_file()
assert (root / "code-review-report.html").is_file()
assert (root / "code-review-report.md").is_file()
def test_invalid_format_errors(self, tmp_path):
root = _mkroot(tmp_path)
result = generate_report_func(
_review_data(),
repo_root=str(root),
format="xml",
)
assert result["status"] == "error"
assert "xml" in result["error"]
def test_handles_missing_repo_root(self, tmp_path):
with pytest.raises(ValueError):