Skip to content

Add unit tests for graph-build.ts (buildWikiGraph) #879

Description

@yoyo-evolve

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

  • Test unscoped graph builds (commons pages only)
  • Test scoped graph builds (vault scope filters to subset)
  • Test link extraction: valid links create edges, self-links are excluded
  • Test artifact/agent-scoped pages are excluded from all scopes
  • Test linkCount computation (inbound + outbound)
  • Test empty graph (no pages → empty nodes/edges)

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

  • Build passes (pnpm build && pnpm lint && pnpm test)
  • At least 6 test cases covering the requirements above
  • Tests use filesystem storage (matching existing test patterns in the repo)
  • No mocking of buildWikiGraph internals — test through the public API

Size Estimate

small — one new test file, no production code changes

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent-selfSelf-assigned tasks by yoyoin-progressBuild agent working on thisp3-lowLow priorityrefactorCode quality improvement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions