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(csharp): resolve calls between fragments of a partial class (#2776)
Raghav Chamadiya926eb0dd407b
diff --git a/packages/core/src/repowise/core/analysis/dead_code/analyzer.py b/packages/core/src/repowise/core/analysis/dead_code/analyzer.pyindex 17cbc42a9..1f3d50dc7 100644--- a/packages/core/src/repowise/core/analysis/dead_code/analyzer.py+++ b/packages/core/src/repowise/core/analysis/dead_code/analyzer.py@@ -1628,12 +1628,11 @@ class DeadCodeAnalyzer:# reported all three as unused. The set is shared with the# unused-export pass, so it also carries types this population can# never hold — a method or an interface is filtered out above.- is_used = any(- self.graph.get_edge_data(pred, node, {}).get("edge_type")- in REACHABILITY_USE_EDGE_TYPES- for pred in self.graph.predecessors(node)- )- if is_used:+ # ``new X(..)`` lands on X's constructor (``path::X::X``) when X+ # declares one, and constructing a type uses it.+ if self._has_inbound_use(node) or self._has_inbound_use(+ f"{file_path}::{sym_name}::{sym_name}"+ ):continue# Dispatch-table pattern: a private helper imported by name@@ -1674,6 +1673,16 @@ class DeadCodeAnalyzer:return findings+ def _has_inbound_use(self, node: str) -> bool:+ """Whether any reachability-use edge lands on *node* (False if absent)."""+ if not self.graph.has_node(node):+ return False+ return any(+ self.graph.get_edge_data(pred, node, {}).get("edge_type")+ in REACHABILITY_USE_EDGE_TYPES+ for pred in self.graph.predecessors(node)+ )+def _is_internal_candidate(self, node_data: dict, dynamic_patterns: tuple[str, ...], whitelist: set[str]) -> bool:diff --git a/packages/core/src/repowise/core/ingestion/call_resolver.py b/packages/core/src/repowise/core/ingestion/call_resolver.pyindex f513f6bd6..fa7b88a94 100644--- a/packages/core/src/repowise/core/ingestion/call_resolver.py+++ b/packages/core/src/repowise/core/ingestion/call_resolver.py@@ -233,11 +233,15 @@ class CallResolver(LanguageStrategiesMixin, ReceiverTypingMixin):import_maps: Any | None = None,heritage_parents: dict[str, set[str]] | None = None,return_type_chain_languages: frozenset[str] | None = None,+ partial_fragments: dict[tuple[str, str], tuple[str, ...]] | None = None,) -> None:# {type symbol id: parent type symbol ids}, from the caller's already# resolved heritage. Absent when the resolver is built standalone, in# which case the inherited tier simply never fires.self._heritage_parents: dict[str, set[str]] = heritage_parents or {}+ # {(file, partial type name): files declaring a fragment of it}, from+ # the builder's C#/VB.NET partial pass. Empty in every other language.+ self._partial_fragments = partial_fragments or {}self._return_type_chain_languages = (PRODUCTION_RETURN_TYPE_CHAIN_LANGUAGESif return_type_chain_languages is None@@ -980,6 +984,37 @@ class CallResolver(LanguageStrategiesMixin, ReceiverTypingMixin):return Nonereturn self._file_methods.get(file_path, {}).get((caller_class, call.target_name))+ def _partial_fragment_member(self, file_path: str, caller_id: str, name: str) -> str | None:+ """The caller's class member *name* declared in another fragment of it.++ Every fragment of a C#/VB.NET ``partial`` type is one class scope, so a+ member (nested types included) that any fragment declares is visible by+ bare name in all of them. The lookup is keyed on the caller's file and+ class, so a same-named member of an unrelated class never answers.+ Fragments are asked in path order; an overload set split across them+ binds to the first. A nested type answers with its constructor when it+ declares one, as ``new X(..)`` does within a single file.+ """+ caller_class = _extract_class_from_symbol_id(caller_id)+ if not caller_class:+ return None+ for fragment in self._partial_fragments.get((file_path, caller_class), ()):+ if fragment == file_path:+ continue+ methods = self._file_methods.get(fragment, {})+ sym_id = methods.get((caller_class, name))+ if sym_id is None or sym_id == caller_id:+ continue+ if self._symbols_by_id[sym_id].kind in _TYPE_KINDS:+ return methods.get((name, name), sym_id)+ # A call site does not record ``new``, so ``new FaultGenerator()``+ # and a member method ``FaultGenerator()`` look alike. When the+ # repo also declares a type of that name, the method is a guess.+ if name in self._csharp_type_names:+ return None+ return sym_id+ return None+def _resolve_free_call(self,file_path: str,@@ -999,6 +1034,15 @@ class CallResolver(LanguageStrategiesMixin, ReceiverTypingMixin):handled, resolved = self._same_file_free_call(file_path, call, caller_id)if handled:return resolved+ # Still the caller's own class, declared in a sibling partial fragment.+ # Not asked when this file declares the name itself: Tier 1 declines a+ # call into the caller's own overload set (one id), and a same-named+ # overload in another fragment is no better evidence than that. Nor for a+ # member call on its bare fallback: its receiver is not the caller's class.+ if not call.receiver_name and target_name not in self._file_symbols.get(file_path, {}):+ sym_id = self._partial_fragment_member(file_path, caller_id, target_name)+ if sym_id is not None:+ return ResolvedCall(caller_id, sym_id, 0.95, call.line, "enclosing_class")# A language may see names no import mentions (a package sibling, a# C/C++ build target), and those beat the import and global tiers.@@ -1374,15 +1418,18 @@ class CallResolver(LanguageStrategiesMixin, ReceiverTypingMixin):) -> ResolvedCall | None:"""Strategy 3: receiver is "self" or "this", so look in the same class.- Only the caller's own file can hold the match, so index straight- into it instead of scanning every file's method dict.+ Only the caller's own file, or a sibling fragment of a partial class,+ can hold the match, so index straight into those instead of scanning+ every file's method dict."""if call.receiver_name not in ("self", "this"):return Nonecaller_class = _extract_class_from_symbol_id(caller_id)if not caller_class:return None- sym_id = self._file_methods.get(file_path, {}).get((caller_class, call.target_name))+ sym_id = self._file_methods.get(file_path, {}).get(+ (caller_class, call.target_name)+ ) or self._partial_fragment_member(file_path, caller_id, call.target_name)if sym_id is None or sym_id == caller_id:return Nonereturn ResolvedCall(caller_id, sym_id, 0.95, call.line, "self_scope")diff --git a/packages/core/src/repowise/core/ingestion/graph/_resolvers.py b/packages/core/src/repowise/core/ingestion/graph/_resolvers.pyindex 9a338d721..9c6974b80 100644--- a/packages/core/src/repowise/core/ingestion/graph/_resolvers.py+++ b/packages/core/src/repowise/core/ingestion/graph/_resolvers.py@@ -401,9 +401,21 @@ class ResolveMixin:continueif self._graph.has_node(rel):rels.append(rel)+ # ``Policy`1`` is the generic ``Policy<T>``; symbol ids and+ # imported names spell it ``Policy``.+ local_name = fqn.rsplit(".", 1)[-1].split("`", 1)[0]+ fragments = tuple(sorted(rels))+ for rel in rels:+ # Two partial types sharing a bare name in one file+ # (``Policy`` and ``Policy<T>``, or two namespaces) are+ # told apart by nothing the call resolver sees, so+ # neither lends that file its fragments.+ key = (rel, local_name)+ self._partial_fragments[key] = (+ () if key in self._partial_fragments else fragments+ )if len(rels) < 2:continue- local_name = fqn.rsplit(".", 1)[-1]for a in rels:for b in rels:if a == b or self._graph.has_edge(a, b):@@ -609,6 +621,7 @@ class ResolveMixin:repo_path=str(self._repo_path) if self._repo_path else None,import_maps=self._shared_import_maps(),heritage_parents=self._heritage_parents(),+ partial_fragments=self._partial_fragments,)# Record which C/C++ declarations were paired with a definition. Thediff --git a/packages/core/src/repowise/core/ingestion/graph/builder.py b/packages/core/src/repowise/core/ingestion/graph/builder.pyindex 276037ff2..8f4349d42 100644--- a/packages/core/src/repowise/core/ingestion/graph/builder.py+++ b/packages/core/src/repowise/core/ingestion/graph/builder.py@@ -63,6 +63,10 @@ class GraphBuilder(MetricsMixin, ResolveMixin, EdgesMixin, SerializeMixin, Rehyd# Resolver-built DotNetProjectIndex, stashed by build() for the# dynamic-hints phase to reuse (see build()).self.dotnet_index: Any | None = None+ # {(file, partial type's bare name): every file declaring a fragment+ # of that type}, filled by ``_resolve_dotnet_partials`` so the call+ # resolver can treat the fragments as the one class scope they are.+ self._partial_fragments: dict[tuple[str, str], tuple[str, ...]] = {}# ``TraversalStats`` for the walk that produced this graph, stashed by# the caller. Carried here rather than widened into the return tuples# of ``build_repo_graph``/``rebuild_graph_and_git`` (ten unpack sitesdiff --git a/packages/core/src/repowise/core/ingestion/resolvers/dotnet/namespace_map.py b/packages/core/src/repowise/core/ingestion/resolvers/dotnet/namespace_map.pyindex c80d61a4f..92d072321 100644--- a/packages/core/src/repowise/core/ingestion/resolvers/dotnet/namespace_map.py+++ b/packages/core/src/repowise/core/ingestion/resolvers/dotnet/namespace_map.py@@ -44,6 +44,10 @@ _TYPE_DECL_RE = re.compile(re.MULTILINE,)+# The type-parameter list right after a declared name: ``<TKey, TValue>``.+# Type parameters are plain identifiers, so the list holds no nested ``<``.+_GENERIC_PARAMS_RE = re.compile(r"\s*<([^<>]*)>")+def declared_namespaces(cs_text: str) -> list[str]:"""Return every namespace declared in *cs_text*, in source order.@@ -55,19 +59,28 @@ def declared_namespaces(cs_text: str) -> list[str]:class TypeDecl:- """One type declaration: bare + one-level-qualified name, partial flag."""+ """One type declaration: bare + one-level-qualified name, partial flag.++ *arity* is the declaration's own generic parameter count. ``Policy`` and+ ``Policy<TResult>`` are two types, so ``fqn`` carries it the way the CLR+ spells it (``Policy`1``) and their partial fragments stay apart.+ """- __slots__ = ("is_partial", "name", "namespace", "qualified")+ __slots__ = ("arity", "is_partial", "name", "namespace", "qualified")- def __init__(self, name: str, qualified: str, namespace: str, is_partial: bool):+ def __init__(+ self, name: str, qualified: str, namespace: str, is_partial: bool, arity: int = 0+ ):self.name = nameself.qualified = qualifiedself.namespace = namespaceself.is_partial = is_partial+ self.arity = arity@propertydef fqn(self) -> str:- return f"{self.namespace}.{self.qualified}" if self.namespace else self.qualified+ name = f"{self.qualified}`{self.arity}" if self.arity else self.qualified+ return f"{self.namespace}.{name}" if self.namespace else namedef scan_type_declarations(cs_text: str) -> list[TypeDecl]:@@ -103,7 +116,9 @@ def scan_type_declarations(cs_text: str) -> list[TypeDecl]:else:breakis_partial = "partial" in (m.group(1) or "").split()- decls.append(TypeDecl(name, qualified, namespace, is_partial))+ generic = _GENERIC_PARAMS_RE.match(cs_text, m.end())+ arity = generic.group(1).count(",") + 1 if generic else 0+ decls.append(TypeDecl(name, qualified, namespace, is_partial, arity))stack.append((depth, name))return decls@@ -193,6 +208,8 @@ _VB_MODIFIERS = (r"Public|Private|Protected|Friend|Partial|MustInherit|NotInheritable|"r"Shadows|Overloads|Default|Shared")+# ``Class Foo(Of TKey, TValue)``: the VB spelling of a type-parameter list.+_VB_GENERIC_PARAMS_RE = re.compile(r"\s*\(\s*Of\s+([^()]*)\)", re.IGNORECASE)_VB_TYPE_DECL_RE = re.compile(rf"^((?:(?:{_VB_MODIFIERS})\s+)*)"rf"(?:Class|Module|Structure|Interface|Enum)\s+({_VB_IDENT})",@@ -230,7 +247,9 @@ def scan_vb_declarations(vb_text: str) -> tuple[list[str], list[TypeDecl]]:if type_match:name = type_match.group(2)is_partial = "partial" in type_match.group(1).lower().split()- decls.append(TypeDecl(name, name, ".".join(stack), is_partial))+ generic = _VB_GENERIC_PARAMS_RE.match(line, type_match.end())+ arity = generic.group(1).count(",") + 1 if generic else 0+ decls.append(TypeDecl(name, name, ".".join(stack), is_partial, arity))return namespaces, decls@@ -286,4 +305,4 @@ def vb_namespace_key(namespace: str, root: str) -> str:def _vb_fqn(decl: TypeDecl, root: str) -> str:"""Fully-qualified name of a VB declaration, under its namespace key."""namespace = vb_namespace_key(decl.namespace, root)- return f"{namespace}.{decl.name}" if namespace else decl.name+ return TypeDecl(decl.name, decl.qualified, namespace, decl.is_partial, decl.arity).fqndiff --git a/tests/unit/dead_code/test_unused_internal.py b/tests/unit/dead_code/test_unused_internal.pyindex bd919a838..0506b3d67 100644--- a/tests/unit/dead_code/test_unused_internal.py+++ b/tests/unit/dead_code/test_unused_internal.py@@ -201,6 +201,52 @@ def test_unused_internal_skipped_when_referenced_as_a_value():assert "_handle" not in names+def _private_nested_classes(edges: list) -> set[str]:+ """Unused-internal names for a C# file holding private nested ``Inner``/``Spare``."""+ g = _build_graph(+ nodes={+ "src/Outer.cs": {+ "language": "csharp",+ "symbols": [+ {+ "name": name,+ "kind": "class",+ "language": "csharp",+ "visibility": "private",+ "decorators": [],+ "start_line": line,+ "end_line": line + 4,+ }+ for name, line in (("Inner", 3), ("Spare", 9))+ ],+ },+ },+ edges=edges,+ )+ report = DeadCodeAnalyzer(g, git_meta_map={}).analyze(+ {+ "detect_unreachable_files": False,+ "detect_unused_exports": False,+ "detect_zombie_packages": False,+ "min_confidence": 0.0,+ }+ )+ return {f.symbol_name for f in report.findings if f.kind == DeadCodeKind.UNUSED_INTERNAL}+++def test_a_class_constructed_through_its_constructor_is_used():+ """``new Inner(..)`` lands on ``Inner``'s constructor, not on the class node."""+ ctor = "src/Outer.cs::Inner::Inner"+ edges = [("src/Main.cs::Main::Run", ctor, {"edge_type": "calls"})]+ assert _private_nested_classes(edges) == {"Spare"}+++def test_a_constructor_with_only_containment_edges_does_not_rescue_its_class():+ ctor = "src/Outer.cs::Inner::Inner"+ edges = [("src/Outer.cs", ctor, {"edge_type": "defines"})]+ assert _private_nested_classes(edges) == {"Inner", "Spare"}++def test_unused_internal_still_flagged_with_only_containment_edges():"""A ``defines`` / ``has_method`` containment edge alone must not count as use."""g = _build_graph(diff --git a/tests/unit/ingestion/test_csharp_partials.py b/tests/unit/ingestion/test_csharp_partials.pyindex b44ff5ed8..0c3af46e9 100644--- a/tests/unit/ingestion/test_csharp_partials.py+++ b/tests/unit/ingestion/test_csharp_partials.py@@ -85,6 +85,25 @@ class TestNamespaceMapNestedKeys:assert len(partials["A.Order"]) == 1assert len(partials["B.Order"]) == 1+ def test_generic_arity_keeps_types_apart(self, tmp_path: Path) -> None:+ # Policy and Policy<TResult> are two types, each split across files.+ files = {+ "p.cs": "namespace A;\npublic partial class Policy {}\n",+ "p2.cs": "namespace A;\npublic partial class Policy {}\n",+ "t.cs": "namespace A;\npublic partial class Policy<TResult> {}\n",+ "t2.cs": "namespace A;\npublic partial class Policy<TResult>\n{\n}\n",+ "kv.cs": "namespace A;\npublic partial class Policy<TKey, TValue> {}\n",+ }+ for name, text in files.items():+ (tmp_path / name).write_text(text)+ _ns, _types, partials = build_namespace_map([tmp_path / n for n in files])+ names = {k: sorted(p.name for p in v) for k, v in partials.items()}+ assert names == {+ "A.Policy": ["p.cs", "p2.cs"],+ "A.Policy`1": ["t.cs", "t2.cs"],+ "A.Policy`2": ["kv.cs"],+ }+class TestPartialClassEdges:def test_partial_fragments_linked_bidirectionally(self, tmp_path: Path) -> None:@@ -111,6 +130,182 @@ class TestPartialClassEdges:assert not graph.has_edge("b.cs", "a.cs")+def _calls(graph, caller: str) -> dict[str, str]:+ """``{callee id: resolution origin}`` for every call edge out of *caller*."""+ return {+ callee: data.get("resolution_origin")+ for _, callee, data in graph.out_edges(caller, data=True)+ if data.get("edge_type") == "calls"+ }+++# Polly's ResiliencePipelineRegistry shape: a private nested type and private+# members declared in one fragment, used only from the other.+_REGISTRY = (+ "namespace Acme;\ninternal sealed partial class Registry\n{\n"+ " private object _generic;\n"+ " public object Get<TResult>()\n {\n"+ " var created = new GenericRegistry<TResult>(this);\n"+ " Helper();\n"+ " this.Other();\n"+ " return (GenericRegistry<TResult>)_generic;\n"+ " }\n}\n"+)+_REGISTRY_TRESULT = (+ "namespace Acme;\ninternal sealed partial class Registry\n{\n"+ " private void Helper() { }\n"+ " private void Other() { }\n"+ " private sealed class Spare { }\n"+ " private sealed class GenericRegistry<TResult>\n {\n"+ " public GenericRegistry(Registry owner) { }\n"+ " }\n}\n"+)+++class TestPartialFragmentScope:+ """Every fragment of a partial type is one class scope for call resolution."""++ def test_members_of_a_sibling_fragment_resolve(self, tmp_path: Path) -> None:+ (tmp_path / "Registry.cs").write_text(_REGISTRY)+ (tmp_path / "Registry.TResult.cs").write_text(_REGISTRY_TRESULT)+ calls = _calls(_build(tmp_path), "Registry.cs::Registry::Get")+ assert calls == {+ # ``new GenericRegistry<TResult>(..)`` reaches the constructor.+ "Registry.TResult.cs::GenericRegistry::GenericRegistry": "enclosing_class",+ "Registry.TResult.cs::Registry::Helper": "enclosing_class",+ "Registry.TResult.cs::Registry::Other": "self_scope",+ }++ def test_same_named_member_of_an_unrelated_class_is_not_linked(+ self, tmp_path: Path+ ) -> None:+ # ``Plain`` shares a file with a Registry fragment but is not part of+ # the partial type, so Registry's private Helper is not in its scope.+ # A second Helper elsewhere keeps the repo-wide unique tier out of it.+ (tmp_path / "Registry.cs").write_text(+ "namespace Acme;\ninternal partial class Registry { }\n"+ "internal class Plain\n{\n public void Run() { Helper(); }\n}\n"+ )+ (tmp_path / "Registry.Helpers.cs").write_text(+ "namespace Acme;\ninternal partial class Registry\n{\n"+ " private void Helper() { }\n}\n"+ )+ (tmp_path / "Other.cs").write_text(+ "namespace Acme;\ninternal class Other\n{\n private void Helper() { }\n}\n"+ )+ graph = _build(tmp_path)+ assert _calls(graph, "Registry.cs::Plain::Run") == {}++ def test_own_overload_is_not_rebound_to_a_sibling_fragment(self, tmp_path: Path) -> None:+ # Polly's Policy.Bulkhead shape: an overload calls its own overload set,+ # and another fragment declares a generic variant of the same name.+ (tmp_path / "Policy.cs").write_text(+ "namespace Acme;\npublic partial class Policy\n{\n"+ " public static object Bulkhead(int n) => Bulkhead(n, 0);\n"+ " public static object Bulkhead(int n, int q) => null;\n}\n"+ )+ (tmp_path / "Policy.TResult.cs").write_text(+ "namespace Acme;\npublic partial class Policy\n{\n"+ " public static object Bulkhead<TResult>(int n) => null;\n}\n"+ )+ graph = _build(tmp_path)+ assert "Policy.TResult.cs::Policy::Bulkhead" not in _calls(+ graph, "Policy.cs::Policy::Bulkhead"+ )++ def test_generic_twin_is_not_a_fragment(self, tmp_path: Path) -> None:+ # Polly's Policy / Policy<TResult>: the non-generic type's call must not+ # land on the generic type's same-named member.+ (tmp_path / "Policy.Execute.cs").write_text(+ "namespace Acme;\npublic abstract partial class Policy\n{\n"+ " public void Execute() { Implementation(); }\n}\n"+ )+ (tmp_path / "Policy.Impl.cs").write_text(+ "namespace Acme;\npublic abstract partial class Policy\n{\n"+ " protected abstract void Implementation();\n}\n"+ )+ (tmp_path / "Policy.TResult.Impl.cs").write_text(+ "namespace Acme;\npublic abstract partial class Policy<TResult>\n{\n"+ " protected abstract TResult Implementation();\n}\n"+ )+ (tmp_path / "Policy.TResult.Execute.cs").write_text(+ "namespace Acme;\npublic abstract partial class Policy<TResult>\n{\n"+ " public TResult Execute() => Implementation();\n}\n"+ )+ graph = _build(tmp_path)+ assert _calls(graph, "Policy.Execute.cs::Policy::Execute") == {+ "Policy.Impl.cs::Policy::Implementation": "enclosing_class"+ }+ assert _calls(graph, "Policy.TResult.Execute.cs::Policy::Execute") == {+ "Policy.TResult.Impl.cs::Policy::Implementation": "enclosing_class"+ }++ def test_construction_of_a_type_is_not_bound_to_a_same_named_method(+ self, tmp_path: Path+ ) -> None:+ # Polly's docs snippets: ``new FaultGenerator()`` builds the library+ # type while a sibling fragment declares a snippet method of that name.+ (tmp_path / "Chaos.Index.cs").write_text(+ "namespace Snippets;\ninternal static partial class Chaos\n{\n"+ " public static void Use() { var g = new FaultGenerator(); }\n}\n"+ )+ (tmp_path / "Chaos.Fault.cs").write_text(+ "namespace Snippets;\ninternal static partial class Chaos\n{\n"+ " public static void FaultGenerator() { }\n}\n"+ )+ (tmp_path / "FaultGenerator.cs").write_text(+ "namespace Lib;\npublic sealed class FaultGenerator { }\n"+ )+ graph = _build(tmp_path)+ assert "Chaos.Fault.cs::Chaos::FaultGenerator" not in _calls(+ graph, "Chaos.Index.cs::Chaos::Use"+ )++ def test_partial_method_call_reaches_a_fragment(self, tmp_path: Path) -> None:+ # A partial method is declared in one fragment and implemented in+ # another; a call from a third lands on one of the two, never elsewhere.+ (tmp_path / "Form.cs").write_text(+ "namespace Acme;\npublic partial class Form\n{\n"+ " public void Load() { OnLoaded(); }\n}\n"+ )+ (tmp_path / "Form.Hooks.cs").write_text(+ "namespace Acme;\npublic partial class Form\n{\n"+ " partial void OnLoaded();\n}\n"+ )+ (tmp_path / "Form.Impl.cs").write_text(+ "namespace Acme;\npublic partial class Form\n{\n"+ " partial void OnLoaded() { }\n}\n"+ )+ (tmp_path / "Other.cs").write_text(+ "namespace Acme;\ninternal class Other\n{\n private void OnLoaded() { }\n}\n"+ )+ calls = _calls(_build(tmp_path), "Form.cs::Form::Load")+ assert len(calls) == 1+ assert set(calls) <= {+ "Form.Hooks.cs::Form::OnLoaded",+ "Form.Impl.cs::Form::OnLoaded",+ }++ def test_sibling_fragment_use_is_not_unused_internal(self, tmp_path: Path) -> None:+ from repowise.core.analysis.dead_code import DeadCodeAnalyzer, DeadCodeKind++ (tmp_path / "Registry.cs").write_text(_REGISTRY)+ (tmp_path / "Registry.TResult.cs").write_text(_REGISTRY_TRESULT)+ report = DeadCodeAnalyzer(_build(tmp_path), git_meta_map={}).analyze(+ {+ "detect_unreachable_files": False,+ "detect_unused_exports": False,+ "detect_zombie_packages": False,+ "min_confidence": 0.0,+ }+ )+ flagged = {+ f.symbol_name for f in report.findings if f.kind == DeadCodeKind.UNUSED_INTERNAL+ }+ # C# methods are not judged by this pass; nested types are.+ assert flagged == {"Spare"}++class TestNestedTypeResolution:def test_outer_inner_type_ref_resolves(self, tmp_path: Path) -> None:# using A.Models; ... Outer.Inner x; — the qualified reference mustdiff --git a/tests/unit/ingestion/test_vbnet_same_namespace.py b/tests/unit/ingestion/test_vbnet_same_namespace.pyindex 42b1ae779..842d27b7e 100644--- a/tests/unit/ingestion/test_vbnet_same_namespace.py+++ b/tests/unit/ingestion/test_vbnet_same_namespace.py@@ -16,6 +16,10 @@ from repowise.core.ingestion import ASTParser, FileTraverser, GraphBuilderfrom repowise.core.ingestion.languages.vbnet_same_namespace import (resolve_vbnet_same_namespace_refs,)+from repowise.core.ingestion.resolvers.dotnet.namespace_map import (+ build_vb_namespace_map,+ scan_vb_declarations,+)def _graph_for(texts: dict[str, str]) -> nx.DiGraph:@@ -221,6 +225,90 @@ class TestPartialClasses:assert forward is not None and forward.get("hint_source") == "partial_class"assert back is not None and back.get("hint_source") == "partial_class"+ def test_designer_member_called_from_the_form_resolves(self, tmp_path: Path) -> None:+ # The designer fragment's private members are in the form's scope. A+ # second InitializeComponent keeps the repo-wide unique tier out of it.+ repo = _write(+ tmp_path,+ {+ "App/App.vbproj": (+ '<Project Sdk="Microsoft.NET.Sdk">\n <PropertyGroup>\n'+ " <RootNamespace>Acme</RootNamespace>\n"+ " </PropertyGroup>\n</Project>\n"+ ),+ "App/MainForm.vb": (+ "Partial Public Class MainForm\n"+ " Public Sub Load()\n InitializeComponent()\n End Sub\n"+ "End Class\n"+ ),+ "App/MainForm.Designer.vb": (+ "Partial Class MainForm\n"+ " Private Sub InitializeComponent()\n End Sub\n"+ "End Class\n"+ ),+ "App/Other.vb": (+ "Public Class Other\n"+ " Private Sub InitializeComponent()\n End Sub\n"+ "End Class\n"+ ),+ },+ )+ edge = _build(repo).get_edge_data(+ "App/MainForm.vb::MainForm::Load",+ "App/MainForm.Designer.vb::MainForm::InitializeComponent",+ )+ assert edge is not None and edge["edge_type"] == "calls"+ assert edge["resolution_origin"] == "enclosing_class"++ def test_generic_arity_is_part_of_the_partial_key(self) -> None:+ _ns, decls = scan_vb_declarations(+ "Partial Class Cache\nEnd Class\n"+ "Partial Class Cache(Of TKey, TValue)\nEnd Class\n"+ )+ assert [d.fqn for d in decls] == ["Cache", "Cache`2"]++ def test_generic_twin_is_not_a_fragment(self, tmp_path: Path) -> None:+ # Cache and Cache(Of TKey, TValue) are two types: neither the partial+ # map nor call resolution may merge their fragments.+ files = {+ "App/App.vbproj": (+ '<Project Sdk="Microsoft.NET.Sdk">\n <PropertyGroup>\n'+ " <RootNamespace>Acme</RootNamespace>\n"+ " </PropertyGroup>\n</Project>\n"+ ),+ "App/Cache.vb": (+ "Partial Class Cache\n"+ " Public Sub Run()\n Evict()\n End Sub\n"+ "End Class\n"+ ),+ "App/Cache.Evict.vb": (+ "Partial Class Cache\n"+ " Private Sub Evict()\n End Sub\n"+ "End Class\n"+ ),+ "App/CacheT.vb": (+ "Partial Class Cache(Of TKey, TValue)\n"+ " Private Sub Evict()\n End Sub\n"+ "End Class\n"+ ),+ }+ repo = _write(tmp_path, files)+ vb = [repo / p for p in files if p.endswith(".vb")]+ texts = {p: p.read_text() for p in vb}+ _ns, _types, partials = build_vb_namespace_map(+ vb, texts=texts, root_namespaces=dict.fromkeys(vb, "Acme")+ )+ assert {k: sorted(p.name for p in v) for k, v in partials.items()} == {+ "Acme.Cache": ["Cache.Evict.vb", "Cache.vb"],+ "Acme.Cache`2": ["CacheT.vb"],+ }+ calls = {+ callee+ for _, callee, data in _build(repo).out_edges("App/Cache.vb::Cache::Run", data=True)+ if data.get("edge_type") == "calls"+ }+ assert calls == {"App/Cache.Evict.vb::Cache::Evict"}+def test_non_partial_same_name_types_are_not_linked(self, tmp_path: Path) -> None:repo = _write(tmp_path,