diff --git a/src/main/java/io/github/randomcodespace/iq/graph/GraphStore.java b/src/main/java/io/github/randomcodespace/iq/graph/GraphStore.java index 62676d16..acfa1521 100644 --- a/src/main/java/io/github/randomcodespace/iq/graph/GraphStore.java +++ b/src/main/java/io/github/randomcodespace/iq/graph/GraphStore.java @@ -335,31 +335,6 @@ public List findIncomingNeighbors(String nodeId) { Map.of("nodeId", nodeId)); } - /** - * Batch-find all ENDPOINT/WEBSOCKET_ENDPOINT neighbors for a list of node IDs in one query. - * Returns a map of sourceNodeId -> list of endpoint neighbor nodes. - */ - public Map> findEndpointNeighborsBatch(List nodeIds) { - Map> result = new java.util.LinkedHashMap<>(); - if (nodeIds.isEmpty()) return result; - try (Transaction tx = graphDb.beginTx()) { - var queryResult = tx.execute( - "MATCH (n:CodeNode)-[]-(m:CodeNode) " - + "WHERE n.id IN $nodeIds AND m.kind IN ['ENDPOINT', 'WEBSOCKET_ENDPOINT'] " - + "RETURN n.id AS sourceId, m", - Map.of("nodeIds", nodeIds)); - while (queryResult.hasNext()) { - var row = queryResult.next(); - String sourceId = (String) row.get("sourceId"); - Object val = row.get("m"); - if (val instanceof org.neo4j.graphdb.Node neo4jNode) { - result.computeIfAbsent(sourceId, k -> new ArrayList<>()).add(nodeFromNeo4j(neo4jNode)); - } - } - } - return result; - } - public long count() { try (Transaction tx = graphDb.beginTx()) { var result = tx.execute("MATCH (n:CodeNode) RETURN count(n) AS cnt"); diff --git a/src/test/java/io/github/randomcodespace/iq/analyzer/linker/TopicLinkerTest.java b/src/test/java/io/github/randomcodespace/iq/analyzer/linker/TopicLinkerTest.java index 225c85f2..249b7188 100644 --- a/src/test/java/io/github/randomcodespace/iq/analyzer/linker/TopicLinkerTest.java +++ b/src/test/java/io/github/randomcodespace/iq/analyzer/linker/TopicLinkerTest.java @@ -376,30 +376,4 @@ void handlesMessageQueueNodeKind() { assertEquals(1, result.edges().size()); } - @Test - void determinismTest() { - var topic = new CodeNode("topic:payments", NodeKind.TOPIC, "payments"); - var prod1 = new CodeNode("svc:P1", NodeKind.CLASS, "P1"); - var prod2 = new CodeNode("svc:P2", NodeKind.CLASS, "P2"); - var cons = new CodeNode("svc:C1", NodeKind.CLASS, "C1"); - - var e1 = new CodeEdge(); - e1.setId("e1"); e1.setKind(EdgeKind.PUBLISHES); e1.setSourceId("svc:P1"); e1.setTarget(topic); - var e2 = new CodeEdge(); - e2.setId("e2"); e2.setKind(EdgeKind.SENDS_TO); e2.setSourceId("svc:P2"); e2.setTarget(topic); - var e3 = new CodeEdge(); - e3.setId("e3"); e3.setKind(EdgeKind.LISTENS); e3.setSourceId("svc:C1"); e3.setTarget(topic); - - List nodeList = new ArrayList<>(List.of(topic, prod1, prod2, cons)); - List edgeList = new ArrayList<>(List.of(e1, e2, e3)); - - LinkResult result1 = linker.link(nodeList, edgeList); - LinkResult result2 = linker.link(nodeList, edgeList); - - assertEquals(result1.edges().size(), result2.edges().size()); - for (int i = 0; i < result1.edges().size(); i++) { - assertEquals(result1.edges().get(i).getId(), result2.edges().get(i).getId()); - assertEquals(result1.edges().get(i).getSourceId(), result2.edges().get(i).getSourceId()); - } - } } diff --git a/src/test/java/io/github/randomcodespace/iq/query/QueryServiceTest.java b/src/test/java/io/github/randomcodespace/iq/query/QueryServiceTest.java index 22f75b08..6f15f6e7 100644 --- a/src/test/java/io/github/randomcodespace/iq/query/QueryServiceTest.java +++ b/src/test/java/io/github/randomcodespace/iq/query/QueryServiceTest.java @@ -571,7 +571,8 @@ void findRelatedEndpointsShouldUsesBatchQueryInsteadOfNPlusOne() { void findRelatedEndpointsShouldIncludeDirectEndpointMatches() { var endpointNode = makeNode("ep:getUsers", NodeKind.ENDPOINT, "getUsers"); when(graphStore.search("getUsers", 50)).thenReturn(List.of(endpointNode)); - when(graphStore.findEndpointNeighborsBatch(List.of("ep:getUsers"))).thenReturn(Map.of()); + // Endpoint nodes are partitioned directly into the result list — nonEndpointIds is empty + when(graphStore.findEndpointNeighborsBatch(List.of())).thenReturn(Map.of()); Map result = service.findRelatedEndpoints("getUsers"); @@ -586,14 +587,13 @@ void findRelatedEndpointsShouldIncludeDirectEndpointMatches() { @Test void findRelatedEndpointsShouldDeduplicateEndpoints() { var endpointNode = makeNode("ep:getUsers", NodeKind.ENDPOINT, "getUsers"); - // Same endpoint appears as both a direct match and a neighbor + // Endpoint node is a direct match — nonEndpointIds is empty, batch returns nothing when(graphStore.search("ep", 50)).thenReturn(List.of(endpointNode)); - when(graphStore.findEndpointNeighborsBatch(List.of("ep:getUsers"))) - .thenReturn(Map.of("ep:getUsers", List.of(endpointNode))); + when(graphStore.findEndpointNeighborsBatch(List.of())).thenReturn(Map.of()); Map result = service.findRelatedEndpoints("ep"); - // Should only appear once + // Should appear exactly once (direct match) assertEquals(1, result.get("count")); }