Local code intelligence for developers and AI agents. Connect code, docs and infrastructure in a persistent graph, with CBM Lens, MCP tools, agent integrations and change-aware test selection.
C aiderastclaude-codecode-analysiscode-intelligencecodexcursorcypherdeveloper-toolsgemini-cligraph-visualizationkilocodeknowledge-graphmcpmcp-servermodel-context-protocolopencodesqlitetree-sitterwindsurf
fix(ui): show exactly a route group's routes when it is opened
Bernhard Jackiewicz3ae2aa4941ec
diff --git a/graph-ui/src/architecture/SpatialArchitecture.test.tsx b/graph-ui/src/architecture/SpatialArchitecture.test.tsxindex cca3662f2..73e758271 100644--- a/graph-ui/src/architecture/SpatialArchitecture.test.tsx+++ b/graph-ui/src/architecture/SpatialArchitecture.test.tsx@@ -95,17 +95,23 @@ it('cancels a route request on generation change and ignores its late result', a});it('groups endpoints, hides test routes by default and narrows a group through the filter', async () => {const route = (id: number, name: string, file_path: string): GraphNode => ({ id, label: 'Route', name, qualified_name: `sample.route.${id}`, file_path, x: 0, y: 0, z: 0, size: 1, color: '' });- const input: GraphData = { nodes: [node, route(2, '/accounts/login/', 'app/urls.py'), route(3, '/accounts/logout/', 'app/urls.py'), route(4, '/fixture/', 'tests/urls.py')], edges: [], total_nodes: 4 };+ const input: GraphData = { nodes: [node, route(2, '/accounts/login/', 'app/urls.py'), route(3, '/accounts/logout/', 'app/urls.py'), route(4, '/fixture/', 'tests/urls.py'),+ route(5, '/accounts_old/', 'accounts/urls.py')], edges: [], total_nodes: 5 };const onFilter = vi.fn();- await act(async () => root.render(<SpatialArchitecture project="sample" graph={input} overview={overview} view="routes" filter="" active onNavigate={vi.fn()} onView={vi.fn()} onFilter={onFilter} />));+ const render = (filter: string) => act(async () => root.render(<SpatialArchitecture project="sample" graph={input} overview={overview} view="routes" filter={filter} active onNavigate={vi.fn()} onView={vi.fn()} onFilter={onFilter} />));+ await render('');const scene = () => [...host.querySelectorAll('[data-testid="scene"] [data-node]')].map(item => item.textContent);- expect(scene()).toEqual(['/accounts · 2']);+ expect(scene()).toEqual(['/accounts · 2', '/accounts_old/']);const toggle = [...host.querySelectorAll('label')].find(label => label.textContent?.startsWith('Include test routes'))!;expect(toggle.textContent).toBe('Include test routes (1 hidden)');await click('/accounts · 2'); await click('Show these 2 routes →');expect(onFilter).toHaveBeenCalledExactlyOnceWith('/accounts');+ // The filter the group hands over shows its two routes, not every route whose text contains it.+ await render('/accounts');+ expect(scene()).toEqual(['/accounts/login/', '/accounts/logout/']);+ await render('');await act(async () => toggle.querySelector('input')!.click());- expect(scene()).toEqual(['/accounts · 2', '/fixture/']);+ expect(scene()).toEqual(['/accounts · 2', '/fixture/', '/accounts_old/']);expect(toggle.textContent).toBe('Include test routes');});it('does not load route evidence while the workspace is hidden', async () => {diff --git a/graph-ui/src/architecture/semantic-graph.test.ts b/graph-ui/src/architecture/semantic-graph.test.tsindex e0b998749..08077f38f 100644--- a/graph-ui/src/architecture/semantic-graph.test.ts+++ b/graph-ui/src/architecture/semantic-graph.test.ts@@ -332,6 +332,38 @@ describe('route identities and service evidence', () => {const filtered = buildSemanticGraph(graph, { view: 'routes', groupRoutes: true, filter: '/accounts', routeSnapshot });expect(filtered.nodes.filter(item => item.kind === 'route').map(item => item.label)).toEqual(['/accounts/login/', '/accounts/logout/']);});+ it('selects exactly the routes of a group when the filter names its prefix', () => {+ const at = (id: number, name: string, file_path: string): GraphNode => ({ ...route, id, name, qualified_name: `fixture.route.${id}`, file_path });+ const routes = [at(400, '/', 'app/urls.py'), at(401, '/', 'shop/urls.py'), at(402, '/', 'blog/urls.py'),+ at(403, '/admin/', 'django/contrib/admin/sites.py'), at(404, '/admin/y/', 'django/contrib/admin/sites.py'),+ at(405, '/admin_views/x/', 'tests/urls.py'), at(406, '/login/', 'django/contrib/admin/sites.py'),+ at(407, '/accounts/login/', 'app/urls.py'), at(408, 'accounts/profile/', 'app/urls.py'), at(409, 'GET /accounts/logout/', 'app/urls.py')];+ const handler = node(1, 'django/contrib/admin/sites.py', 'login');+ const graph: GraphData = { nodes: [handler, ...routes], edges: [], total_nodes: 11 };+ const routeSnapshot = { truncated: false, warnings: [], relationships: [routes[3], routes[4], routes[6]].map(source => ({ source, target: handler, type: 'HANDLES' as const })) };+ const options = { view: 'routes' as const, groupRoutes: true, routeSnapshot };+ const grouped = buildSemanticGraph(graph, options);+ // The root path names no shared segment: its routes stay single instead of becoming a group the filter cannot select.+ expect(grouped.nodes.filter(item => item.kind === 'route').map(item => item.label).sort())+ .toEqual(['/', '/', '/', '/accounts · 3', '/admin · 2', '/admin_views/x/', '/login/']);+ const routesFor = (prefix: string) => {+ const model = buildSemanticGraph(graph, { ...options, filter: prefix });+ return model.nodes.filter(item => item.kind === 'route').map(item => item.label).sort();+ };+ for (const group of grouped.nodes.filter(item => item.routePrefix)) {+ expect(routesFor(group.routePrefix!)).toEqual(group.members.map(member => member.name).sort());+ expect(routesFor(group.routePrefix!)).toHaveLength(group.count);+ }+ // Neither '/admin_views' nor a route registered under django/contrib/admin joins the '/admin' group, though its handler area stays as context.+ const admin = buildSemanticGraph(graph, { ...options, filter: '/admin' });+ expect(admin.nodes.map(item => item.label).sort()).toEqual(['/admin/', '/admin/y/', 'django']);+ expect(admin.edges.map(edge => [edge.source, edge.target])).toEqual([['route:Route:fixture.route.403@django/contrib/admin/sites.py', 'handler-area:django'],+ ['route:Route:fixture.route.404@django/contrib/admin/sites.py', 'handler-area:django']]);+ // Text that names no group prefix is still a search over labels, paths and details.+ expect(routesFor('admin')).toEqual(['/admin/', '/admin/y/', '/admin_views/x/', '/login/']);+ expect(routesFor('/')).toHaveLength(10);+ expect(buildSemanticGraph(graph, { view: 'routes', filter: '/admin', routeSnapshot }).nodes.some(item => item.label === '/admin_views/x/')).toBe(true);+ });it('keeps routes of a product test package and hides those of test roots', () => {const at = (id: number, name: string, file_path: string): GraphNode => ({ ...route, id, name, qualified_name: `fixture.route.${id}`, file_path });const graph: GraphData = { nodes: [at(500, '/client/', 'django/test/client.py'), at(501, '/fixture/', 'tests/urls.py'),diff --git a/graph-ui/src/architecture/semantic-graph.ts b/graph-ui/src/architecture/semantic-graph.tsindex fe399a817..c5f09d322 100644--- a/graph-ui/src/architecture/semantic-graph.ts+++ b/graph-ui/src/architecture/semantic-graph.ts@@ -105,6 +105,8 @@ const symbolId = (node: GraphNode) => `symbol:${identity(node)}`;* file. A nested test/ package such as django/test/ is product code.*/const TEST_SOURCE = /(^|\/)(tests|__tests__|specs?)\/|^(src\/)?test\/|(^|\/)(test_[^/]*|tests?\.[^/.]+|[^/]+[._-](test|spec)\.[^/.]+)$/i;+/** The first path segment of a route label, without its method: '/accounts' for 'GET /accounts/login/'. */+const routePrefixOf = (label: string) => `/${label.replace(/^[A-Z]+\s+/, '').split('/').filter(Boolean)[0] ?? ''}`;const sourceNode = (node: GraphNode) => Boolean(node.file_path && node.file_path !== '{}'&& !['Project', 'Folder', 'Package', 'Branch', 'Route'].includes(node.label));const symbolNode = (node: GraphNode): SemanticNode => ({ id: symbolId(node),@@ -405,15 +407,16 @@ export function buildSemanticGraph(graph: GraphData, options: SemanticGraphOptio}hiddenRoutes = hidden.size;// Without a filter, routes sharing a first path segment become one counted- // group; a filter lists the matching routes one by one again.+ // group; a filter lists the matching routes one by one again. The root+ // path '/' shares no segment, so its routes stay single.const grouped = new Map<string, string>();if (options.groupRoutes && !options.filter?.trim()) {const prefixes = new Map<string, SemanticNode[]>();for (const node of routeNodes.values()) if (node.kind === 'route') {- const prefix = `/${node.label.replace(/^[A-Z]+\s+/, '').split('/').filter(Boolean)[0] ?? ''}`;+ const prefix = routePrefixOf(node.label);prefixes.set(prefix, [...prefixes.get(prefix) ?? [], node]);}- for (const [prefix, routes] of prefixes) if (routes.length > 1) {+ for (const [prefix, routes] of prefixes) if (routes.length > 1 && prefix !== '/') {const id = `route-group:${prefix}`;routeNodes.set(id, { id, kind: 'route', kindLabel: 'Route group', routePrefix: prefix, label: `${prefix} · ${routes.length}`,detail: `${routes.length} routes whose path starts with ${prefix}`, position: [0, 0, 0], count: routes.length,@@ -539,12 +542,19 @@ export function buildSemanticGraph(graph: GraphData, options: SemanticGraphOptio};const unfiltered = capped(nodes, edges);if (filter) {+ // A filter that names a route group's prefix selects exactly that group's+ // routes, by the rule that built the group; any other text is a search.+ const prefixed = (node: SemanticNode) => node.kind === 'route' && routePrefixOf(node.label).toLowerCase() === filter;+ const routeGroup = options.view === 'routes' && options.groupRoutes && /^\/[^/\s]+$/.test(filter) && nodes.some(prefixed);for (const node of nodes) {- if (`${node.label} ${node.filePath ?? node.areaPath ?? ''} ${node.detail} ${node.members.map(member => member.name).join(' ')}`.toLowerCase().includes(filter)) matching.add(node.id);+ if (routeGroup ? prefixed(node)+ : `${node.label} ${node.filePath ?? node.areaPath ?? ''} ${node.detail} ${node.members.map(member => member.name).join(' ')}`.toLowerCase().includes(filter)) matching.add(node.id);}+ // Neighbours add relationship context; for a route group they never add routes.+ const routeIds = new Set(routeGroup ? nodes.filter(node => node.kind === 'route').map(node => node.id) : []);const context = new Set(matching);for (const edge of edges) {- if (matching.has(edge.source) || matching.has(edge.target)) { context.add(edge.source); context.add(edge.target); }+ if (matching.has(edge.source) || matching.has(edge.target)) for (const id of [edge.source, edge.target]) if (!routeIds.has(id)) context.add(id);}nodes = nodes.filter(node => context.has(node.id));edges = edges.filter(edge => context.has(edge.source) && context.has(edge.target));