fix(#4678): resolve :LINE citations against their underlying files (#4719)

* fix(#4678): check :LINE citations instead of dropping or misreporting them

cmdVerifyReferences had two opposite failures on citations carrying a
trailing line suffix. The backtick extractor anchored the closing
backtick right after the extension, so `src/foo.ts:42` matched neither
regex and was silently dropped -- an all-line-numbered document
reported {valid:true, found:0, missing:[], total:0}, indistinguishable
from one with no citations. The @-extractor treated ':' as a legal path
character, so @src/foo.ts:42 was probed with the suffix glued on and a
resolvable file was reported missing.

Strip the :N / :N-M suffix (stripLineSuffix) before existsSync in both
loops -- for filesystem resolution only; found/missing keep reporting
the original citation text -- and let the backtick regex accept the
optional suffix so those citations are counted at all. URL skip,
template-placeholder skip, dedup, ~/ expansion and the output contract
are unchanged. Whether a line number past EOF counts as missing is an
open design question and stays out of scope.

* chore(#4678): backfill changeset pr field with PR number

The fragment shipped as the documented pr: 0 placeholder; the merge
gate requires pr > 0 before a fragment can land, so backfill 4719 now
that the PR number exists.

---------

Co-authored-by: TwistedRiCen <16397953+TwistedRiCen@users.noreply.github.com>
Co-authored-by: Tom Boucher <trekkie@nomorestars.com>
This commit is contained in:
Twisted Fate
2026-09-15 08:40:46 +08:00
committed by GitHub
parent 77ff068cc3
commit 39db16a653
3 changed files with 69 additions and 5 deletions

View File

@@ -1312,6 +1312,12 @@ function cmdVerifyPhaseCompleteness(cwd: string, phase: string, raw: boolean): v
);
}
// #4678: citations may carry a trailing line suffix (":42", ":1-20") that
// describes a location inside the file, not part of the path itself.
function stripLineSuffix(ref: string): string {
return ref.replace(/:\d+(?:-\d+)?$/, '');
}
function cmdVerifyReferences(cwd: string, filePath: string, raw: boolean): void {
if (!filePath) {
error('file path required');
@@ -1329,9 +1335,10 @@ function cmdVerifyReferences(cwd: string, filePath: string, raw: boolean): void
const atRefs = content.match(/@([^\s\n,)]+\/[^\s\n,)]+)/g) || [];
for (const ref of atRefs) {
const cleanRef = ref.slice(1);
const resolved = cleanRef.startsWith('~/')
? path.join(process.env['HOME'] || '', cleanRef.slice(2))
: path.join(cwd, cleanRef);
const fsRef = stripLineSuffix(cleanRef);
const resolved = fsRef.startsWith('~/')
? path.join(process.env['HOME'] || '', fsRef.slice(2))
: path.join(cwd, fsRef);
if (fs.existsSync(resolved)) {
found.push(cleanRef);
} else {
@@ -1339,12 +1346,12 @@ function cmdVerifyReferences(cwd: string, filePath: string, raw: boolean): void
}
}
const backtickRefs = content.match(/`([^`]+\/[^`]+\.[a-zA-Z]{1,10})`/g) || [];
const backtickRefs = content.match(/`([^`]+\/[^`]+\.[a-zA-Z]{1,10}(?::\d+(?:-\d+)?)?)`/g) || [];
for (const ref of backtickRefs) {
const cleanRef = ref.slice(1, -1);
if (cleanRef.startsWith('http') || cleanRef.includes('${') || cleanRef.includes('{{')) continue;
if (found.includes(cleanRef) || missing.includes(cleanRef)) continue;
const resolved = path.join(cwd, cleanRef);
const resolved = path.join(cwd, stripLineSuffix(cleanRef));
if (fs.existsSync(resolved)) {
found.push(cleanRef);
} else {