| 12345678910111213141516171819202122232425262728293031323334 |
- import assert from 'node:assert/strict';
- import { execFileSync } from 'node:child_process';
- // The user's verified handoff is the preservation baseline for this body-only edit.
- const baseline = '9cae31f7ac0c1ef41790436e0454757d79b7783d';
- const before = JSON.parse(execFileSync('git', ['show', `${baseline}:src/content/blog/articles.json`], { encoding: 'utf8' }));
- // Preserve the accepted readability milestone; subsequent targeted source additions
- // are checked separately by check-blog-targeted-copy.mjs.
- const acceptedReadability = 'e84a62e17e2f4cbd985968d716361e3bbd6d0f87';
- const after = JSON.parse(execFileSync('git', ['show', `${acceptedReadability}:src/content/blog/articles.json`], { encoding: 'utf8' }));
- const key = a => `${a.locale}/${a.id}`;
- const links = body => [...body.matchAll(/\]\(([^)\s]+)\)/g)].map(m => m[1]).sort();
- const headings = body => (body.match(/^## /gm) || []).length;
- const stats = body => {
- const paragraphs = body.split(/\n\s*\n/).filter(p => p.trim() && !/^(?:#|\||[-*] |\d+\. )/.test(p));
- const visible = paragraphs.map(p => p.replace(/\[([^\]]+)\]\([^)]+\)/g, '$1').replace(/[*_`]/g, ''));
- return { proseBlocks: paragraphs.length, longestVisibleProseBlock: Math.max(0, ...visible.map(p => p.length)), listItems: (body.match(/^(?:[-*]|\d+\.) /gm) || []).length };
- };
- assert.equal(before.length, 21);
- assert.equal(after.length, 21);
- assert.deepEqual(after.map(key).sort(), before.map(key).sort());
- const report = [];
- for (const article of after) {
- const original = before.find(a => key(a) === key(article));
- const { body: oldBody, ...oldFields } = original;
- const { body, ...fields } = article;
- assert.deepEqual(fields, oldFields, `${key(article)} changed fields outside body`);
- assert.deepEqual(links(body), links(oldBody), `${key(article)} changed link occurrences`);
- assert.equal(headings(body), headings(oldBody), `${key(article)} changed H2 section count`);
- assert(!/<\/?(?:script|iframe|html|body)\b/i.test(body), 'Unsafe HTML');
- report.push({ article: key(article), changed: body !== oldBody, before: stats(oldBody), after: stats(body) });
- }
- console.log(JSON.stringify({ baseline, acceptedReadability, changedBodies: report.filter(a => a.changed).length, articles: report }, null, 2));
- console.log('PASS: 21-article inventory, body-only scope, exact link occurrences and H2 boundaries. Readability statistics are descriptive; factual qualifiers require editorial review.');
|