Skip to content

fix: scope title:/type: extraction to the frontmatter block, not the whole file#577

Merged
nashsu merged 1 commit into
nashsu:mainfrom
chuenchen309:fix/wiki-graph-frontmatter-scope
Jul 15, 2026
Merged

fix: scope title:/type: extraction to the frontmatter block, not the whole file#577
nashsu merged 1 commit into
nashsu:mainfrom
chuenchen309:fix/wiki-graph-frontmatter-scope

Conversation

@chuenchen309

Copy link
Copy Markdown
Contributor

Problem

extractTitle()/extractType() in src/lib/wiki-graph.ts match title:/type: with:

content.match(/^---\n[\s\S]*?^title:\s*["']?(.+?)["']?\s*$/m)

This is anchored at the opening ---, but the lazy [\s\S]*? is never required to stop at the closing ---. A page whose frontmatter has no title/type — but whose body happens to contain a later line starting with title: or type: (plain prose, not YAML) — gets that body line misread as the frontmatter value.

The more severe case: a misread type of "query" matches HIDDEN_TYPES, silently dropping the entire page from the wiki graph.

graph-relevance.ts's extractFrontmatter() already handles this correctly — it isolates the ---...--- block first (/^---\n([\s\S]*?)\n---/) before searching it for title:/type:.

Fix

Extract the same isolated frontmatter block via a small shared helper, and search only within it for both functions.

Testing

Added src/lib/__tests__/wiki-graph.test.ts with two regression tests (mocking @/commands/fs):

  • A page with type: entity frontmatter (no title) and a body line title: not-frontmatter-at-all — confirms the label still falls back to the # Real Heading, not the body line.
  • A page with title: Real Page frontmatter (no type) and a body line type: query — confirms the page isn't misclassified and dropped from the graph.

Both fail against the pre-fix code and pass after. Ran the full npm run test:mocks suite (1640 passed across 114 files — no regressions) and npm run typecheck (clean).

Disclosure: I used an AI coding assistant (Claude) to help identify this bug and draft the fix. I independently traced the misread-and-drop mechanism through HIDDEN_TYPES, wrote/verified the regression tests in both red and green states, and ran the full local test suite before opening this PR.

…whole file

extractTitle()/extractType() matched title:/type: with a regex anchored
only at the opening `---`, and the lazy [\s\S]*? in between was never
required to stop at the closing `---`. A page whose frontmatter has no
title/type -- but whose body happens to contain a later line starting
with "title:" or "type:" (plain prose, not YAML) -- gets that body line
misread as the frontmatter value.

The more severe case: a misread type of "query" matches HIDDEN_TYPES,
silently dropping the entire page from the wiki graph.

graph-relevance.ts's extractFrontmatter() already isolates the
`---...---` block first before searching it for title:/type:. Extract
the same isolated block and search only within it, fixing both
functions with one shared helper.

Added two regression tests via a mocked buildWikiGraph(): one confirms
a body line starting with "title:" doesn't override the correct
heading-derived label, the other confirms a body line starting with
"type:" doesn't cause the page to be misclassified and dropped.
Confirmed both fail against the pre-fix code and pass after. Ran the
full test:mocks suite (1640 passed across 114 files -- no regressions)
and typecheck (clean).

Disclosure: I used an AI coding assistant (Claude) to help identify
this bug and draft the fix. I independently verified the exact
misread-and-drop mechanism by tracing HIDDEN_TYPES, wrote/verified the
regression tests in both red and green states, and ran the full local
test suite plus typecheck before opening this PR.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@chuenchen309

Copy link
Copy Markdown
Contributor Author

Thanks for merging this. I've really enjoyed digging into the frontmatter / wiki-cleanup part of the codebase — I also left reviews on a couple of the open frontmatter PRs (#517 and #561) in case they're useful. You've got a big incoming-PR and issue queue at the moment; if an extra set of hands on reviewing PRs or triaging issues in those areas would help, I'd be glad to pitch in. Entirely your call.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants