Skip to content

Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.

test(server): pin get_context, get_symbol, search and overview payloads (#3972)

Raghav Chamadiyae83745082d09
diff --git a/tests/unit/server/conftest.py b/tests/unit/server/conftest.py
index feec1ab6c..984407ae2 100644
--- a/tests/unit/server/conftest.py
+++ b/tests/unit/server/conftest.py
@@ -6,7 +6,10 @@ provides an httpx AsyncClient for making requests.
from __future__ import annotations
+import json
+import os
from pathlib import Path
+from typing import Any
import pytest
from httpx import ASGITransport, AsyncClient
@@ -192,3 +195,48 @@ async def create_test_repo(client: AsyncClient, tmp_path: Path | None = None) ->
)
assert resp.status_code == 201
return resp.json()
+
+
+def normalize_payload(value: Any, replace: dict[str, str]) -> Any:
+ """Swap per-run substrings (temp paths, generated ids) for placeholders.
+
+ Values, nesting and key order are kept exact; freeze the clock instead of
+ masking timestamps, so a moved timestamp still fails the golden.
+ """
+ if isinstance(value, dict):
+ return {k: normalize_payload(v, replace) for k, v in value.items()}
+ if isinstance(value, list):
+ return [normalize_payload(v, replace) for v in value]
+ if isinstance(value, str):
+ for old, new in replace.items():
+ value = value.replace(old, new)
+ return value
+
+
+def path_placeholders(root: str | Path, placeholder: str = "<repo>") -> dict[str, str]:
+ """Map a temp root, in either slash style, to one spelling on every OS.
+
+ A separator right after the root becomes ``/`` too, so a joined path
+ reads the same on Windows and Linux. Longest first, so the joined forms win.
+ """
+ native = str(root)
+ replace: dict[str, str] = {}
+ for form in {native, native.replace("\\", "/")}:
+ replace[form + "\\"] = placeholder + "/"
+ replace[form + "/"] = placeholder + "/"
+ replace[form] = placeholder
+ return dict(sorted(replace.items(), key=lambda kv: len(kv[0]), reverse=True))
+
+
+def assert_payload_golden(path: Path, payload: Any) -> None:
+ """Compare a normalized payload byte for byte, key order included.
+
+ ``REPOWISE_REWRITE_GOLDEN=1`` rewrites the file instead, only for an
+ intended behaviour change.
+ """
+ text = json.dumps(payload, indent=2, sort_keys=False) + "\n"
+ if os.environ.get("REPOWISE_REWRITE_GOLDEN") == "1":
+ path.parent.mkdir(parents=True, exist_ok=True)
+ path.write_text(text, encoding="utf-8", newline="\n")
+ pytest.skip("golden rewritten")
+ assert text == path.read_text(encoding="utf-8")
diff --git a/tests/unit/server/golden/mcp/change_risk_cross_repo.json b/tests/unit/server/golden/mcp/change_risk_cross_repo.json
new file mode 100644
index 000000000..712ccaab9
--- /dev/null
+++ b/tests/unit/server/golden/mcp/change_risk_cross_repo.json
@@ -0,0 +1,45 @@
+{
+ "consumers": [
+ {
+ "provider_file": "packages/types/src/order.ts",
+ "repo": "frontend",
+ "file": "src/api.ts",
+ "contract_id": "code::@acme/types::Order",
+ "contract_type": "code",
+ "match_type": "exact",
+ "provider_symbol_id": "packages/types/src/order.ts::Order"
+ },
+ {
+ "provider_file": "packages/types/src/order.ts",
+ "repo": "mobile",
+ "file": "app/order.ts",
+ "contract_id": "code::@acme/types::Order",
+ "contract_type": "code",
+ "match_type": "exact",
+ "provider_symbol_id": "packages/types/src/order.ts::Order"
+ }
+ ],
+ "consumers_truncated": 0,
+ "consumer_repos": [
+ "frontend",
+ "mobile"
+ ],
+ "breaking_changes": [
+ {
+ "contract_id": "code::@acme/types::Order",
+ "type": "code",
+ "kind": "removed_endpoint",
+ "severity": "breaking",
+ "detail": "code::@acme/types::Order was removed",
+ "provider_file": "packages/types/src/order.ts",
+ "impacted_repos": [
+ "frontend"
+ ],
+ "provider_symbol_id": "packages/types/src/order.ts::Order"
+ }
+ ],
+ "breaking_changes_truncated": 0,
+ "breaking_changes_available": true,
+ "breaking_changes_as_of": "2026-08-23T00:00:00+00:00",
+ "summary": "2 consumer link(s) in 2 other repo(s) touch the files this change edits; 1 provider incompatibility finding(s) and 0 comparison warning(s) have endpoint-exposed consumers."
+}
diff --git a/tests/unit/server/golden/mcp/get_context_file.json b/tests/unit/server/golden/mcp/get_context_file.json
new file mode 100644
index 000000000..9cd22b33a
--- /dev/null
+++ b/tests/unit/server/golden/mcp/get_context_file.json
@@ -0,0 +1,35 @@
+{
+ "targets": {
+ "src/auth/service.py": {
+ "type": "file",
+ "path": "src/auth/service.py",
+ "docs": {
+ "title": "Auth Service",
+ "summary": "service.py: defines AuthService; function login.",
+ "symbols": [
+ {
+ "name": "AuthService",
+ "kind": "class",
+ "signature": "class AuthService",
+ "line": 10
+ },
+ {
+ "name": "login",
+ "kind": "method",
+ "signature": "async def login(self, username: str, password: str) -> Token",
+ "line": 20
+ }
+ ]
+ },
+ "hotspot": true,
+ "freshness": {
+ "confidence_score": 0.85,
+ "freshness_status": "fresh",
+ "is_stale": false
+ }
+ }
+ },
+ "_meta": {
+ "index_age_days": 7
+ }
+}
diff --git a/tests/unit/server/golden/mcp/get_context_file_include.json b/tests/unit/server/golden/mcp/get_context_file_include.json
new file mode 100644
index 000000000..aa1c08d3c
--- /dev/null
+++ b/tests/unit/server/golden/mcp/get_context_file_include.json
@@ -0,0 +1,70 @@
+{
+ "targets": {
+ "src/auth/service.py": {
+ "type": "file",
+ "path": "src/auth/service.py",
+ "docs": {
+ "title": "Auth Service",
+ "summary": "service.py: defines AuthService; function login.",
+ "symbols": [
+ {
+ "name": "AuthService",
+ "kind": "class",
+ "signature": "class AuthService",
+ "line": 10
+ },
+ {
+ "name": "login",
+ "kind": "method",
+ "signature": "async def login(self, username: str, password: str) -> Token",
+ "line": 20
+ }
+ ]
+ },
+ "hotspot": true,
+ "ownership": {
+ "primary_owner": "Alice",
+ "owner_pct": 0.65,
+ "owner_line_pct": null,
+ "contributor_count": 2,
+ "bus_factor": 0
+ },
+ "last_change": {
+ "date": "2026-03-15T00:00:00",
+ "author": "Alice",
+ "days_ago": 0
+ },
+ "decisions": [],
+ "candidates": [
+ {
+ "id": "dec1",
+ "title": "Use JWT for authentication",
+ "status": "proposed",
+ "decision": "Use JWT tokens for all API authentication",
+ "rationale": "Stateless, scalable, works across services",
+ "confidence": 0.6,
+ "authority": "candidate"
+ }
+ ],
+ "freshness": {
+ "confidence_score": 0.85,
+ "freshness_status": "fresh",
+ "is_stale": false
+ },
+ "callers": [
+ {
+ "file": "src/auth/middleware.py",
+ "imports": true
+ },
+ {
+ "file": "tests/test_service.py",
+ "imports": true
+ }
+ ],
+ "_call_graph_note": "File-level rollup: importing files plus inbound cross-file call counts. For symbol-precise callers pass 'file.py::Symbol'."
+ }
+ },
+ "_meta": {
+ "index_age_days": 7
+ }
+}
diff --git a/tests/unit/server/golden/mcp/get_context_graph_node_only.json b/tests/unit/server/golden/mcp/get_context_graph_node_only.json
new file mode 100644
index 000000000..0cd5b8fe5
--- /dev/null
+++ b/tests/unit/server/golden/mcp/get_context_graph_node_only.json
@@ -0,0 +1,21 @@
+{
+ "targets": {
+ "tests/test_service.py": {
+ "type": "file",
+ "path": "tests/test_service.py",
+ "docs": {
+ "symbols": [],
+ "summary": "test_service.py: empty or non-symbol file"
+ },
+ "hotspot": false,
+ "freshness": {
+ "confidence_score": null,
+ "freshness_status": null,
+ "is_stale": null
+ }
+ }
+ },
+ "_meta": {
+ "index_age_days": 7
+ }
+}
diff --git a/tests/unit/server/golden/mcp/get_context_module.json b/tests/unit/server/golden/mcp/get_context_module.json
new file mode 100644
index 000000000..b07221169
--- /dev/null
+++ b/tests/unit/server/golden/mcp/get_context_module.json
@@ -0,0 +1,32 @@
+{
+ "targets": {
+ "src/auth": {
+ "type": "module",
+ "docs": {
+ "title": "Auth Module",
+ "summary": "",
+ "files": [
+ {
+ "path": "src/auth/service.py",
+ "description": "",
+ "confidence_score": 0.85
+ },
+ {
+ "path": "src/auth/middleware.py",
+ "description": "",
+ "confidence_score": 0.5
+ }
+ ]
+ },
+ "hotspot": false,
+ "freshness": {
+ "confidence_score": 0.95,
+ "freshness_status": "fresh",
+ "is_stale": false
+ }
+ }
+ },
+ "_meta": {
+ "index_age_days": 7
+ }
+}
diff --git a/tests/unit/server/golden/mcp/get_context_not_found.json b/tests/unit/server/golden/mcp/get_context_not_found.json
new file mode 100644
index 000000000..dcee53bb3
--- /dev/null
+++ b/tests/unit/server/golden/mcp/get_context_not_found.json
@@ -0,0 +1,10 @@
+{
+ "targets": {
+ "nonexistent_thing_xyz": {
+ "error": "Target not found: 'nonexistent_thing_xyz'"
+ }
+ },
+ "_meta": {
+ "index_age_days": 7
+ }
+}
diff --git a/tests/unit/server/golden/mcp/get_context_symbol.json b/tests/unit/server/golden/mcp/get_context_symbol.json
new file mode 100644
index 000000000..30c7d516a
--- /dev/null
+++ b/tests/unit/server/golden/mcp/get_context_symbol.json
@@ -0,0 +1,33 @@
+{
+ "targets": {
+ "AuthService": {
+ "type": "symbol",
+ "docs": {
+ "name": "AuthService",
+ "kind": "class",
+ "file_path": "src/auth/service.py",
+ "qualified_name": "auth.service.AuthService",
+ "signature": "class AuthService",
+ "docstring": "Main authentication service.",
+ "file_summary": "",
+ "used_by": [],
+ "used_by_basis": {
+ "language": "python",
+ "resolved_call_edges": 0,
+ "guessed_share": null,
+ "unresolved_call_sites": null,
+ "note": "No call edges were resolved for this language, so an empty list carries no information."
+ }
+ },
+ "hotspot": true,
+ "freshness": {
+ "confidence_score": 0.85,
+ "freshness_status": "fresh",
+ "is_stale": false
+ }
+ }
+ },
+ "_meta": {
+ "index_age_days": 7
+ }
+}
diff --git a/tests/unit/server/golden/mcp/get_symbol.json b/tests/unit/server/golden/mcp/get_symbol.json
new file mode 100644
index 000000000..65613e290
--- /dev/null
+++ b/tests/unit/server/golden/mcp/get_symbol.json
@@ -0,0 +1,21 @@
+{
+ "symbol_id": "src/auth/service.py::login",
+ "file": "src/auth/service.py",
+ "name": "login",
+ "kind": "method",
+ "qualified_name": "auth.service.AuthService.login",
+ "signature": "async def login(self, username: str, password: str) -> Token",
+ "language": "python",
+ "start_line": 20,
+ "end_line": 40,
+ "symbol_start_line": 20,
+ "symbol_end_line": 40,
+ "source": " 20\t async def login(self, username: str, password: str) -> Token:\n 21\t \"\"\"Authenticate a user.\"\"\"\n 22\t user = await self.store.get(User, username)\n 23\t if user is None:\n 24\t return None\n 25\t return self._hash(password)\n 26\t # line 26\n 27\t # line 27\n 28\t # line 28\n 29\t # line 29\n 30\t # line 30\n 31\t # line 31\n 32\t # line 32\n 33\t # line 33\n 34\t # line 34\n 35\t # line 35\n 36\t # line 36\n 37\t # line 37\n 38\t # line 38\n 39\t # line 39\n 40\t # line 40",
+ "truncated": false,
+ "verified": true,
+ "_meta": {
+ "index_age_days": 7,
+ "complete": "Complete: 1 symbol body served whole from live source; do not re-open it.",
+ "replaced_tokens": 385
+ }
+}
diff --git a/tests/unit/server/golden/mcp/search_codebase_hybrid.json b/tests/unit/server/golden/mcp/search_codebase_hybrid.json
new file mode 100644
index 000000000..da73d9e13
--- /dev/null
+++ b/tests/unit/server/golden/mcp/search_codebase_hybrid.json
@@ -0,0 +1,45 @@
+{
+ "results": [
+ {
+ "type": "symbol",
+ "symbol_id": "src/auth/service.py::AuthService",
+ "name": "AuthService",
+ "kind": "class",
+ "start_line": 10,
+ "end_line": 100,
+ "signature": "class AuthService",
+ "qualified_name": "auth.service.AuthService",
+ "language": "python",
+ "score": 160.0,
+ "next": "get_symbol",
+ "symbols": [
+ "login:20"
+ ],
+ "path": "src/auth/service.py"
+ },
+ {
+ "title": "DB Models",
+ "page_type": "file_page",
+ "snippet": "",
+ "relevance_score": 2.9508,
+ "sources": [
+ "vector"
+ ],
+ "type": "page",
+ "path": "src/db/models.py"
+ }
+ ],
+ "mode": "hybrid",
+ "_meta": {
+ "index_age_days": 7
+ },
+ "candidates": [
+ {
+ "path": "src/auth/service.py"
+ },
+ {
+ "path": "src/db/models.py"
+ }
+ ],
+ "exact_match": true
+}
diff --git a/tests/unit/server/golden/mcp/search_codebase_path.json b/tests/unit/server/golden/mcp/search_codebase_path.json
new file mode 100644
index 000000000..eb1345186
--- /dev/null
+++ b/tests/unit/server/golden/mcp/search_codebase_path.json
@@ -0,0 +1,21 @@
+{
+ "results": [
+ {
+ "type": "file",
+ "page_id": "file_page:src/auth/service.py",
+ "title": "Auth Service",
+ "score": 119.981,
+ "next": "get_context",
+ "path": "src/auth/service.py"
+ }
+ ],
+ "mode": "path",
+ "_meta": {
+ "index_age_days": 7
+ },
+ "candidates": [
+ {
+ "path": "src/auth/service.py"
+ }
+ ]
+}
diff --git a/tests/unit/server/golden/mcp/search_codebase_symbol.json b/tests/unit/server/golden/mcp/search_codebase_symbol.json
new file mode 100644
index 000000000..349259643
--- /dev/null
+++ b/tests/unit/server/golden/mcp/search_codebase_symbol.json
@@ -0,0 +1,37 @@
+{
+ "results": [
+ {
+ "type": "symbol",
+ "symbol_id": "src/auth/service.py::AuthService",
+ "name": "AuthService",
+ "kind": "class",
+ "start_line": 10,
+ "end_line": 100,
+ "signature": "class AuthService",
+ "qualified_name": "auth.service.AuthService",
+ "language": "python",
+ "score": 160.0,
+ "next": "get_symbol",
+ "path": "src/auth/service.py"
+ }
+ ],
+ "mode": "symbol",
+ "_meta": {
+ "index_age_days": 7
+ },
+ "candidates": [
+ {
+ "path": "src/auth/service.py"
+ }
+ ],
+ "exact_match": true,
+ "lines": [
+ {
+ "path": "src/auth/service.py",
+ "line": 10,
+ "kind": "definition",
+ "text": "class AuthService:"
+ }
+ ],
+ "complete": true
+}
diff --git a/tests/unit/server/golden/overview_summary.json b/tests/unit/server/golden/overview_summary.json
new file mode 100644
index 000000000..ec6535058
--- /dev/null
+++ b/tests/unit/server/golden/overview_summary.json
@@ -0,0 +1,456 @@
+{
+ "repo": {
+ "id": "<repo-id>",
+ "name": "test-repo",
+ "local_path": "<tmp>/test-repo",
+ "default_branch": "main",
+ "head_commit": null,
+ "updated_at": "2026-09-02T12:00:00",
+ "remote_url": "https://github.com/example/test-repo"
+ },
+ "stats": {
+ "file_count": 4,
+ "symbol_count": 14,
+ "entry_point_count": 2,
+ "doc_page_count": 2,
+ "doc_prose_page_count": 1,
+ "doc_coverage_pct": 70.0,
+ "freshness_score": 50.0,
+ "dead_export_count": 1,
+ "hotspot_count": 2,
+ "silo_count": 2,
+ "module_count": 3,
+ "total_nloc": 450,
+ "deltas": {
+ "average_health": null,
+ "hotspot_health": null,
+ "file_count": null
+ }
+ },
+ "health": {
+ "average_health": 4.5,
+ "unanalysed_file_count": 1,
+ "analysed_share": 0.5,
+ "band": "needs_work",
+ "hotspot_health": 4.5,
+ "worst_performer_path": "src/core.py",
+ "worst_performer_score": 4.5,
+ "open_findings": 5,
+ "finding_counts": {
+ "inventory": 5,
+ "in_scope": 5,
+ "eligible": 0,
+ "due": 0,
+ "shown": 0,
+ "excluded": {
+ "not_judged": 5
+ },
+ "gated": 0
+ },
+ "gated": {},
+ "maintainability_average": 5.5,
+ "performance_average": 9.5,
+ "performance_findings": 0,
+ "worst_performance_path": "src/core.py",
+ "worst_performance_score": 9.5,
+ "severity_breakdown": {
+ "critical": 0,
+ "high": 5,
+ "medium": 0,
+ "low": 0
+ },
+ "defect_accuracy": null,
+ "last_indexed_at": null,
+ "snapshot_count": 0,
+ "history": []
+ },
+ "languages": [
+ {
+ "language": "python",
+ "file_count": 3
+ },
+ {
+ "language": "typescript",
+ "file_count": 1
+ }
+ ],
+ "docs_config_languages": [],
+ "attention": [
+ {
+ "id": "health-src/core.py",
+ "type": "health_finding",
+ "title": "src/core.py",
+ "description": "2 findings \u00b7 9.5 deducted",
+ "severity": "critical",
+ "target_id": "src/core.py",
+ "subtype": "god_class",
+ "weight": 9.5
+ },
+ {
+ "id": "security-1",
+ "type": "security_finding",
+ "title": "config/settings.py",
+ "description": "aws_access_key",
+ "severity": "high",
+ "target_id": "config/settings.py",
+ "subtype": "aws_access_key",
+ "weight": 1.0
+ },
+ {
+ "id": "security-2",
+ "type": "security_finding",
+ "title": "old/keys.py",
+ "description": "hardcoded_secret in commit abcdef1",
+ "severity": "high",
+ "target_id": "old/keys.py",
+ "subtype": "hardcoded_secret",
+ "weight": 0.0
+ },
+ {
+ "id": "refactor-ref1",
+ "type": "refactoring",
+ "title": "Engine.run",
+ "description": "+1.8 health, M effort \u00b7 src/core.py",
+ "severity": "medium",
+ "target_id": "src/core.py",
+ "subtype": "extract_method",
+ "weight": 1.8
+ },
+ {
+ "weight": 8.0,
+ "id": "ungoverned-src/core.py",
+ "type": "ungoverned_hotspot",
+ "title": "src/core.py",
+ "description": "High-churn file with no governing decision",
+ "severity": "medium",
+ "target_id": "src/core.py"
+ },
+ {
+ "id": "drift-1",
+ "type": "doc_drift",
+ "title": "README.md",
+ "description": "names a file that is not in the tree",
+ "severity": "medium",
+ "target_id": "README.md",
+ "subtype": "missing_path",
+ "weight": 0.95
+ },
+ {
+ "weight": 8.0,
+ "id": "proposed-dec1",
+ "type": "proposed_decision",
+ "title": "Keep the engine single-threaded",
+ "description": "Auto-proposed decision awaiting review",
+ "severity": "medium",
+ "target_id": "dec1"
+ },
+ {
+ "id": "silo-src/core.py",
+ "type": "knowledge_silo",
+ "title": "src/core.py",
+ "description": "90% single-owner concentration, 12 commits in 90d",
+ "severity": "medium",
+ "target_id": "src/core.py",
+ "weight": 12.9
+ },
+ {
+ "weight": 7.0,
+ "id": "ungoverned-web/app.ts",
+ "type": "ungoverned_hotspot",
+ "title": "web/app.ts",
+ "description": "High-churn file with no governing decision",
+ "severity": "medium",
+ "target_id": "web/app.ts"
+ },
+ {
+ "id": "silo-src/util.py",
+ "type": "knowledge_silo",
+ "title": "src/util.py",
+ "description": "90% single-owner concentration, 9 commits in 90d",
+ "severity": "medium",
+ "target_id": "src/util.py",
+ "weight": 9.9
+ },
+ {
+ "id": "silo-web/app.ts",
+ "type": "knowledge_silo",
+ "title": "web/app.ts",
+ "description": "90% single-owner concentration, 6 commits in 90d",
+ "severity": "medium",
+ "target_id": "web/app.ts",
+ "weight": 6.9
+ },
+ {
+ "id": "security-3",
+ "type": "security_finding",
+ "title": "src/run.py",
+ "description": "eval_call",
+ "severity": "low",
+ "target_id": "src/run.py",
+ "subtype": "eval_call",
+ "weight": 1.0
+ },
+ {
+ "id": "health-src/util.py",
+ "type": "health_finding",
+ "title": "src/util.py",
+ "description": "1 finding \u00b7 3.0 deducted",
+ "severity": "low",
+ "target_id": "src/util.py",
+ "subtype": "nested_complexity",
+ "weight": 3.0
+ },
+ {
+ "id": "refactor-ref2",
+ "type": "refactoring",
+ "title": "src/util.py",
+ "description": "+0.6 health \u00b7 src/util.py",
+ "severity": "low",
+ "target_id": "src/util.py",
+ "subtype": "split_class",
+ "weight": 0.6
+ },
+ {
+ "id": "drift-2",
+ "type": "doc_drift",
+ "title": "docs/setup.md",
+ "description": "missing_symbol no longer matches the tree",
+ "severity": "low",
+ "target_id": "docs/setup.md",
+ "subtype": "missing_symbol",
+ "weight": 0.5
+ },
+ {
+ "id": "dead-dead1",
+ "type": "dead_code",
+ "title": "old_helper",
+ "description": "Unreachable function (12 lines)",
+ "severity": "low",
+ "target_id": "src/legacy.py",
+ "subtype": "unused_export",
+ "weight": 0.9
+ },
+ {
+ "id": "health-src/tiny.py",
+ "type": "health_finding",
+ "title": "src/tiny.py",
+ "description": "1 finding \u00b7 0.4 deducted",
+ "severity": "low",
+ "target_id": "src/tiny.py",
+ "subtype": "long_method",
+ "weight": 0.4
+ }
+ ],
+ "attention_summary": {
+ "total": 18,
+ "by_source": {
+ "health_finding": 4,
+ "security_finding": 3,
+ "refactoring": 2,
+ "doc_drift": 2,
+ "dead_code": 1,
+ "decisions": 3,
+ "knowledge_silo": 3
+ },
+ "areas": [
+ {
+ "key": "security",
+ "total": 3,
+ "severity": "high",
+ "detail": "2 in the working tree, 1 in git history",
+ "lead": {
+ "title": "config/settings.py",
+ "description": "aws_access_key",
+ "type": "security_finding",
+ "target_id": "config/settings.py",
+ "subtype": "aws_access_key",
+ "severity": "high"
+ }
+ },
+ {
+ "key": "health",
+ "total": 4,
+ "severity": "critical",
+ "detail": "",
+ "lead": {
+ "title": "src/core.py",
+ "description": "2 findings \u00b7 9.5 deducted",
+ "type": "health_finding",
+ "target_id": "src/core.py",
+ "subtype": "god_class",
+ "severity": "critical"
+ }
+ },
+ {
+ "key": "refactoring",
+ "total": 2,
+ "severity": "medium",
+ "detail": "",
+ "lead": {
+ "title": "Engine.run",
+ "description": "+1.8 health, M effort \u00b7 src/core.py",
+ "type": "refactoring",
+ "target_id": "src/core.py",
+ "subtype": "extract_method",
+ "severity": "medium"
+ }
+ },
+ {
+ "key": "doc_drift",
+ "total": 2,
+ "severity": "medium",
+ "detail": "",
+ "lead": {
+ "title": "README.md",
+ "description": "names a file that is not in the tree",
+ "type": "doc_drift",
+ "target_id": "README.md",
+ "subtype": "missing_path",
+ "severity": "medium"
+ }
+ },
+ {
+ "key": "decisions",
+ "total": 3,
+ "severity": "medium",
+ "detail": "1 awaiting review \u00b7 2 hotspots ungoverned",
+ "lead": {
+ "title": "src/core.py",
+ "description": "High-churn file with no governing decision",
+ "type": "ungoverned_hotspot",
+ "target_id": "src/core.py",
+ "subtype": null,
+ "severity": "medium"
+ }
+ },
+ {
+ "key": "ownership",
+ "total": 3,
+ "severity": "medium",
+ "detail": "",
+ "lead": {
+ "title": "src/core.py",
+ "description": "90% single-owner concentration, 12 commits in 90d",
+ "type": "knowledge_silo",
+ "target_id": "src/core.py",
+ "subtype": null,
+ "severity": "medium"
+ }
+ },
+ {
+ "key": "dead_code",
+ "total": 1,
+ "severity": "low",
+ "detail": "",
+ "lead": {
+ "title": "old_helper",
+ "description": "Unreachable function (12 lines)",
+ "type": "dead_code",
+ "target_id": "src/legacy.py",
+ "subtype": "unused_export",
+ "severity": "low"
+ }
+ }
+ ]
+ },
+ "onboarding_targets": [
+ {
+ "path": "src/util.py",
+ "pagerank": 0.25,
+ "doc_words": 0
+ },
+ {
+ "path": "web/app.ts",
+ "pagerank": 0.5,
+ "doc_words": 2
+ },
+ {
+ "path": "src/core.py",
+ "pagerank": 0.4,
+ "doc_words": 2
+ }
+ ],
+ "top_hotspots": [
+ {
+ "file_path": "src/core.py",
+ "commit_count_total": 40,
+ "commit_count_90d": 12,
+ "commit_count_30d": 4,
+ "churn_percentile": 95.0,
+ "temporal_hotspot_score": 3.0,
+ "primary_owner": "Alice",
+ "primary_owner_commit_pct": 0.9,
+ "recent_owner_name": null,
+ "recent_owner_commit_pct": null,
+ "is_hotspot": true,
+ "is_stable": false,
+ "bus_factor": 0,
+ "contributor_count": 0,
+ "lines_added_90d": 0,
+ "lines_deleted_90d": 0,
+ "avg_commit_size": 0.0,
+ "commit_categories": {},
+ "merge_commit_count_90d": 0,
+ "commit_count_capped": false,
+ "age_days": 0,
+ "last_commit_at": "2026-08-20T00:00:00",
+ "change_entropy": 0.0,
+ "change_entropy_pct": 0.0,
+ "prior_defect_count": 0,
+ "bug_magnet": false,
+ "last_fix_at": null,
+ "original_path": null
+ },
+ {
+ "file_path": "web/app.ts",
+ "commit_count_total": 20,
+ "commit_count_90d": 6,
+ "commit_count_30d": 2,
+ "churn_percentile": 75.0,
+ "temporal_hotspot_score": 1.0,
+ "primary_owner": "Bob",
+ "primary_owner_commit_pct": 0.9,
+ "recent_owner_name": null,
+ "recent_owner_commit_pct": null,
+ "is_hotspot": true,
+ "is_stable": false,
+ "bus_factor": 0,
+ "contributor_count": 0,
+ "lines_added_90d": 0,
+ "lines_deleted_90d": 0,
+ "avg_commit_size": 0.0,
+ "commit_categories": {},
+ "merge_commit_count_90d": 0,
+ "commit_count_capped": false,
+ "age_days": 0,
+ "last_commit_at": "2026-08-22T00:00:00",
+ "change_entropy": 0.0,
+ "change_entropy_pct": 0.0,
+ "prior_defect_count": 0,
+ "bug_magnet": false,
+ "last_fix_at": null,
+ "original_path": null
+ }
+ ],
+ "recent_decisions": [
+ {
+ "id": "dec1",
+ "title": "Keep the engine single-threaded",
+ "status": "proposed",
+ "source": "cli",
+ "created_at": "2026-09-02T12:00:00",
+ "staleness_score": 0.0
+ }
+ ],
+ "savings": {
+ "available": false
+ },
+ "sync": {
+ "last_sync_at": "2026-09-02T12:00:00",
+ "last_resync_at": null,
+ "last_sync_model": null,
+ "active_job_id": null,
+ "page_count": 2,
+ "index_storage_bytes": 0
+ }
+}
diff --git a/tests/unit/server/mcp/test_payload_goldens.py b/tests/unit/server/mcp/test_payload_goldens.py
new file mode 100644
index 000000000..e4828ebe1
--- /dev/null
+++ b/tests/unit/server/mcp/test_payload_goldens.py
@@ -0,0 +1,139 @@
+"""Byte-for-byte goldens of real MCP tool payloads.
+
+Pins values, nesting and dict key order (part of the wire format), so a
+refactor of the server code must serve identical bytes. Rewrite with
+``REPOWISE_REWRITE_GOLDEN=1`` only for an intended behaviour change.
+"""
+
+from __future__ import annotations
+
+from datetime import UTC, datetime
+from pathlib import Path
+
+import pytest
+import time_machine
+
+from tests.unit.server.conftest import (
+ assert_payload_golden,
+ normalize_payload,
+ path_placeholders,
+)
+
+GOLDEN_DIR = Path(__file__).parent.parent / "golden" / "mcp"
+# A week after the fixture's index time, so index age is fixed too.
+_CLOCK = datetime(2026, 3, 26, 12, 0, 0, tzinfo=UTC)
+
+# The span the fixture's AuthService (10-100) and login (20-40) rows describe.
+_SERVICE_SOURCE = "\n".join(
+ ['"""Auth service."""', "", "from src.db.models import User", ""]
+ + [""] * 5
+ + [
+ "class AuthService:",
+ ' """Main authentication service."""',
+ "",
+ " def __init__(self, store):",
+ " self.store = store",
+ "",
+ " def _hash(self, password: str) -> str:",
+ " return password[::-1]",
+ "",
+ "",
+ " async def login(self, username: str, password: str) -> Token:",
+ ' """Authenticate a user."""',
+ " user = await self.store.get(User, username)",
+ " if user is None:",
+ " return None",
+ " return self._hash(password)",
+ ]
+ + [f" # line {n}" for n in range(26, 101)]
+)
+
+
+async def repo_root(setup_mcp, tmp_path):
+ """The fixture repo with live source and two embedded pages, at a fixed clock."""
+ import repowise.server.mcp_server as mcp_mod
+
+ source = tmp_path / "src" / "auth" / "service.py"
+ source.parent.mkdir(parents=True, exist_ok=True)
+ source.write_text(_SERVICE_SOURCE + "\n", encoding="utf-8", newline="\n")
+ await mcp_mod._vector_store.embed_and_upsert(
+ "file_page:src/auth/service.py",
+ "Auth Service - Main authentication service class",
+ {"title": "Auth Service", "page_type": "file_page", "target_path": "src/auth/service.py"},
+ )
+ await mcp_mod._vector_store.embed_and_upsert(
+ "file_page:src/db/models.py",
+ "DB Models - SQLAlchemy ORM models",
+ {"title": "DB Models", "page_type": "file_page", "target_path": "src/db/models.py"},
+ )
+ with time_machine.travel(_CLOCK, tick=False):
+ yield tmp_path
+
+
+def _check(name: str, result: dict, root: Path) -> None:
+ assert_payload_golden(
+ GOLDEN_DIR / f"{name}.json", normalize_payload(result, path_placeholders(root))
+ )
+
+
+ ("name", "target", "include"),
+ [
+ ("file", "src/auth/service.py", None),
+ (
+ "file_include",
+ "src/auth/service.py",
+ ["ownership", "last_change", "decisions", "callers"],
+ ),
+ ("module", "src/auth", None),
+ ("symbol", "AuthService", None),
+ # A graph node with no page, no git row and no symbols.
+ ("graph_node_only", "tests/test_service.py", None),
+ ("not_found", "nonexistent_thing_xyz", None),
+ ],
+)
+async def test_get_context_payload_matches_the_golden(repo_root, name, target, include) -> None:
+ from repowise.server.mcp_server import get_context
+
+ result = await get_context([target], include=include)
+ _check(f"get_context_{name}", result, repo_root)
+
+
+async def test_get_symbol_payload_matches_the_golden(repo_root) -> None:
+ from repowise.server.mcp_server import get_symbol
+
+ result = await get_symbol("src/auth/service.py::login")
+ _check("get_symbol", result, repo_root)
+
+
+ ("mode", "query"),
+ [
+ ("symbol", "AuthService"),
+ ("hybrid", "how does AuthService handle authentication"),
+ ("path", "src/auth/service.py"),
+ ],
+)
+async def test_search_codebase_payload_matches_the_golden(repo_root, mode, query) -> None:
+ from repowise.server.mcp_server import search_codebase
+
+ result = await search_codebase(query, mode=mode)
+ _check(f"search_codebase_{mode}", result, repo_root)
+
+
+def test_change_risk_cross_repo_block_matches_the_golden(tmp_path) -> None:
+ from tests.unit.server.test_mcp_change_risk_cross_repo import (
+ PROVIDER_FILE,
+ _block,
+ _enricher,
+ _link,
+ _report,
+ )
+
+ links = [_link(), _link("mobile", "app/order.ts")]
+ block = _block(_enricher(tmp_path, links, _report()), [PROVIDER_FILE, "README.md"])
+ _check("change_risk_cross_repo", block, tmp_path)
diff --git a/tests/unit/server/test_attention_golden.py b/tests/unit/server/test_attention_golden.py
index dfa9f3ef7..ec6a4a0db 100644
--- a/tests/unit/server/test_attention_golden.py
+++ b/tests/unit/server/test_attention_golden.py
@@ -194,7 +194,7 @@ async def test_build_attention_matches_the_golden(
knowledge_silos=_SILOS,
)
- if os.environ.get("REPOWISE_REWRITE_GOLDEN"):
+ if os.environ.get("REPOWISE_REWRITE_GOLDEN") == "1":
GOLDEN.parent.mkdir(exist_ok=True)
GOLDEN.write_text(json.dumps(result, indent=2) + "\n", encoding="utf-8", newline="\n")
pytest.skip("golden rewritten")
diff --git a/tests/unit/server/test_knowledge_map_golden.py b/tests/unit/server/test_knowledge_map_golden.py
index b96d79ca5..84c64e0fd 100644
--- a/tests/unit/server/test_knowledge_map_golden.py
+++ b/tests/unit/server/test_knowledge_map_golden.py
@@ -125,7 +125,7 @@ async def test_knowledge_map_matches_the_golden(
assert resp.status_code == 200
result["endpoint"] = resp.json()
- if os.environ.get("REPOWISE_REWRITE_GOLDEN"):
+ if os.environ.get("REPOWISE_REWRITE_GOLDEN") == "1":
GOLDEN.parent.mkdir(exist_ok=True)
GOLDEN.write_text(json.dumps(result, indent=2) + "\n", encoding="utf-8", newline="\n")
pytest.skip("golden rewritten")
diff --git a/tests/unit/server/test_overview_summary_golden.py b/tests/unit/server/test_overview_summary_golden.py
new file mode 100644
index 000000000..62f7e3d10
--- /dev/null
+++ b/tests/unit/server/test_overview_summary_golden.py
@@ -0,0 +1,157 @@
+"""Golden of the whole ``/overview-summary`` payload, byte for byte.
+
+Pins every block, value and dict key order the Overview page reads, so a
+refactor of ``overview_summary`` must serve identical JSON. Rewrite with
+``REPOWISE_REWRITE_GOLDEN=1`` only for an intended behaviour change.
+"""
+
+from __future__ import annotations
+
+import json
+from datetime import UTC, datetime
+from pathlib import Path
+
+import pytest
+import time_machine
+from httpx import AsyncClient
+from sqlalchemy import update
+
+from repowise.core.persistence.database import get_session
+from repowise.core.persistence.models import (
+ DecisionRecord,
+ GitMetadata,
+ GraphNode,
+ HealthFileMetric,
+ Page,
+)
+from tests.unit.server.conftest import (
+ assert_payload_golden,
+ create_test_repo,
+ normalize_payload,
+ path_placeholders,
+)
+from tests.unit.server.test_attention_golden import _seed as seed_findings
+
+GOLDEN = Path(__file__).parent / "golden" / "overview_summary.json"
+_CLOCK = datetime(2026, 9, 2, 12, 0, 0, tzinfo=UTC)
+
+
+async def _seed_index(session_factory, repo_id: str) -> None:
+ async with get_session(session_factory) as session:
+ for i, (path, lang, entry, rank) in enumerate(
+ [
+ ("src/core.py", "python", True, 0.4),
+ ("src/util.py", "python", False, 0.25),
+ ("web/app.ts", "typescript", True, 0.5),
+ ("tests/test_core.py", "python", False, 0.05),
+ ]
+ ):
+ session.add(
+ GraphNode(
+ id=f"gn{i}",
+ repository_id=repo_id,
+ node_id=path,
+ node_type="file",
+ language=lang,
+ symbol_count=i + 2,
+ is_entry_point=entry,
+ is_test=path.startswith("tests/"),
+ pagerank=rank,
+ created_at=_CLOCK,
+ )
+ )
+ for i, (path, owner, hotspot, churn) in enumerate(
+ [
+ ("src/core.py", "Alice", True, 0.95),
+ ("src/util.py", "Alice", False, 0.5),
+ ("web/app.ts", "Bob", True, 0.75),
+ ]
+ ):
+ session.add(
+ GitMetadata(
+ id=f"gm{i}",
+ repository_id=repo_id,
+ file_path=path,
+ commit_count_total=40 - i * 10,
+ commit_count_90d=12 - i * 3,
+ commit_count_30d=4 - i,
+ last_commit_at=datetime(2026, 8, 20 + i, tzinfo=UTC),
+ primary_owner_name=owner,
+ primary_owner_commit_pct=0.9,
+ top_authors_json=json.dumps([{"name": owner, "count": 30}]),
+ is_hotspot=hotspot,
+ churn_percentile=churn,
+ temporal_hotspot_score=3.0 - i,
+ created_at=_CLOCK,
+ updated_at=_CLOCK,
+ )
+ )
+ for i, (path, status, confidence) in enumerate(
+ [("src/core.py", "fresh", 0.9), ("web/app.ts", "stale", 0.5)]
+ ):
+ session.add(
+ Page(
+ id=f"file_page:{path}",
+ repository_id=repo_id,
+ page_type="file_page",
+ title=path,
+ content=f"# {path}",
+ target_path=path,
+ source_hash=f"h{i}",
+ model_name="mock",
+ provider_name="template" if i else "mock",
+ generation_level=2,
+ confidence=confidence,
+ freshness_status=status,
+ metadata_json="{}",
+ created_at=_CLOCK,
+ updated_at=_CLOCK,
+ )
+ )
+ session.add(
+ DecisionRecord(
+ id="dec1",
+ repository_id=repo_id,
+ title="Keep the engine single-threaded",
+ status="proposed",
+ decision="One worker per repo",
+ rationale="Simpler locking",
+ affected_files_json=json.dumps(["src/core.py"]),
+ source="cli",
+ confidence=0.9,
+ created_at=_CLOCK,
+ updated_at=_CLOCK,
+ )
+ )
+ # The findings seed leaves scores unset; score its one code file.
+ await session.execute(
+ update(HealthFileMetric)
+ .where(
+ HealthFileMetric.repository_id == repo_id,
+ HealthFileMetric.file_path == "src/core.py",
+ )
+ .values(
+ score=4.5,
+ defect_score=4.5,
+ maintainability_score=5.5,
+ performance_score=9.5,
+ max_ccn=12,
+ max_nesting=3,
+ )
+ )
+ await session.commit()
+
+
+async def test_overview_summary_matches_the_golden(
+ client: AsyncClient, session_factory, tmp_path
+) -> None:
+ with time_machine.travel(_CLOCK, tick=False):
+ repo = await create_test_repo(client, tmp_path)
+ await seed_findings(session_factory, repo["id"])
+ await _seed_index(session_factory, repo["id"])
+ resp = await client.get(f"/api/repos/{repo['id']}/overview-summary")
+
+ assert resp.status_code == 200
+ replace = {repo["id"]: "<repo-id>", **path_placeholders(tmp_path, "<tmp>")}
+ assert_payload_golden(GOLDEN, normalize_payload(resp.json(), replace))
diff --git a/tests/unit/server/test_ownership_rollups_golden.py b/tests/unit/server/test_ownership_rollups_golden.py
index 7761a30a5..97f7ae497 100644
--- a/tests/unit/server/test_ownership_rollups_golden.py
+++ b/tests/unit/server/test_ownership_rollups_golden.py
@@ -249,7 +249,7 @@ async def test_ownership_rollups_match_the_golden(client: AsyncClient, session_f
),
}
- if os.environ.get("REPOWISE_REWRITE_GOLDEN"):
+ if os.environ.get("REPOWISE_REWRITE_GOLDEN") == "1":
GOLDEN.parent.mkdir(exist_ok=True)
GOLDEN.write_text(json.dumps(result, indent=2) + "\n", encoding="utf-8", newline="\n")
pytest.skip("golden rewritten")