Build a GraphTraverser over a fixed node/edge set, honoring the `kinds` filter.
(nodes: Node[], edges: Edge[])
| 548 | |
| 549 | /** Build a GraphTraverser over a fixed node/edge set, honoring the `kinds` filter. */ |
| 550 | function tGraph(nodes: Node[], edges: Edge[]): GraphTraverser { |
| 551 | const byId = new Map(nodes.map((n) => [n.id, n])); |
| 552 | const q = { |
| 553 | getNodeById: (id: string) => byId.get(id) ?? null, |
| 554 | getNodesByIds: (ids: readonly string[]) => { |
| 555 | const m = new Map<string, Node>(); |
| 556 | for (const id of ids) { |
| 557 | const n = byId.get(id); |
| 558 | if (n) m.set(id, n); |
| 559 | } |
| 560 | return m; |
| 561 | }, |
| 562 | getOutgoingEdges: (source: string, kinds?: string[]) => |
| 563 | edges.filter((e) => e.source === source && (!kinds || kinds.includes(e.kind))), |
| 564 | getIncomingEdges: (target: string, kinds?: string[]) => |
| 565 | edges.filter((e) => e.target === target && (!kinds || kinds.includes(e.kind))), |
| 566 | getIncomingEdgesExceptContains: (target: string) => |
| 567 | edges.filter((e) => e.target === target && e.kind !== 'contains'), |
| 568 | }; |
| 569 | return new GraphTraverser(q as never); |
| 570 | } |
| 571 | |
| 572 | describe('Traversal edge-completeness & limits (#1086–#1090)', () => { |
| 573 | it('findPath keeps shortest-path order without duplicate frontier entries', () => { |
no test coverage detected