Files
Eva SarafianouandCursor 356bdc7d9b docs: scope AI documentation drafts to the merged change (#39211)
* docs: scope AI documentation drafts to the merged change

Draft PRs were titled by number, filled with the review loop, and restyling whole pages because pre-open review treated every line as new.

Co-authored-by: Cursor <cursoragent@cursor.com>

* docs: strip HTML comment delimiters from AI draft summaries

An unmatched comment opener in the model summary is an HTML block through the end of the pull request body, which hides the editorial-review notice.

Co-authored-by: Cursor <cursoragent@cursor.com>

* docs: drop a draft summary that does not match the accepted revision

An accepted revision with no summary fence was keeping the previous pass's summary, so the draft pull request could describe files that had already been replaced.

Co-authored-by: Cursor <cursoragent@cursor.com>

* docs: match sibling spacing when a draft adds a section

The command reference puts each label on the line above its fence. Drafts were inserting a blank line there, which made a new command harder to scan than the rest of the page.

Co-authored-by: Cursor <cursoragent@cursor.com>

* docs: let related brief actions share a section

Forcing a heading per gap-brief action split behaviours that belong together on the page.

Co-authored-by: Cursor <cursoragent@cursor.com>

* docs: keep the writer trail and the full action list

The pre-open trail disappeared with the runner, and a maxed gap brief could drop the last action before review.

Co-authored-by: Cursor <cursoragent@cursor.com>

* docs-ai: use git diff --no-index for pre-open review diffs

Co-authored-by: Cursor <cursoragent@cursor.com>

* docs-ai: keep prior draft when a revision reverts the page; fold draftTitle into author-loop

Co-authored-by: Cursor <cursoragent@cursor.com>

* docs-ai: never draft changelogs, upgrade notes, or the version archive

Co-authored-by: Cursor <cursoragent@cursor.com>

* docs-ai: keep gap analysis recommendations unchanged

Co-authored-by: Cursor <cursoragent@cursor.com>

---------

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-16 17:31:25 +00:00

136 lines
5.2 KiB
JavaScript

import {test} from 'node:test';
import assert from 'node:assert/strict';
import {additionsDiff, unifiedDiff} from './diff.mjs';
function hunkHeader(diff) {
const m = diff.match(/@@ -0,0 \+(\d+)(?:,(\d+))? @@/);
if (!m) return null;
// +0,0 → count 0; +1,N → count N; +N alone is not used here.
if (m[2] !== undefined) return Number(m[2]);
return Number(m[1]);
}
test('additionsDiff normalises a file with no trailing newline', () => {
const diff = additionsDiff([{path: 'docs/main/a.mdx', content: 'line1\nline2'}]);
assert.ok(diff.endsWith('\n'));
assert.equal(hunkHeader(diff), 2);
assert.match(diff, /\+line1\n\+line2\n/);
assert.doesNotMatch(diff, /\+line2\n\+\n/);
});
test('additionsDiff drops the phantom empty line after a trailing newline', () => {
const diff = additionsDiff([{path: 'docs/main/a.mdx', content: 'line1\nline2\n'}]);
assert.equal(hunkHeader(diff), 2);
assert.match(diff, /\+line1\n\+line2\n$/);
});
test('additionsDiff handles empty content without crashing', () => {
const diff = additionsDiff([{path: 'docs/main/empty.mdx', content: ''}]);
assert.match(diff, /diff --git a\/docs\/main\/empty\.mdx/);
assert.match(diff, /new file mode 100644/);
assert.match(diff, /@@ -0,0 \+0,0 @@/);
assert.equal(hunkHeader(diff), 0);
// No content lines after the hunk header (+++ file header still uses +).
assert.equal((diff.split(/@@[^\n]*\n/)[1] ?? '').trim(), '');
assert.ok(diff.endsWith('\n'));
});
test('additionsDiff joins multiple files as separate chunks', () => {
const diff = additionsDiff([
{path: 'docs/main/a.mdx', content: 'A\n'},
{path: 'docs/main/b.mdx', content: 'B\n'},
]);
const a = diff.indexOf('+++ b/docs/main/a.mdx');
const b = diff.indexOf('+++ b/docs/main/b.mdx');
assert.ok(a !== -1 && b !== -1 && a < b);
assert.match(diff, /\+A\n/);
assert.match(diff, /\+B\n/);
});
test('additionsDiff returns empty string for no files', () => {
assert.equal(additionsDiff([]), '');
});
test('unifiedDiff shows an insertion and leaves distant lines out of the hunk', () => {
const path = 'docs/main/administration-guide/manage/command-line-tools.mdx';
const before = ['## Compliance export', '', 'Existing export text.', '', '## Server operations', ''].join('\n');
const after = [
'## Compliance export',
'',
'Existing export text.',
'',
'## Read the bundled documentation',
'',
'Open /_documentation/ on a running server.',
'',
'## Server operations',
'',
].join('\n');
const diff = unifiedDiff([{path, content: after}], [{path, content: before}]);
assert.match(diff, /^\+\+\+ b\/docs\/main/m);
assert.doesNotMatch(diff, /\/dev\/null/);
assert.match(diff, /\+## Read the bundled documentation/);
assert.match(diff, /\+Open \/_documentation\/ on a running server\./);
assert.doesNotMatch(diff, /\+## Compliance export/);
assert.doesNotMatch(diff, /-## Compliance export/);
});
test('unifiedDiff still reports a real edit away from the insertion', () => {
const path = 'docs/main/a.mdx';
const before = ['## Compliance Export', '', 'Body.', '', '## Tail', ''].join('\n');
const after = ['## Compliance export', '', 'Body.', '', '## Tail', '', 'Added.', ''].join('\n');
const diff = unifiedDiff([{path, content: after}], [{path, content: before}]);
assert.match(diff, /-## Compliance Export/);
assert.match(diff, /\+## Compliance export/);
assert.match(diff, /\+Added\./);
});
test('unifiedDiff treats a missing original as a new file', () => {
const file = {path: 'docs/main/new.mdx', content: 'Hello\n'};
const diff = unifiedDiff([file], []);
assert.equal(diff, additionsDiff([file]));
});
test('unifiedDiff omits a file that did not change', () => {
const path = 'docs/main/a.mdx';
const content = 'Same\n';
assert.equal(unifiedDiff([{path, content}], [{path, content}]), '');
});
test('unifiedDiff on a long page reports the insertion and not the unchanged head', () => {
const path = 'docs/main/a.mdx';
const head = Array.from({length: 5000}, (_, i) => `line ${i}`);
const before = [...head, 'tail'].join('\n');
const after = [...head.slice(0, 2500), '## New', ...head.slice(2500), 'tail'].join('\n');
const diff = unifiedDiff([{path, content: `${after}\n`}], [{path, content: before}]);
assert.match(diff, /\+## New/);
assert.doesNotMatch(diff, /\+line 0\b/);
assert.doesNotMatch(diff, /\+line 4999\b/);
assert.doesNotMatch(diff, /-line 0\b/);
});
test('unifiedDiff treats an empty original as an existing file', () => {
const path = 'docs/main/a.mdx';
const diff = unifiedDiff([{path, content: 'Hello\n'}], [{path, content: ''}]);
assert.match(diff, /^--- a\/docs\/main\/a\.mdx$/m);
assert.match(diff, /^\+Hello$/m);
});
test('unifiedDiff reports a change to the trailing newline only', () => {
const path = 'docs/main/a.mdx';
const diff = unifiedDiff([{path, content: 'Body\n'}], [{path, content: 'Body'}]);
assert.match(diff, /No newline at end of file/);
});
test('unifiedDiff joins new and edited files', () => {
const diff = unifiedDiff(
[
{path: 'docs/main/new.mdx', content: 'New\n'},
{path: 'docs/main/a.mdx', content: 'One\nTwo\n'},
],
[{path: 'docs/main/a.mdx', content: 'One\n'}],
);
assert.match(diff, /^\+New\n(?=diff --git a\/docs\/main\/a\.mdx)/m);
assert.match(diff, /^\+Two$/m);
});