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): stop listing the test layer as an architecture layer (#2726)
Raghav Chamadiya6239e7db4a82
diff --git a/docs/agent/MCP_TOOLS.md b/docs/agent/MCP_TOOLS.mdindex b32d6d8dc..5e219bdbf 100644--- a/docs/agent/MCP_TOOLS.md+++ b/docs/agent/MCP_TOOLS.md@@ -224,7 +224,7 @@ Architecture summary, module map, and entry points.| `repo` | string | No | *(workspace only)* Target repo alias, or `"all"` || `include` | list[string] | No | Opt-in blocks, any combination of `"content"`, `"outline"`, `"tour"`, `"decisions"`, `"graph"`, `"ownership"` (see below) |-**Returns (default):** `title`, `content_md` (the overview essay's summary section), `key_modules` (name, path, outline section), `entry_points`, `architecture` (layer names, file counts, layer order), `code_health`, `git_health`, `next_actions` (per horizon, week and quarter: the first three stored actions as `id`, `tier`, `title`, `impact`, `done_when`, `target`, with `total` and `by_tier`; `unavailable` names stores the index predates; replaced by `next_actions_reason` when they cannot be read), `_meta`, and in workspace mode a `workspace` footer. The response's `more` field names the opt-in blocks.+**Returns (default):** `title`, `content_md` (the overview essay's summary section), `key_modules` (name, path, outline section), `entry_points`, `architecture` (layer names and file counts in stack order, the test layer left out; `layer_order` only for an index without knowledge-graph layers), `code_health`, `git_health`, `next_actions` (per horizon, week and quarter: the first three stored actions as `id`, `tier`, `title`, `impact`, `done_when`, `target`, with `total` and `by_tier`; `unavailable` names stores the index predates; replaced by `next_actions_reason` when they cannot be read), `_meta`, and in workspace mode a `workspace` footer. The response's `more` field names the opt-in blocks.**Opt-in blocks** — omitted unless named in `include`, and not computed at all when they are not:diff --git a/packages/core/src/repowise/core/generation/layers.py b/packages/core/src/repowise/core/generation/layers.pyindex ac11dc75c..58fdd311a 100644--- a/packages/core/src/repowise/core/generation/layers.py+++ b/packages/core/src/repowise/core/generation/layers.py@@ -183,6 +183,18 @@ _CANONICAL_RANK_BY_KEY: dict[str, int] = {}+_ADJACENT_KEYS: frozenset[str] = frozenset(layer_key(la) for la in ADJACENT_LAYERS)+++def is_adjacent_layer(layer: str) -> bool:+ """True for a layer outside the architecture (tests), by name or ``layer:`` id.++ The layer still partitions its files; surfaces that describe the+ architecture leave it out.+ """+ return layer_key(layer) in _ADJACENT_KEYS++def _is_pinned(layer: str) -> bool:return layer_key(layer) in _PINNED_KEYSdiff --git a/packages/core/src/repowise/core/generation/page_generator/orchestrate.py b/packages/core/src/repowise/core/generation/page_generator/orchestrate.pyindex 4ca635e10..e9d5ef567 100644--- a/packages/core/src/repowise/core/generation/page_generator/orchestrate.py+++ b/packages/core/src/repowise/core/generation/page_generator/orchestrate.py@@ -551,7 +551,7 @@ class _GenerationRun:the import graph) and reference only pages that will exist, so neitherspawns new LLM work."""- from ..layers import compute_layer_order, infer_layer, layer_key+ from ..layers import compute_layer_order, infer_layer, is_adjacent_layer, layer_keyfrom ..tour import build_tourimport_edges = self._file_import_edges()@@ -608,7 +608,12 @@ class _GenerationRun:file_layers[path] = layer_iddisplay_of.setdefault(layer_id, display)self.layer_order_ids = compute_layer_order(file_layers, import_edges)- self.layer_order = [display_of.get(lid, lid) for lid in self.layer_order_ids]+ # Tests keep their place in the tree but are not a layer of the stack.+ self.layer_order = [+ display_of.get(lid, lid)+ for lid in self.layer_order_ids+ if not is_adjacent_layer(lid)+ ]# ------------------------------------------------------------------# Level runnerdiff --git a/packages/server/src/repowise/server/mcp_server/_scope.py b/packages/server/src/repowise/server/mcp_server/_scope.pyindex d41412eb3..c6c14f6fc 100644--- a/packages/server/src/repowise/server/mcp_server/_scope.py+++ b/packages/server/src/repowise/server/mcp_server/_scope.py@@ -48,10 +48,15 @@ async def _load_layers(cached = _CACHE.get(cache_key)if cached is not None:return cached+ from repowise.core.generation.layers import is_adjacent_layerfrom repowise.core.persistence.crud.knowledge_graph import get_kg_layersrows = await get_kg_layers(session, repo_id)- layers = [(row.name, _layer_paths(row.node_ids_json)) for row in rows]+ layers = [+ (row.name, _layer_paths(row.node_ids_json))+ for row in rows+ if not is_adjacent_layer(row.layer_id)+ ]if len(_CACHE) >= _CACHE_LIMIT:_CACHE.clear()_CACHE[cache_key] = layersdiff --git a/packages/server/src/repowise/server/mcp_server/tool_overview/graph.py b/packages/server/src/repowise/server/mcp_server/tool_overview/graph.pyindex d32af48fc..ee1c5f91b 100644--- a/packages/server/src/repowise/server/mcp_server/tool_overview/graph.py+++ b/packages/server/src/repowise/server/mcp_server/tool_overview/graph.py@@ -8,6 +8,7 @@ from typing import Anyfrom sqlalchemy import select+from repowise.core.generation.layers import is_adjacent_layerfrom repowise.core.persistence.crud import (get_kg_layers as _get_kg_layers,)@@ -88,8 +89,12 @@ def _stored_label(node: GraphNode) -> str:async def _build_architecture(session: Any, repository: Any) -> dict[str, Any]:- """KG architecture layers + tour availability."""- kg_layers = await _get_kg_layers(session, repository.id)+ """KG architecture layers, in stack order, + tour availability."""+ kg_layers = [+ layer+ for layer in await _get_kg_layers(session, repository.id)+ if not is_adjacent_layer(layer.layer_id)+ ]kg_tour = await _get_kg_tour_steps(session, repository.id)if not kg_layers:return {}diff --git a/packages/server/src/repowise/server/mcp_server/tool_overview/tour.py b/packages/server/src/repowise/server/mcp_server/tool_overview/tour.pyindex b9e0fb9df..1ee324ac0 100644--- a/packages/server/src/repowise/server/mcp_server/tool_overview/tour.py+++ b/packages/server/src/repowise/server/mcp_server/tool_overview/tour.py@@ -7,6 +7,7 @@ from typing import Anyfrom sqlalchemy import select+from repowise.core.generation.layers import is_adjacent_layerfrom repowise.core.generation.onboarding.slots import (ONBOARDING_ORDER,PROMOTED_SLOTS,@@ -90,9 +91,19 @@ def _build_guided_tour("in order — entry points first, then the files they import, ""with infrastructure last. Each step builds on the previous.")- layer_order = ov_meta.get("layer_order") or []- if layer_order:- result.setdefault("architecture", {})["layer_order"] = layer_order+ # The KG layers already arrive in stack order under their current names;+ # the stored name list is only the fallback for an index without them.+ architecture = result.setdefault("architecture", {})+ # Filter on the stable id where the names pair with it one to one; a+ # model-given name ("Automated Test Suites") says nothing about the layer.+ names = ov_meta.get("layer_order") or []+ ids = ov_meta.get("layer_order_ids") or []+ keyed = zip(names, ids, strict=True) if len(ids) == len(names) else zip(names, names, strict=True)+ layer_order = [name for name, key in keyed if not is_adjacent_layer(key)]+ if layer_order and not architecture.get("layers"):+ architecture["layer_order"] = layer_order+ if not architecture:+ del result["architecture"]def _tour_step(n: int, s: dict[str, Any], sections: dict[str, str | None]) -> dict[str, Any]:diff --git a/tests/fixtures/mcp/tool_response_shapes.json b/tests/fixtures/mcp/tool_response_shapes.jsonindex 35feb06ea..fb939cba8 100644--- a/tests/fixtures/mcp/tool_response_shapes.json+++ b/tests/fixtures/mcp/tool_response_shapes.json@@ -1288,9 +1288,6 @@}},"architecture": {- "layer_order": [- null- ],"layers": [{"file_count": null,diff --git a/tests/unit/generation/test_layers.py b/tests/unit/generation/test_layers.pyindex e2b7ad7f2..d1075983b 100644--- a/tests/unit/generation/test_layers.py+++ b/tests/unit/generation/test_layers.py@@ -7,6 +7,7 @@ from repowise.core.generation.layers import (DOCS_TOOLING_LAYER,compute_layer_order,infer_layer,+ is_adjacent_layer,layer_key,layer_order_basis,)@@ -364,6 +365,13 @@ def test_layer_key_normalises_both_spellings():assert layer_key("Docs & Tooling") == layer_key("layer:docs-tooling") == "docs-tooling"+def test_is_adjacent_layer_names_tests_by_name_or_id():+ assert is_adjacent_layer("Test")+ assert is_adjacent_layer("layer:test")+ assert not is_adjacent_layer("layer:service")+ assert not is_adjacent_layer(DOCS_TOOLING_LAYER)++def test_compute_layer_order_single_layer():assert compute_layer_order({"a.py": "API"}, []) == ["API"]assert compute_layer_order({}, []) == []diff --git a/tests/unit/server/mcp/test_scope_hint.py b/tests/unit/server/mcp/test_scope_hint.pyindex 579069983..6963b1cb9 100644--- a/tests/unit/server/mcp/test_scope_hint.py+++ b/tests/unit/server/mcp/test_scope_hint.py@@ -211,3 +211,20 @@ async def test_answer_projection_stamps_the_key_from_served_paths(empty = {"confidence": "high", "citations": [], "_meta": {"scope_hint": "stale sentence"}}await _refresh_freshness(empty, None)assert "scope_hint" not in empty["_meta"]+++async def test_the_test_layer_is_never_named(session: AsyncSession, repo_id: str):+ await _seed(+ session,+ repo_id,+ [+ _layer(repo_id, "layer:test", "Automated Checks", ["tests/a.py", "tests/b.py"]),+ _layer(repo_id, "layer:ui", "Web Screens", ["web/a.tsx"]),+ _layer(repo_id, "layer:service", "Core Logic", ["src/core.py"]),+ ],+ )++ hint = await unrelated_scope_hint(session, repo_id, ["src/core.py"], cache_key="k-test")++ assert hint == "Unrelated to what was served: Web Screens (1 file)."diff --git a/tests/unit/server/mcp/test_tool_overview.py b/tests/unit/server/mcp/test_tool_overview.pyindex fa40039b0..d46340e45 100644--- a/tests/unit/server/mcp/test_tool_overview.py+++ b/tests/unit/server/mcp/test_tool_overview.py@@ -210,6 +210,30 @@ def test_layer_order_is_attached_under_architecture_even_without_the_tour():assert result == {"architecture": {"layers": [], "layer_order": ["api", "core"]}}+def test_layer_order_yields_to_kg_layers_and_never_lists_tests():+ page = SimpleNamespace(metadata_json=json.dumps({"layer_order": ["api", "core", "Test"]}))+ with_layers: dict = {"architecture": {"layers": [{"name": "API", "file_count": 3}]}}+ ov._build_guided_tour(page, with_layers, {}, False)+ assert "layer_order" not in with_layers["architecture"]++ without: dict = {}+ ov._build_guided_tour(page, without, {}, False)+ assert without == {"architecture": {"layer_order": ["api", "core"]}}++ # A model-given test layer name is caught through its paired id.+ named = SimpleNamespace(+ metadata_json=json.dumps(+ {+ "layer_order": ["Web Entry", "Automated Checks"],+ "layer_order_ids": ["layer:api", "layer:test"],+ }+ )+ )+ by_id: dict = {}+ ov._build_guided_tour(named, by_id, {}, False)+ assert by_id == {"architecture": {"layer_order": ["Web Entry"]}}++# ---------------------------------------------------------------------------# Workspace footer# ---------------------------------------------------------------------------diff --git a/tests/unit/server/test_mcp_kg_enrichment.py b/tests/unit/server/test_mcp_kg_enrichment.pyindex 0a448ea8e..80b7fea68 100644--- a/tests/unit/server/test_mcp_kg_enrichment.py+++ b/tests/unit/server/test_mcp_kg_enrichment.py@@ -205,6 +205,15 @@ async def populated_db_with_kg(session: AsyncSession, repo_id: str) -> str:node_ids_json=json.dumps(["file:src/utils/helpers.py"]),display_order=1,),+ KnowledgeGraphLayer(+ id="kgl3",+ repository_id=rid,+ layer_id="layer:test",+ name="Automated Checks",+ description="Unit tests",+ node_ids_json=json.dumps(["file:tests/test_graph.py"]),+ display_order=2,+ ),]for layer in kg_layers:session.add(layer)@@ -348,7 +357,9 @@ async def test_overview_includes_architecture_when_kg_exists(setup_mcp_with_kg):assert "architecture" in resultarch = result["architecture"]assert "layers" in arch+ # The test layer partitions its files but is not part of the architecture.assert len(arch["layers"]) == 2+ assert all(layer["name"] != "Automated Checks" for layer in arch["layers"])assert any(layer["name"] == "Core Ingestion" for layer in arch["layers"])assert any(layer["name"] == "Utilities" for layer in arch["layers"])assert arch["tour_available"] is True