fix(coding-agent): normalize fuzzy edit matching and run touched tests closes #2044

This commit is contained in:
Mario Zechner
2026-03-15 19:08:24 +01:00
parent 1ae0833a72
commit 700bcf3455
3 changed files with 32 additions and 0 deletions

View File

@@ -25,6 +25,7 @@ read README.md, then ask which module(s) to work on. Based on the answer, read t
- NEVER run: `npm run dev`, `npm run build`, `npm test`
- Only run specific tests if user instructs: `npx tsx ../../node_modules/vitest/dist/cli.js --run test/specific.test.ts`
- Run tests from the package root, not the repo root.
- If you create or modify a test file, you MUST run that test file and iterate until it passes.
- When writing tests, run them, identify issues in either the test or implementation, and iterate until fixed.
- NEVER commit unless user asks

View File

@@ -34,6 +34,7 @@ export function restoreLineEndings(text: string, ending: "\r\n" | "\n"): string
export function normalizeForFuzzyMatch(text: string): string {
return (
text
.normalize("NFKC")
// Strip trailing whitespace per line
.split("\n")
.map((line) => line.trimEnd())

View File

@@ -442,6 +442,36 @@ describe("edit tool fuzzy matching", () => {
expect(content).toBe("replaced\nline three\n");
});
it("should match fullwidth punctuation in Chinese text", async () => {
const testFile = join(testDir, "chinese-punctuation.txt");
writeFileSync(testFile, "你好,世界\n你好世界\n");
const result = await editTool.execute("test-fuzzy-chinese", {
path: testFile,
oldText: "你好,世界\n你好(世界)\n",
newText: "你好pi\n你好(pi)\n",
});
expect(getTextOutput(result)).toContain("Successfully replaced");
const content = readFileSync(testFile, "utf-8");
expect(content).toBe("你好pi\n你好(pi)\n");
});
it("should match compatibility-equivalent Unicode forms", async () => {
const testFile = join(testDir, "unicode-compatibility.txt");
writeFileSync(testFile, "\ncafe\u0301\n");
const result = await editTool.execute("test-fuzzy-unicode", {
path: testFile,
oldText: "ABC123\ncafé\n",
newText: "XYZ789\ncoffee\n",
});
expect(getTextOutput(result)).toContain("Successfully replaced");
const content = readFileSync(testFile, "utf-8");
expect(content).toBe("XYZ789\ncoffee\n");
});
it("should match smart single quotes to ASCII quotes", async () => {
const testFile = join(testDir, "smart-quotes.txt");
// File has smart/curly single quotes (U+2018, U+2019)