Fix hashline-edit deduplication and validation

- Canonicalize anchors in dedupe keys to handle whitespace variants
- Make lines field required in edit operations
- Only allow unanchored append/prepend to create missing files
- Reorder delete/rename validation to prevent edge cases
- Add allow_non_gpt_model and max_prompt_tokens to config schema
  ```
This commit is contained in:
minpeter
2026-02-26 17:43:49 +09:00
parent 58201220cc
commit b1203b9501
7 changed files with 117 additions and 15 deletions
@@ -1,5 +1,5 @@
import { describe, expect, it } from "bun:test"
import { applyHashlineEdits } from "./edit-operations"
import { applyHashlineEdits, applyHashlineEditsWithReport } from "./edit-operations"
import { applyAppend, applyInsertAfter, applyPrepend, applyReplaceLines, applySetLine } from "./edit-operation-primitives"
import { computeLineHash } from "./hash-computation"
import type { HashlineEdit } from "./types"
@@ -389,3 +389,23 @@ describe("hashline edit operations", () => {
expect(result).toEqual("replaced A\nline 3\nreplaced B")
})
})
describe("dedupe anchor canonicalization", () => {
it("deduplicates edits with whitespace-variant anchors", () => {
//#given
const content = "line 1\nline 2"
const lines = content.split("\n")
const canonical = `1#${computeLineHash(1, lines[0])}`
const spaced = ` 1 # ${computeLineHash(1, lines[0])} `
//#when
const report = applyHashlineEditsWithReport(content, [
{ op: "append", pos: canonical, lines: ["inserted"] },
{ op: "append", pos: spaced, lines: ["inserted"] },
])
//#then
expect(report.deduplicatedEdits).toBe(1)
expect(report.content).toBe("line 1\ninserted\nline 2")
})
})