From a321a94ee78f5a5512b4bd255523adc1d382d2fe Mon Sep 17 00:00:00 2001 From: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com> Date: Sun, 15 Nov 2026 04:35:20 -0300 Subject: [PATCH] fix(scripts): restore a claim with the base's own text in the strip pass MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit restoreClaims wrote the parsed base value back as an ASCII number. A translated mirror that writes the count in native digits (Persian README: "۲۳۳ مهاجرت") got "233" instead, so the line still differed from the merge base and the PR kept conflicting on that mirror. Use the base's exact substring for the claim span. Regression test with a Persian-digit claim fails on the old code and passes now. --- scripts/ad-hoc/strip-derived-from-pr.mjs | 5 ++++- tests/unit/strip-derived-from-pr.test.ts | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/scripts/ad-hoc/strip-derived-from-pr.mjs b/scripts/ad-hoc/strip-derived-from-pr.mjs index 1ea86600571..1f6b0baaa1d 100644 --- a/scripts/ad-hoc/strip-derived-from-pr.mjs +++ b/scripts/ad-hoc/strip-derived-from-pr.mjs @@ -52,6 +52,8 @@ export function classifyFile(file, { claimFiles, instructionFiles }) { /** * Each managed value the head changed goes back to the base value of the same claim (same check, * same position). A check whose claim count differs between base and head is left to a human. + * The replacement is the base's own text for that claim, not the parsed value: a mirror that + * writes "۲۳۳" must get "۲۳۳" back, or the line still differs from the base and keeps conflicting. */ export function restoreClaims(base, head, checks) { const edits = []; @@ -72,6 +74,7 @@ export function restoreClaims(base, head, checks) { label: check.label, from: hv[i], to: bv[i], + text: b[i].start >= 0 ? (base ?? "").slice(b[i].start, b[i].end) : bv[i], start: claim.start, end: claim.end, }); @@ -84,7 +87,7 @@ export function restoreClaims(base, head, checks) { const key = `${e.start}:${e.end}`; if (seen.has(key)) continue; seen.add(key); - content = content.slice(0, e.start) + e.to + content.slice(e.end); + content = content.slice(0, e.start) + e.text + content.slice(e.end); } for (const check of checks) { if (!edits.some((e) => e.label === check.label)) continue; diff --git a/tests/unit/strip-derived-from-pr.test.ts b/tests/unit/strip-derived-from-pr.test.ts index 543d38d6ccb..a1f7e412e8f 100644 --- a/tests/unit/strip-derived-from-pr.test.ts +++ b/tests/unit/strip-derived-from-pr.test.ts @@ -84,6 +84,28 @@ test("claims: each value the PR changed goes back to the base value; prose edits assert.deepEqual(r.manual, []); }); +test("claims: the base's own digits come back, not a re-rendered number", () => { + // A translated mirror writes the count in Persian digits; the head rewrote it in ASCII. + const toAscii = (t: string) => t.replace(/[۰-۹]/g, (d) => String("۰۱۲۳۴۵۶۷۸۹".indexOf(d))); + const nativeCheck: Check = { + label: "DB migrations count (README mirrors)", + extract: (content) => + [...content.matchAll(/([0-9۰-۹]+) مهاجرت/dg)].map((m) => ({ + value: Number(toAscii(m[1])), + start: (m as unknown as { indices: [number, number][] }).indices[1][0], + end: (m as unknown as { indices: [number, number][] }).indices[1][1], + })), + }; + const base = "