test(fleet): stabilize documentation surface scan
All checks were successful
ci/woodpecker/pr/ci Pipeline was successful
All checks were successful
ci/woodpecker/pr/ci Pipeline was successful
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -483,15 +483,11 @@ function codeSurfaceDiagnostics(path: string, source: string): SurfaceDiagnostic
|
||||
diagnostics.push({ path, line: lineNumber, code: 'indented-code' });
|
||||
continue;
|
||||
}
|
||||
if (/`{2,}/.test(line) && !/^```[a-z-]+$/.test(line)) {
|
||||
diagnostics.push({ path, line: lineNumber, code: 'inline-delimiter' });
|
||||
continue;
|
||||
}
|
||||
const marker = line.match(/^(`{3,}|~{3,})(.*)$/);
|
||||
if (marker !== null) {
|
||||
block += 1;
|
||||
const info = marker[2] ?? '';
|
||||
if (marker[1] !== '```') {
|
||||
if (marker[1] !== '```' || /[`~]/.test(info)) {
|
||||
diagnostics.push({ path, line: lineNumber, block, code: 'fence-marker' });
|
||||
continue;
|
||||
}
|
||||
@@ -507,6 +503,15 @@ function codeSurfaceDiagnostics(path: string, source: string): SurfaceDiagnostic
|
||||
inFence = true;
|
||||
continue;
|
||||
}
|
||||
if (/`{2,}/.test(line)) {
|
||||
diagnostics.push({ path, line: lineNumber, code: 'inline-delimiter' });
|
||||
continue;
|
||||
}
|
||||
const withoutClosedInlineSpans = line.replace(/`[^`\n]+`/g, '');
|
||||
if (withoutClosedInlineSpans.includes('`')) {
|
||||
diagnostics.push({ path, line: lineNumber, code: 'inline-delimiter' });
|
||||
continue;
|
||||
}
|
||||
if (/<\/?(?:pre|code|script|style|xmp|listing)(?=$|\s|[>/])/i.test(line)) {
|
||||
diagnostics.push({ path, line: lineNumber, code: 'raw-code-container' });
|
||||
}
|
||||
@@ -702,8 +707,38 @@ describe('closed documentation publication grammar', (): void => {
|
||||
}
|
||||
});
|
||||
|
||||
it('rejects unmatched single-backtick delimiters on either side', (): void => {
|
||||
for (const source of ['`literal', 'literal`', 'text `literal', 'literal` text']) {
|
||||
expect(codeSurfaceDiagnostics('fixture.md', source)).toContainEqual({
|
||||
path: 'fixture.md',
|
||||
line: 1,
|
||||
code: 'inline-delimiter',
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
it('counts every invalid column-one fence candidate before later profile selection', (): void => {
|
||||
for (const firstCandidate of [
|
||||
'````fleet-synopsis',
|
||||
'```fleet-synopsis```',
|
||||
'~~~fleet-synopsis~~~',
|
||||
]) {
|
||||
expect(
|
||||
codeSurfaceDiagnostics(
|
||||
'reference/cli.md',
|
||||
`${firstCandidate}\n\`\`\`unknown\n\`\`\`fleet-synopsis\nmosaic fleet verify\n\`\`\``,
|
||||
),
|
||||
).toEqual([
|
||||
{ path: 'reference/cli.md', line: 1, block: 1, code: 'fence-marker' },
|
||||
{ path: 'reference/cli.md', line: 2, block: 2, code: 'fence-info' },
|
||||
{ path: 'reference/cli.md', line: 3, block: 3, code: 'profile-unknown' },
|
||||
{ path: 'reference/cli.md', line: 5, block: 4, code: 'fence-info' },
|
||||
]);
|
||||
}
|
||||
});
|
||||
|
||||
it('rejects inline delimiter runs instead of silently omitting them', (): void => {
|
||||
for (const source of ['``literal``', '```literal```', 'text ``literal`` text']) {
|
||||
for (const source of ['``literal``', 'text ```literal```', 'text ``literal`` text']) {
|
||||
expect(codeSurfaceDiagnostics('fixture.md', source)).toContainEqual({
|
||||
path: 'fixture.md',
|
||||
line: 1,
|
||||
|
||||
Reference in New Issue
Block a user