fix(hashline): use strict whitespace hashing (trimEnd only, preserve leading indentation)

Previously computeLineHash stripped ALL whitespace before hashing, making
indentation changes invisible to hash validation. This weakened the stale-line
detection guarantee, especially for indentation-sensitive files (Python, YAML).

Now only trailing whitespace and carriage returns are stripped, matching
oh-my-pi upstream behavior. Leading indentation is preserved in the hash,
so indentation-only changes correctly trigger hash mismatches.
This commit is contained in:
YeonGyu-Kim
2026-03-12 16:42:41 +09:00
parent 04b0d62a55
commit 0cbc15da96
2 changed files with 29 additions and 3 deletions
@@ -45,10 +45,36 @@ describe("computeLineHash", () => {
expect(hash1).not.toBe(hash2)
})
it("ignores whitespace differences", () => {
it("produces different hashes for different leading indentation", () => {
//#given
const content1 = "function hello() {"
const content2 = " function hello() { "
const content2 = " function hello() {"
//#when
const hash1 = computeLineHash(1, content1)
const hash2 = computeLineHash(1, content2)
//#then
expect(hash1).not.toBe(hash2)
})
it("ignores trailing whitespace differences", () => {
//#given
const content1 = "function hello() {"
const content2 = "function hello() { "
//#when
const hash1 = computeLineHash(1, content1)
const hash2 = computeLineHash(1, content2)
//#then
expect(hash1).toBe(hash2)
})
it("produces same hash for CRLF and LF line endings", () => {
//#given
const content1 = "function hello() {"
const content2 = "function hello() {\r"
//#when
const hash1 = computeLineHash(1, content1)