Skip to content

fix(lint): give broken-link stubs the type of the folder they land in (#733) - #746

Open
dajiaohuang wants to merge 1 commit into
nashsu:mainfrom
dajiaohuang:fix/lint-stub-frontmatter-type
Open

fix(lint): give broken-link stubs the type of the folder they land in (#733)#746
dajiaohuang wants to merge 1 commit into
nashsu:mainfrom
dajiaohuang:fix/lint-stub-frontmatter-type

Conversation

@dajiaohuang

Copy link
Copy Markdown

Refs #733 — addresses the first half of the report (the type: query stubs).

Wiki Lint's "Fix broken link" keeps the directory of the link it replaces but
hard-coded type: query on the stub. Only wiki/queries/ made that true.
Everywhere else it did two kinds of damage at once:

  • src/lib/wiki-graph.ts:242 drops every node whose type is query
    (HIDDEN_TYPES), so the new page and every link pointing at it vanished
    from the graph. That is also what drove the inflated isolated-page count in
    Insights.
  • The project's own schema routing rejected the file on the next ingest — a page
    under wiki/concepts/ must carry type: concept. The app was refusing
    content it had written itself.

inferStubType() now derives the type from the stub's destination directory.

The project's schema.md is consulted first, and that ordering is the part
worth reviewing. The report suggested inferWikiTypeFromPath, but that map is
built-in only: for the custom folders in the report's own measurements
(playbooks/, standards/) it returns the plural directory name, which would
still fail validateWikiPageRouting's exact match and leave the page dropped
on the next ingest. The schema table is what routing actually validates
against, so it wins. With no schema to consult, inferWikiTypeFromPath
(previously used only for UI labels) supplies the type; query stays the last
resort.

The schema is read after the exists-check, so the common "stub already there"
path does no extra I/O.

Not addressed

The second half of the report: makeQueryFileName always appending
-YYYY-MM-DD-HHMMSS, so a page created from a review suggestion is never
recognised by sweepResolvedReviews's exact-name match and the suggestion
returns on the next sweep. Fixing it changes the filename policy for every
"Save to Wiki" write, well beyond this stub path. I left it out deliberately
rather than smuggling a broad filename change into a lint fix — happy to do it
as a separate PR, or to fold it in here if you would rather review them
together.

Verification

10 new tests in src/lib/lint-fixes.test.ts (8 of the 18 fail against the
unfixed source
), including one that feeds the generated frontmatter through
validateWikiPageRouting and asserts it is accepted — the exact check that
used to reject it.

  • npx vitest run src/lib/lint-fixes.test.ts → 18 passed
  • npm run test:mocks → 133 files / 1909 tests passed (no regressions)
  • npx tsc --build → clean
  • npx vite build → succeeds

Stubs are identified downstream by tags: [stub, lint], not by their type, and
ensureBrokenLinkStub has only one production caller (lint-view.tsx), so
nothing keys off the old query value. I have not run this against a real
2,900-file wiki; the report's reproduction is the basis for the test fixtures.

🤖 Generated with Claude Code

Wiki Lint's "Fix broken link" keeps the directory of the link it
replaces but hard-coded `type: query` on the stub. Only `wiki/queries/`
made that true. Everywhere else it did two kinds of damage at once:

- `wiki-graph.ts` drops every node whose type is `query`, so the new
  page and all links pointing at it disappeared from the graph — which
  is also what made the Insights panel report the pages as isolated.
- The project's own schema routing rejected the file on the next
  ingest, since a page under `wiki/concepts/` must carry
  `type: concept`. The app was refusing content it had written itself.

`inferStubType()` now derives the type from the stub's destination
directory. The project's `schema.md` is consulted first, because that
table is exactly what `validateWikiPageRouting` validates against — and
because the built-in directory map does not know custom folders, so it
would answer `playbooks` where the schema declares `playbook` and the
plural would still fail routing's exact match. With no schema to
consult, `inferWikiTypeFromPath` (previously used only for UI labels)
supplies the type; `query` stays the last resort.

The schema is read after the exists-check, so the common "stub already
there" path does no extra I/O.

Not addressed: the second half of the report — `makeQueryFileName`
always appending a `-YYYY-MM-DD-HHMMSS` suffix, so pages created from a
review suggestion are never recognised by `sweepResolvedReviews`'s
exact-name match and the suggestion returns on the next sweep. That
changes the filename policy for every "Save to Wiki" write, well beyond
this stub path, and belongs in its own change.

Verified by 18 tests in `src/lib/lint-fixes.test.ts` (10 new), 8 of
which fail against the unfixed source, including one asserting the
generated frontmatter passes `validateWikiPageRouting`. Full mock suite
(1909 tests) and `tsc --build` pass.

Refs nashsu#733
@dajiaohuang
dajiaohuang force-pushed the fix/lint-stub-frontmatter-type branch from 1faa0cc to bd328cd Compare September 11, 2026 10:53
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.

1 participant