From bbb946e99082cf245430f47258bc6a518ef61f24 Mon Sep 17 00:00:00 2001 From: protosphinx <133899485+protosphinx@users.noreply.github.com> Date: Mon, 1 Jun 2026 00:10:00 +0800 Subject: [PATCH] test(fix): add CRLF line-ending coverage for name-drift rewrite --- test/fix.test.ts | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/test/fix.test.ts b/test/fix.test.ts index be52e76..60dd388 100644 --- a/test/fix.test.ts +++ b/test/fix.test.ts @@ -175,4 +175,49 @@ describe("applyFixes", () => { expect(c1).toContain("name: alpha"); expect(c2).toContain("name: beta"); }); + + it("fixes name-drift on a file with CRLF line endings", async () => { + const file = await writeSkill( + "myskill.md", + `---\r\nname: wrongname\r\ndescription: x\r\n---\r\nbody\r\n`, + ); + const parsed = await parseSkillFile(file); + const outcome = await applyFixes( + [parsed], + [{ severity: "warn", rule: "name-drift", message: "", file }], + ); + expect(outcome.fixed).toBe(1); + const written = await readFile(file, "utf8"); + expect(written).toContain("name: myskill"); + expect(written).not.toContain("name: wrongname"); + }); + + it("preserves body line endings after fixing CRLF frontmatter", async () => { + const file = await writeSkill( + "myskill.md", + `---\r\nname: wrongname\r\ndescription: x\r\n---\r\nline one\r\nline two\r\n`, + ); + const parsed = await parseSkillFile(file); + await applyFixes( + [parsed], + [{ severity: "warn", rule: "name-drift", message: "", file }], + ); + const written = await readFile(file, "utf8"); + expect(written).toContain("line one\r\n"); + expect(written).toContain("line two\r\n"); + }); + + it("skips a CRLF file when the name field is absent", async () => { + const original = `---\r\ndescription: x\r\n---\r\nbody\r\n`; + const file = await writeSkill("myskill.md", original); + const parsed = await parseSkillFile(file); + const outcome = await applyFixes( + [parsed], + [{ severity: "warn", rule: "name-drift", message: "", file }], + ); + expect(outcome.fixed).toBe(0); + expect(outcome.skipped).toBe(1); + const written = await readFile(file, "utf8"); + expect(written).toBe(original); + }); });