77
88from .launch_parser import RemapEntry # noqa: F401 — used by callers via star-import
99from .namespace_tree import NamespaceNode
10+ from .port_utils import shorten_port_names
1011
1112# Topics that carry no domain-level information
1213_INFRA_EXACT = {
@@ -103,6 +104,25 @@ def resolve_connections(top_nodes: list[NamespaceNode]) -> list[TopicConnection]
103104 ref = PortRef (component = ns_node .name , port = canonical , node_path = node .full_path )
104105 subscribers [topic ].append (ref )
105106
107+ # Build per-component shortening maps from cross-component ports only.
108+ # Internal-only ports are excluded so they can't cause false collisions.
109+ comp_pub_raw : dict [str , set [str ]] = defaultdict (set )
110+ comp_sub_raw : dict [str , set [str ]] = defaultdict (set )
111+ for topic , pubs in publishers .items ():
112+ subs_for_topic = subscribers .get (topic , [])
113+ for pub in pubs :
114+ for sub in subs_for_topic :
115+ if pub .component != sub .component :
116+ comp_pub_raw [pub .component ].add (pub .port )
117+ comp_sub_raw [sub .component ].add (sub .port )
118+
119+ comp_pub_short : dict [str , dict [str , str ]] = {
120+ c : shorten_port_names (list (ports )) for c , ports in comp_pub_raw .items ()
121+ }
122+ comp_sub_short : dict [str , dict [str , str ]] = {
123+ c : shorten_port_names (list (ports )) for c , ports in comp_sub_raw .items ()
124+ }
125+
106126 connections : list [TopicConnection ] = []
107127 seen : set [tuple ] = set ()
108128
@@ -112,11 +132,19 @@ def resolve_connections(top_nodes: list[NamespaceNode]) -> list[TopicConnection]
112132 for sub in subs :
113133 if pub .component == sub .component :
114134 continue # internal – handled in module.yaml
115- key = (pub .component , pub .port , sub .component , sub .port )
135+ pub_port = comp_pub_short .get (pub .component , {}).get (pub .port , pub .port )
136+ sub_port = comp_sub_short .get (sub .component , {}).get (sub .port , sub .port )
137+ key = (pub .component , pub_port , sub .component , sub_port )
116138 if key in seen :
117139 continue
118140 seen .add (key )
119- connections .append (TopicConnection (publisher = pub , subscriber = sub , topic = topic ))
141+ connections .append (
142+ TopicConnection (
143+ publisher = PortRef (pub .component , pub_port , pub .node_path ),
144+ subscriber = PortRef (sub .component , sub_port , sub .node_path ),
145+ topic = topic ,
146+ )
147+ )
120148
121149 return connections
122150
0 commit comments