fix(sync): normalize section separators in regenerate()
A previous run could merge the '---' separator with the next section
header (---## ✅ Befejezett), breaking section detection. Prefix/suffix
are now trimmed and rejoined with fixed separators. Regression test
added; also create Plane issues for local-only completed work
(MITHOME-28 Custom CMS, MITHOME-29 Webmail) to avoid ID collisions.
This commit is contained in:
@@ -162,3 +162,25 @@ test('buildTable sorts rows by sequence number', () => {
|
||||
assert.equal(lines[2], '| MITHOME-1 | A | ✅ |');
|
||||
assert.equal(lines[3], '| MITHOME-15 | B | ✅ |');
|
||||
});
|
||||
|
||||
// Regression: a previous run dropping the blank line after `---` must not merge
|
||||
// the separator with the section header (`---## ✅ Befejezett`).
|
||||
test('regenerate always separates `---` from section headers', () => {
|
||||
const planeIssues = [
|
||||
{ sequence_id: 1, name: 'Kezdőlap', state: { group: 'completed' } },
|
||||
{ sequence_id: 13, name: 'CI pipeline', state: { group: 'unstarted' } },
|
||||
{ sequence_id: 17, name: 'Winston logger + Loki integráció', state: { group: 'started' } },
|
||||
{ sequence_id: 19, name: 'Accessibility', state: { group: 'backlog' } }
|
||||
];
|
||||
const { rows } = parseTodoFile(SAMPLE_TODO);
|
||||
const buildData = buildDiscrepancies(planeIssues, rows, 'MITHOME');
|
||||
const decisions = { moveToPlane: new Set(), keepOrphan: new Set(), addNew: new Set() };
|
||||
const final = buildFinalSections(buildData, decisions);
|
||||
|
||||
const corrupted = SAMPLE_TODO.replace('---\n\n## ✅ Befejezett', '---## ✅ Befejezett');
|
||||
const output = regenerate(corrupted, final);
|
||||
|
||||
assert.ok(output.includes('---\n\n## ✅ Befejezett'), 'header must be separated from ---');
|
||||
assert.ok(!output.includes('---##'), 'no merged separator+header');
|
||||
assert.ok(output.includes('## ✅ Befejezett'));
|
||||
});
|
||||
|
||||
@@ -64,7 +64,9 @@ function buildTable(sec, rows) {
|
||||
return [header, separator, ...body].join('\n');
|
||||
}
|
||||
|
||||
// WHY: only the section region is regenerated, prefix/suffix (overview, commands) are preserved
|
||||
// WHY: only the section region is regenerated, prefix/suffix (overview, commands) are preserved.
|
||||
// Prefix/suffix are trimmed and rejoined with normalized separators so that a previous run
|
||||
// that dropped the blank line after `---` cannot corrupt the section headers (`---## ✅`).
|
||||
function regenerate(content, finalSections) {
|
||||
const lines = content.split('\n');
|
||||
const firstIdx = lines.findIndex(l => SECTIONS[0].header.test(l));
|
||||
@@ -79,8 +81,8 @@ function regenerate(content, finalSections) {
|
||||
}
|
||||
}
|
||||
|
||||
const prefix = lines.slice(0, firstIdx).join('\n');
|
||||
const suffix = lines.slice(endIdx + 1).join('\n');
|
||||
const prefix = lines.slice(0, firstIdx).join('\n').trimEnd();
|
||||
const suffix = lines.slice(endIdx + 1).join('\n').trimStart();
|
||||
|
||||
const headerOf = key => {
|
||||
const sec = SECTIONS.find(s => s.key === key);
|
||||
@@ -92,9 +94,8 @@ function regenerate(content, finalSections) {
|
||||
const rows = finalSections[sec.key] || [];
|
||||
return `## ${headerOf(sec.key)}\n\n${buildTable(sec, rows)}`;
|
||||
});
|
||||
const middle = blocks.join('\n\n---\n\n') + '\n\n---\n';
|
||||
|
||||
const result = `${prefix}${middle}${suffix}`;
|
||||
const middle = blocks.join('\n\n---\n\n');
|
||||
const result = `${prefix}\n\n${middle}\n\n---\n\n${suffix}`;
|
||||
return result.endsWith('\n') ? result : `${result}\n`;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user