Context
src/lib/graph-build.ts (116 lines) contains buildWikiGraph, the function that transforms wiki pages into the knowledge graph (nodes + edges). It's called by both the REST endpoint (/api/wiki/graph) and the MCP tool (wiki_graph). The adjacent modules are well-tested: graph.test.ts covers community detection and graph-render.test.ts covers canvas rendering — but the middle layer that builds the data has zero tests.
The function has non-trivial logic worth verifying:
- Scope filtering — unscoped queries use
listCommonsPages, scoped queries filter by resolved scope slugs
- Link extraction — a regex (
/\[([^\]]*)\]\(([^)]+)\.md\)/g) parses markdown links
- Self-link exclusion — edges from a page to itself are filtered
- Artifact/agent-scoped type exclusion — these page types are stripped even within a vault scope
- Link count computation — each node gets inbound + outbound edge count
If the link regex or scope filtering breaks, the graph silently shows wrong data (no crash, no error — a silent correctness bug).
Requirements
Files Involved
src/lib/__tests__/graph-build.test.ts — new test file
src/lib/graph-build.ts — the module under test (read-only reference)
Acceptance Criteria
Size Estimate
small — one new test file, no production code changes
Context
src/lib/graph-build.ts(116 lines) containsbuildWikiGraph, the function that transforms wiki pages into the knowledge graph (nodes+edges). It's called by both the REST endpoint (/api/wiki/graph) and the MCP tool (wiki_graph). The adjacent modules are well-tested:graph.test.tscovers community detection andgraph-render.test.tscovers canvas rendering — but the middle layer that builds the data has zero tests.The function has non-trivial logic worth verifying:
listCommonsPages, scoped queries filter by resolved scope slugs/\[([^\]]*)\]\(([^)]+)\.md\)/g) parses markdown linksIf the link regex or scope filtering breaks, the graph silently shows wrong data (no crash, no error — a silent correctness bug).
Requirements
Files Involved
src/lib/__tests__/graph-build.test.ts— new test filesrc/lib/graph-build.ts— the module under test (read-only reference)Acceptance Criteria
pnpm build && pnpm lint && pnpm test)buildWikiGraphinternals — test through the public APISize Estimate
small — one new test file, no production code changes