From 1339ecdd13b831e99b856aec10964b924a53d2ec Mon Sep 17 00:00:00 2001 From: YeonGyu-Kim Date: Mon, 16 Mar 2026 13:52:26 +0900 Subject: [PATCH] fix(hashline): restore v3.11.2 legacy hash computation for backward compatibility MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🤖 Generated with [OhMyOpenCode](https://github.com/code-yeongyu/oh-my-openagent) --- src/tools/hashline-edit/hash-computation.test.ts | 13 +++++++++++++ src/tools/hashline-edit/hash-computation.ts | 2 +- src/tools/hashline-edit/validation.test.ts | 9 +++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/tools/hashline-edit/hash-computation.test.ts b/src/tools/hashline-edit/hash-computation.test.ts index 60350c736..15f19dfee 100644 --- a/src/tools/hashline-edit/hash-computation.test.ts +++ b/src/tools/hashline-edit/hash-computation.test.ts @@ -72,6 +72,19 @@ describe("computeLineHash", () => { expect(hash1).toBe(hash2) }) + it("preserves legacy hashes for internal whitespace variants", () => { + //#given + const content1 = "if (a && b) {" + const content2 = "if(a&&b){" + + //#when + const hash1 = computeLegacyLineHash(1, content1) + const hash2 = computeLegacyLineHash(1, content2) + + //#then + expect(hash1).toBe(hash2) + }) + it("ignores trailing whitespace differences", () => { //#given const content1 = "function hello() {" diff --git a/src/tools/hashline-edit/hash-computation.ts b/src/tools/hashline-edit/hash-computation.ts index 7434445cf..ac8d3f55c 100644 --- a/src/tools/hashline-edit/hash-computation.ts +++ b/src/tools/hashline-edit/hash-computation.ts @@ -16,7 +16,7 @@ export function computeLineHash(lineNumber: number, content: string): string { } export function computeLegacyLineHash(lineNumber: number, content: string): string { - return computeNormalizedLineHash(lineNumber, content.replace(/\r/g, "").trim()) + return computeNormalizedLineHash(lineNumber, content.replace(/\r/g, "").replace(/\s+/g, "")) } export function formatHashLine(lineNumber: number, content: string): string { diff --git a/src/tools/hashline-edit/validation.test.ts b/src/tools/hashline-edit/validation.test.ts index 8839103db..739def9fa 100644 --- a/src/tools/hashline-edit/validation.test.ts +++ b/src/tools/hashline-edit/validation.test.ts @@ -125,6 +125,15 @@ describe("validateLineRef", () => { expect(() => validateLineRef(lines, `1#${legacyHash}`)).not.toThrow() }) + it("accepts legacy hashes for internal whitespace variants", () => { + //#given + const lines = ["if (a && b) {"] + const legacyHash = computeLegacyLineHash(1, "if(a&&b){") + + //#when / #then + expect(() => validateLineRef(lines, `1#${legacyHash}`)).not.toThrow() + }) + it("shows >>> mismatch context in batched validation", () => { //#given const lines = ["one", "two", "three", "four"]