mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-11-16 17:09:09 +00:00
fix(scripts): restore a claim with the base's own text in the strip pass
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.
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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 = "<td>۱۴۷ ماژول، ۲۳۳ مهاجرت</td>\n";
|
||||
const head = "<td>۱۴۷ ماژول، 234 مهاجرت</td>\n";
|
||||
const r = strip.restoreClaims(base, head, [nativeCheck]);
|
||||
assert.equal(r.content, base, "byte-identical to the base line");
|
||||
assert.deepEqual(r.edits, [
|
||||
{ label: "DB migrations count (README mirrors)", from: "234", to: "233" },
|
||||
]);
|
||||
assert.deepEqual(r.manual, []);
|
||||
});
|
||||
|
||||
test("claims: a PR that adds or removes a claim is left to a human", () => {
|
||||
const r = strip.restoreClaims("387 providers.\n", "388 providers. Also 388 providers.\n", [
|
||||
providerCheck,
|
||||
|
||||
Reference in New Issue
Block a user