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(matching): mark internally-served consumers to prevent cross-repo candidate linking (#2884)
Rishabh Mishrab74b38c791db
diff --git a/packages/core/src/repowise/core/workspace/matching/__init__.py b/packages/core/src/repowise/core/workspace/matching/__init__.pyindex 8f30573dc..55a015c5e 100644--- a/packages/core/src/repowise/core/workspace/matching/__init__.py+++ b/packages/core/src/repowise/core/workspace/matching/__init__.py@@ -71,6 +71,7 @@ def _exact_pass(state: MatchState) -> None:providers = [p for k in keys for p in state.provider_index[k]]for provider in prefer_target_repo(providers, consumer):if internal(provider, consumer):+ state.mark_served(consumer)continueif rules.accepts is not None and not rules.accepts(provider, consumer):continuediff --git a/packages/core/src/repowise/core/workspace/matching/common.py b/packages/core/src/repowise/core/workspace/matching/common.pyindex 7fbe0d5a0..13b2c3d12 100644--- a/packages/core/src/repowise/core/workspace/matching/common.py+++ b/packages/core/src/repowise/core/workspace/matching/common.py@@ -52,6 +52,10 @@ class MatchState:if c.contract_type == contract_type and id(c) not in self.matched]+ def mark_served(self, consumer: Contract) -> None:+ """Mark *consumer* as served internally so later matching passes skip it."""+ self.matched.add(id(consumer))+def add(self,consumer: Contract,diff --git a/tests/unit/workspace/test_contracts.py b/tests/unit/workspace/test_contracts.pyindex 6e358e6ae..d6ee6636e 100644--- a/tests/unit/workspace/test_contracts.py+++ b/tests/unit/workspace/test_contracts.py@@ -960,6 +960,27 @@ class TestMatchContracts:links = match_contracts(contracts)assert len(links) == 2+ def test_consumer_served_by_own_service_exact_does_not_fall_through_to_candidate(self) -> None:+ contracts = [+ self._contract(repo="web", role="provider", contract_id="http::GET::/api/orders", file_path="server.ts"),+ self._contract(repo="web", role="consumer", contract_id="http::GET::/api/orders", file_path="client.ts"),+ self._contract(repo="legacy", role="provider", contract_id="http::GET::/orders", file_path="routes.py"),+ ]+ links = match_contracts(contracts)+ assert len(links) == 0++ def test_consumer_without_internal_provider_still_matches_candidate(self) -> None:+ contracts = [+ self._contract(repo="web", role="consumer", contract_id="http::GET::/api/orders", file_path="client.ts"),+ self._contract(repo="legacy", role="provider", contract_id="http::GET::/orders", file_path="routes.py"),+ ]+ links = match_contracts(contracts)+ assert len(links) == 1+ assert links[0].provider_repo == "legacy"+ assert links[0].consumer_repo == "web"+ assert links[0].match_type == "candidate"++# ---------------------------------------------------------------------------# Candidate matching (mount / version / base-prefix tolerant)