fix(agents): count all Markdown line endings in budgets

This commit is contained in:
4gray committed 2026-09-21 00:10:57 +02:00
1 parent b863d8e4d4
commit bbbaebce83
3 files changed
+32 -1

No files matched your search

+1
View File
@@ -29,6 +29,7 @@ Later normal edits maintain the canonical docs, not duplicate historical prose.
Run `pnpm run agents:validate` after guidance changes. It checks line/byte budgets,
root imports and local navigation links/anchors, including migration destinations.
Line budgets count LF, CRLF and standalone CR endings consistently.
Markdown navigation is parsed with the already-declared `marked` dependency;
undefined explicit references (including shortcut images) are errors, and code examples are excluded.
Backticked concrete paths in root guidance and the context map are checked from
+3 -1
View File
@@ -157,7 +157,9 @@ export async function validateAgentGuidance({ rootDir }) {
const lines =
markdown === ''
? 0
: markdown.replace(/\r?\n$/u, '').split(/\r?\n/u).length;
: markdown
.replace(/(?:\r\n|[\r\n])$/u, '')
.split(/\r\n|[\r\n]/u).length;
const bytes = Buffer.byteLength(markdown, 'utf8');
if (lines > maxLines)
diagnostics.push(
@@ -1081,3 +1081,31 @@ test('valid image-map navigation and inert areas pass', async (t) => {
[]
);
});
for (const ending of ['\n', '\r\n', '\r']) {
for (const [source, limit] of [
['AGENTS.md', 200],
['CLAUDE.md', 30],
]) {
test(`line budget handles ${JSON.stringify(ending)} in ${source}`, async (t) => {
const lines = [
source === 'CLAUDE.md' ? '@AGENTS.md' : '# Guidance',
...Array(limit - 1).fill('# Section'),
];
assert.deepEqual(
await diagnostics(t, { [source]: lines.join(ending) + ending }),
[]
);
const result = await diagnostics(t, {
[source]: [...lines, '# Extra'].join(ending) + ending,
});
assert.ok(
result.some((message) =>
message.includes(
`at most ${limit} lines allowed (received ${limit + 1})`
)
)
);
});
}
}