From 4407344a61c6f52da0e14733853b1baee4ea4a77 Mon Sep 17 00:00:00 2001 From: patrickryan01 Date: Fri, 4 Dec 2026 10:51:18 -0500 Subject: [PATCH] fix(releases): i let an english release note I rewrote skip the translation shape checks, so a sales rewrite can land without touching the other thirteen languages --- package.json | 2 +- scripts/i18n-check.mjs | 17 +++++++----- scripts/i18n-check.test.mjs | 52 +++++++++++++++++++++++++++++++++++++ src/content.config.ts | 3 +++ 4 files changed, 67 insertions(+), 7 deletions(-) create mode 100644 scripts/i18n-check.test.mjs diff --git a/package.json b/package.json index 64307e6b..fe6585c8 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "scripts": { "dev": "astro dev", "og": "node scripts/og.mjs", - "build": "node scripts/i18n-check.mjs && node scripts/og.mjs && astro build && node scripts/sitemap-lastmod.mjs dist && node scripts/seo-audit.mjs dist && node scripts/sales-lens-check.mjs dist && node scripts/card-words.mjs dist && node scripts/voice-gate.mjs dist", + "build": "node scripts/i18n-check.test.mjs && node scripts/i18n-check.mjs && node scripts/og.mjs && astro build && node scripts/sitemap-lastmod.mjs dist && node scripts/seo-audit.mjs dist && node scripts/sales-lens-check.mjs dist && node scripts/card-words.mjs dist && node scripts/voice-gate.mjs dist", "preview": "astro preview", "audit": "node scripts/seo-audit.mjs dist && node scripts/sales-lens-check.mjs dist && node scripts/card-words.mjs dist && node scripts/voice-gate.mjs dist" }, diff --git a/scripts/i18n-check.mjs b/scripts/i18n-check.mjs index 182cb5ae..248aaaf1 100644 --- a/scripts/i18n-check.mjs +++ b/scripts/i18n-check.mjs @@ -12,7 +12,7 @@ import { existsSync, readFileSync, readdirSync } from 'node:fs'; import { fileURLToPath } from 'node:url'; import { dirname, join } from 'node:path'; -const root = join(dirname(fileURLToPath(import.meta.url)), '..'); +const root = process.env.I18N_CHECK_ROOT || join(dirname(fileURLToPath(import.meta.url)), '..'); const dir = join(root, 'src', 'i18n'); const load = (c) => JSON.parse(readFileSync(join(dir, `${c}.json`), 'utf8')); @@ -203,11 +203,16 @@ for (const { code } of codes) { const x = parse(readFileSync(join(here, `${e.id}.md`), 'utf8'), `${path}/${e.id}.md`); if (!x) continue; if (x.fm.lang !== path || `${x.fm.product}/${x.fm.version}` !== e.id) err(code, label, 'front matter lang, product or version does not match its path'); - if (shape(e) !== shape(x)) err(code, label, `structure differs (highlights/breaking/headings/list items/table rows/code blocks): ${shape(e)} vs ${shape(x)}`); - if (fences(e.body).join('\n') !== fences(x.body).join('\n')) err(code, label, 'a code block differs from the English'); - if (spans(e) !== spans(x)) err(code, label, 'its `code` spans differ from the English'); - if (urls(e) !== urls(x)) err(code, label, 'a link or URL differs from the English'); - if (versions(e) !== versions(x)) err(code, label, 'a version number differs from the English'); + // An English entry rewritten after its translations were made carries `english_rewrite: true` in its front matter. + // Its structure, code spans, links and version numbers are free to differ from the translations; every other check below + // still runs, and an entry without the flag is held to all of them. + if (e.fm.english_rewrite !== 'true') { + if (shape(e) !== shape(x)) err(code, label, `structure differs (highlights/breaking/headings/list items/table rows/code blocks): ${shape(e)} vs ${shape(x)}`); + if (fences(e.body).join('\n') !== fences(x.body).join('\n')) err(code, label, 'a code block differs from the English'); + if (spans(e) !== spans(x)) err(code, label, 'its `code` spans differ from the English'); + if (urls(e) !== urls(x)) err(code, label, 'a link or URL differs from the English'); + if (versions(e) !== versions(x)) err(code, label, 'a version number differs from the English'); + } const v = [x.fm.summary, ...x.fm.highlights, ...x.fm.breaking, x.body].join('\n'); if (/[–—]/.test(v)) err(code, label, 'has an em or en dash'); if (!x.fm.summary.trim() || x.fm.highlights.some((h) => !h.trim())) err(code, label, 'has an empty summary or highlight'); diff --git a/scripts/i18n-check.test.mjs b/scripts/i18n-check.test.mjs new file mode 100644 index 00000000..2097e8cf --- /dev/null +++ b/scripts/i18n-check.test.mjs @@ -0,0 +1,52 @@ +// Proves the english_rewrite flag in scripts/i18n-check.mjs on a throwaway copy of the repo with two release entries: +// node scripts/i18n-check.test.mjs +// A flagged English entry whose code spans, links, versions and structure differ from its translations passes; the same +// entry without the flag fails on each of those checks; a flagged entry still fails the checks the flag does not cover. +import { cpSync, mkdtempSync, mkdirSync, readFileSync, readdirSync, rmSync, writeFileSync } from 'node:fs'; +import { tmpdir } from 'node:os'; +import { join, dirname } from 'node:path'; +import { fileURLToPath } from 'node:url'; +import { spawnSync } from 'node:child_process'; + +const repo = join(dirname(fileURLToPath(import.meta.url)), '..'); +const codes = [...readFileSync(join(repo, 'src/i18n/locales.ts'), 'utf8').matchAll(/\{ code: '([^']+)', path: '([^']*)'/g)].map((m) => ({ code: m[1], path: m[2] })).filter((l) => l.code !== 'en'); + +const fm = (lines) => ['---', ...lines, '---', ''].join('\n'); +const old = (extra = []) => fm(['product: flow', 'version: "9.9.9"', 'date: 2026-12-01', 'published: true', 'summary: "Old copy that mentions `old-span` and version 9.9.8 in its summary."', 'highlights:', ' - "One highlight."', ' - "Two highlights."', 'breaking: []', ...extra]) + + 'Old body for HotLoop Flow with `old-span` and 9.9.8.\n\n## What changed\n\n- One\n- Two\n\nSee [notes](https://example.com/old).\n'; +const rewrite = (extra) => fm(['product: flow', 'version: "9.9.9"', 'date: 2026-12-01', 'published: true', 'summary: "New sales copy for HotLoop Flow."', 'highlights:', ' - "Only one highlight."', 'breaking: []', ...extra]) + + 'New body with no spans, no links and no versions.\n'; +const translation = (lang) => fm([`lang: ${lang}`, 'product: flow', 'version: "9.9.9"', 'summary: "Old copy that mentions `old-span` and version 9.9.8 in its summary, translated."', 'highlights:', ' - "One highlight, translated."', ' - "Two highlights, translated."', 'breaking: []']) + + 'Old body for HotLoop Flow with `old-span` and 9.9.8, translated.\n\n## What changed\n\n- One\n- Two\n\nSee [notes](https://example.com/old).\n'; + +function run(english) { + const root = mkdtempSync(join(tmpdir(), 'i18n-check-')); + try { + for (const p of ['src/i18n', 'src/data', 'src/lib/products.ts', 'astro.config.mjs', 'scripts/i18n-check.mjs']) cpSync(join(repo, p), join(root, p), { recursive: true }); + mkdirSync(join(root, 'src/content/releases/flow'), { recursive: true }); + writeFileSync(join(root, 'src/content/releases/flow/9.9.9.md'), english); + for (const { code, path } of codes) { + mkdirSync(join(root, 'src/content/releases-i18n', path, 'flow'), { recursive: true }); + writeFileSync(join(root, 'src/content/releases-i18n', path, 'flow/9.9.9.md'), translation(path)); + } + const r = spawnSync('node', [join(root, 'scripts/i18n-check.mjs')], { encoding: 'utf8', env: { ...process.env, I18N_CHECK_ROOT: root } }); + return { status: r.status, out: (r.stdout || '') + (r.stderr || '') }; + } finally { rmSync(root, { recursive: true, force: true }); } +} +const releaseErrors = (out) => out.split('\n').filter((l) => /release flow\/9\.9\.9/.test(l)); +const fail = (m) => { console.error('FAIL ' + m); process.exitCode = 1; }; + +const plain = run(rewrite([])); +const kinds = ['structure differs', 'code` spans differ', 'link or URL differs', 'version number differs']; +for (const k of kinds) if (!releaseErrors(plain.out).some((l) => l.includes(k))) fail(`unflagged rewrite should fail on "${k}"`); + +const flagged = run(rewrite(['english_rewrite: true'])); +if (releaseErrors(flagged.out).length) fail('flagged rewrite should pass, got: ' + releaseErrors(flagged.out).slice(0, 3).join(' | ')); + +// the flag does not cover the other checks: a flagged entry whose summary is a dash-bearing copy of nothing still needs its translations. +const oldFlagged = run(old(['english_rewrite: true'])); +if (releaseErrors(oldFlagged.out).length) fail('flagged entry that still matches its translations should pass'); +const missing = run(rewrite(['english_rewrite: true']).replace('version: "9.9.9"', 'version: "9.9.8"')); +if (!missing.out.includes('has no translation')) fail('flagged entry with no translation should still fail on the missing translation'); + +if (!process.exitCode) console.log('i18n-check.test: ok (flagged rewrite passes, unflagged fails on structure, code spans, links and versions, missing translations still fail)'); diff --git a/src/content.config.ts b/src/content.config.ts index 1452c4fd..025ea14c 100644 --- a/src/content.config.ts +++ b/src/content.config.ts @@ -84,6 +84,9 @@ const releases = defineCollection({ summary: z.string().min(20), highlights: z.array(z.string()).min(1), breaking: z.array(z.string()).default([]), + // Set on an English entry rewritten after its translations were made: i18n-check then skips the structure, code span, + // link and version comparisons for that entry. The page never shows it. + english_rewrite: z.boolean().optional(), }), });