fix(hashline-edit): align autocorrect, BOM/CRLF, and tool description with oh-my-pi
- Rewrite restoreOldWrappedLines to use oh-my-pi's span-scanning algorithm - Add stripTrailingContinuationTokens and stripMergeOperatorChars helpers - Fix detectLineEnding to use first-occurrence logic instead of any-match - Fix applyAppend/applyPrepend to replace empty-line placeholder in empty files - Enhance tool description with 7 critical rules, tag guidance, and anti-patterns
This commit is contained in:
@@ -2,6 +2,7 @@ import { describe, it, expect, beforeEach, afterEach, mock } from "bun:test"
|
||||
import type { ToolContext } from "@opencode-ai/plugin/tool"
|
||||
import { createHashlineEditTool } from "./tools"
|
||||
import { computeLineHash } from "./hash-computation"
|
||||
import { canonicalizeFileText } from "./file-text-canonicalization"
|
||||
import * as fs from "node:fs"
|
||||
import * as os from "node:os"
|
||||
import * as path from "node:path"
|
||||
@@ -262,4 +263,26 @@ describe("createHashlineEditTool", () => {
|
||||
expect(bytes[2]).toBe(0xbf)
|
||||
expect(bytes.toString("utf-8")).toBe("\uFEFFline1\r\nline2-updated\r\n")
|
||||
})
|
||||
|
||||
it("detects LF as line ending when LF appears before CRLF", () => {
|
||||
//#given
|
||||
const content = "line1\nline2\r\nline3"
|
||||
|
||||
//#when
|
||||
const envelope = canonicalizeFileText(content)
|
||||
|
||||
//#then
|
||||
expect(envelope.lineEnding).toBe("\n")
|
||||
})
|
||||
|
||||
it("detects CRLF as line ending when CRLF appears before LF", () => {
|
||||
//#given
|
||||
const content = "line1\r\nline2\nline3"
|
||||
|
||||
//#when
|
||||
const envelope = canonicalizeFileText(content)
|
||||
|
||||
//#then
|
||||
expect(envelope.lineEnding).toBe("\r\n")
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user