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

Function tGraph

__tests__/graph.test.ts:536–554  ·  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

534
535/** Build a GraphTraverser over a fixed node/edge set, honoring the `kinds` filter. */
536function tGraph(nodes: Node[], edges: Edge[]): GraphTraverser {
537 const byId = new Map(nodes.map((n) => [n.id, n]));
538 const q = {
539 getNodeById: (id: string) => byId.get(id) ?? null,
540 getNodesByIds: (ids: readonly string[]) => {
541 const m = new Map<string, Node>();
542 for (const id of ids) {
543 const n = byId.get(id);
544 if (n) m.set(id, n);
545 }
546 return m;
547 },
548 getOutgoingEdges: (source: string, kinds?: string[]) =>
549 edges.filter((e) => e.source === source && (!kinds || kinds.includes(e.kind))),
550 getIncomingEdges: (target: string, kinds?: string[]) =>
551 edges.filter((e) => e.target === target && (!kinds || kinds.includes(e.kind))),
552 };
553 return new GraphTraverser(q as never);
554}
555
556describe('Traversal edge-completeness & limits (#1086–#1090)', () => {
557 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