check-blog-targeted-copy.mjs 2.1 KB

1234567891011121314151617181920212223242526272829303132
  1. import assert from 'node:assert/strict';
  2. import fs from 'node:fs';
  3. import { execFileSync } from 'node:child_process';
  4. const baseline = 'e84a62e17e2f4cbd985968d716361e3bbd6d0f87';
  5. const before = JSON.parse(execFileSync('git', ['show', `${baseline}:src/content/blog/articles.json`], { encoding: 'utf8' }));
  6. const after = JSON.parse(fs.readFileSync('src/content/blog/articles.json', 'utf8'));
  7. const key = a => `${a.locale}/${a.id}`;
  8. const links = body => [...body.matchAll(/\]\(([^)\s]+)\)/g)].map(m => m[1]).sort();
  9. const newDenmarkSource = 'https://visa.vfsglobal.com/one-pager/denmark/Ireland/english/';
  10. assert.equal(after.length, 21);
  11. assert.deepEqual(after.map(key).sort(), before.map(key).sort());
  12. for (const article of after) {
  13. const original = before.find(a => key(a) === key(article));
  14. const { body: oldBody, sources: oldSources, ...oldFields } = original;
  15. const { body, sources, ...fields } = article;
  16. assert.deepEqual(fields, oldFields, `${key(article)} changed protected metadata`);
  17. assert.equal((body.match(/^## /gm) || []).length, 7, 'Retain seven main sections');
  18. const denmark = article.id === 'denmark-appointment-booking';
  19. assert.deepEqual(links(body), [...links(oldBody), ...(denmark ? [newDenmarkSource] : [])].sort(), `${key(article)} changed unapproved links`);
  20. if (denmark) {
  21. assert.deepEqual(sources.slice(0, oldSources.length), oldSources);
  22. assert.equal(sources.length, oldSources.length + 1);
  23. assert.equal(sources.at(-1).url, newDenmarkSource);
  24. assert(sources.at(-1).title.trim());
  25. } else assert.deepEqual(sources, oldSources);
  26. const visibleText = body.replace(/\]\([^)]+\)/g, ']');
  27. assert(!/text\.skin/i.test(visibleText), 'Brand copy must use Strata; URL destinations remain unchanged');
  28. assert(/\[Strata\b|\bStrata\b/.test(visibleText), 'Missing Strata service invitation');
  29. assert(!/<\/?(?:script|iframe|html|body)\b/i.test(body), 'Unsafe HTML');
  30. }
  31. console.log('PASS: 21 records; exact titles/metadata; seven H2s; existing URLs/sources preserved except the approved added Denmark source; Strata brand copy. Refund meaning, removed recommendations and Denmark sequencing require independent editorial review.');