fix(links): a directory link is not a missing file, so a tracked dir now resolves

`checkInternalLinks` compared a link's resolved target only against `present`
(tracked files), so `[x](dir/)` was always LINK-INTERNAL-MISSING even when
every file under it was tracked. Reported by portfolio-optimiser-claude with a
minimal repro; the same defect inflated ERROR counts in voyage, linkedin-studio
and portfolio-optimiser — 12 of the org's 71 measured ERRORs were this one
check, not twelve repo problems.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Uwwfdmrfnp7FuGQ4z25RKH
This commit is contained in:
Kjell Tore Guttormsen 2026-08-03 21:57:53 +02:00
commit 3c2a535297
7 changed files with 50 additions and 5 deletions

View file

@ -578,6 +578,14 @@ function linkLevelFor(path) {
// deliberately out — a check that is sometimes wrong teaches people to ignore it.
export function checkInternalLinks({ files, present }) {
const have = new Set(present ?? []);
// `present` holds tracked FILES only, so a link to a directory — `[x](dir/)`
// — never has a member to match even when every file under it is tracked.
// Derive the directories a tracked file actually lives in from the same set.
const haveDirs = new Set();
for (const p of have) {
const parts = String(p).split('/');
for (let i = 1; i < parts.length; i++) haveDirs.add(parts.slice(0, i).join('/'));
}
const findings = [];
for (const [path, text] of Object.entries(files ?? {})) {
stripCode(text).split('\n').forEach((line, i) => {
@ -600,7 +608,7 @@ export function checkInternalLinks({ files, present }) {
});
continue;
}
if (!have.has(resolved)) {
if (!have.has(resolved) && !haveDirs.has(resolved)) {
findings.push({
level: linkLevelFor(path),
code: 'LINK-INTERNAL-MISSING',