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(workspace): read the service-name map and gateway routes only from production deploy config (#4648)
Raghav Chamadiya627aea31bc50
diff --git a/docs/reference/WORKSPACE_CONTRACTS.md b/docs/reference/WORKSPACE_CONTRACTS.mdindex 62532e63f..9d42a0b6e 100644--- a/docs/reference/WORKSPACE_CONTRACTS.md+++ b/docs/reference/WORKSPACE_CONTRACTS.md@@ -152,9 +152,11 @@ under `context-path: /uaa` is `POST /uaa/users`. A module given two different banone.Each repo is walked once per update for these file names; test, example and build-output-directories are skipped, and files at the workspace root are read too. A name two files-place in different repos is left unmapped rather than guessed. To override or fill a gap, add-the host or base token to `service_bases`, which always wins.+directories are skipped, and so is any file the code-origin classifier calls test, docs or+example, vendored or generated (a compose file under `docs/`, `demo/` or `e2e-tests/`).+Files at the workspace root are read too. A name two files place in different repos is left+unmapped rather than guessed. To override or fill a gap, add the host or base token to+`service_bases`, which always wins.A gateway source states routes rather than names: a path prefix the gateway forwards to aservice, and the path it forwards (Spring `StripPrefix`, `PrefixPath` and adiff --git a/packages/core/src/repowise/core/workspace/service_names/__init__.py b/packages/core/src/repowise/core/workspace/service_names/__init__.pyindex 79249c2b9..3b2270f9b 100644--- a/packages/core/src/repowise/core/workspace/service_names/__init__.py+++ b/packages/core/src/repowise/core/workspace/service_names/__init__.py@@ -33,6 +33,7 @@ from dataclasses import asdict, dataclass, fieldfrom pathlib import Pathfrom typing import Any+from repowise.core.code_origin import CodeOrigin, code_originfrom repowise.core.fs_walk import PRUNED_DIRS, walk_repofrom . import (@@ -86,6 +87,11 @@ _PRUNE = PRUNED_DIRS | {"dist","build",}+# The same question asked of each gated file, by the shared classifier: a+# compose file under ``docs/``, ``demo/`` or ``e2e-tests/`` describes a stack+# that is not the deployed one. ``_PRUNE`` stays as the walk's prune; it also+# skips nested ``samples/`` that this first-segment rule does not see.+_NOT_DEPLOYED: frozenset[CodeOrigin] = frozenset({"test", "docs_example", "vendored", "generated"})_MAX_BYTES = 512_000@@ -242,9 +248,13 @@ def _walk(alias: str, root: Path) -> list[_Found]:rel_dir = dirpath.relative_to(root)parents = tuple(p.lower() for p in rel_dir.parts)for filename in sorted(filenames):- path = dirpath / filename- for source, claim in _claims_in(path, parents):- found.append(_Found(source, claim, alias, f"{alias}/{(rel_dir / filename).as_posix()}"))+ claims = _claims_in(dirpath / filename, parents)+ if not claims:+ continue+ rel = (rel_dir / filename).as_posix()+ if code_origin(rel, repo_root=root) in _NOT_DEPLOYED:+ continue+ found.extend(_Found(source, claim, alias, f"{alias}/{rel}") for source, claim in claims)return founddiff --git a/tests/unit/workspace/test_service_names.py b/tests/unit/workspace/test_service_names.pyindex ee855431f..9fcc19b01 100644--- a/tests/unit/workspace/test_service_names.py+++ b/tests/unit/workspace/test_service_names.py@@ -148,6 +148,41 @@ def test_a_name_claimed_for_two_repos_is_left_unmapped(tmp_path: Path) -> None:assert m.ambiguous[(HOST, "api")] == ("a", "b")+ "rel",+ [+ "docs/reference/docker/docker-compose.yml",+ "e2e-tests/docker-compose.yml",+ "integration-tests/docker-compose.yml",+ "demo/docker-compose.yml",+ "tutorial-1/docker-compose.yml",+ "third_party/stack/docker-compose.yml",+ ],+)+def test_only_deployed_config_claims_a_name(tmp_path: Path, rel: str) -> None:+ # A docs, demo, test or vendored stack is not the deployed one: its sole+ # claim on a name must not map it, nor a second claim make a real name ambiguous.+ compose = "services:\n api: {build: .}\n es01: {build: ./es}\n"+ (tmp_path / "svc" / "deploy").mkdir(parents=True) # a deploy/ tree is production+ (tmp_path / "svc" / "deploy" / "docker-compose.yml").write_text(+ "services:\n api: {build: ..}\n"+ )+ (tmp_path / "other" / rel).parent.mkdir(parents=True)+ (tmp_path / "other" / rel).write_text(compose)+ m = build_service_name_map(_repos(tmp_path, "svc", "other"))+ assert _mapped(m) == {"api": ("svc", "compose")}+ assert not m.ambiguous+++def test_a_docs_gateway_config_states_no_route(tmp_path: Path) -> None:+ conf = "server {\n location /api/ { proxy_pass http://api:8080/; }\n}\n"+ for rel in ("nginx/default.conf", "docs/nginx/default.conf"):+ (tmp_path / "web" / rel).parent.mkdir(parents=True, exist_ok=True)+ (tmp_path / "web" / rel).write_text(conf)+ m = build_service_name_map(_repos(tmp_path, "web"))+ assert {r.file for r in m.routes} == {"web/nginx/default.conf"}++def test_k8s_service_by_selector_label_and_never_a_sibling_by_location() -> None:m = build_service_name_map({"petclinic": FIXTURES / "petclinic"})# demo-db sits in the same repo beside another Service: not its own.