fix: scope title:/type: extraction to the frontmatter block, not the whole file#577
Merged
nashsu merged 1 commit intoJul 15, 2026
Merged
Conversation
…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>
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
extractTitle()/extractType()insrc/lib/wiki-graph.tsmatchtitle:/type:with:This is anchored at the opening
---, but the lazy[\s\S]*?is never required to stop at the closing---. A page whose frontmatter has notitle/type— but whose body happens to contain a later line starting withtitle:ortype:(plain prose, not YAML) — gets that body line misread as the frontmatter value.The more severe case: a misread
typeof"query"matchesHIDDEN_TYPES, silently dropping the entire page from the wiki graph.graph-relevance.ts'sextractFrontmatter()already handles this correctly — it isolates the---...---block first (/^---\n([\s\S]*?)\n---/) before searching it fortitle:/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.tswith two regression tests (mocking@/commands/fs):type: entityfrontmatter (notitle) and a body linetitle: not-frontmatter-at-all— confirms the label still falls back to the# Real Heading, not the body line.title: Real Pagefrontmatter (notype) and a body linetype: 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:mockssuite (1640 passed across 114 files — no regressions) andnpm 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.