MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / tGraph

Function tGraph

__tests__/graph.test.ts:550–570  ·  view source on GitHub ↗

Build a GraphTraverser over a fixed node/edge set, honoring the `kinds` filter.

(nodes: Node[], edges: Edge[])

Source from the content-addressed store, hash-verified

548
549/** Build a GraphTraverser over a fixed node/edge set, honoring the `kinds` filter. */
550function 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
572describe('Traversal edge-completeness & limits (#1086–#1090)', () => {
573 it('findPath keeps shortest-path order without duplicate frontier entries', () => {

Callers 1

graph.test.tsFile · 0.85

Calls 3

mapMethod · 0.80
getMethod · 0.65
setMethod · 0.45

Tested by

no test coverage detected