import { describe, expect, it } from "vite-plus/test"; import { removeAgentCredits } from "./mergeMessage.ts"; describe("removeAgentCredits", () => { it("removes recognized agent trailers and generated footers, keeping human co-authors", () => { expect( removeAgentCredits( [ "Details about Claude support.", "", "", "Co-authored-by: Alice ", "Co-authored-by: Claude ", "* Co-authored-by: Codex ", "co-authored-by: Cursor ", "Co-authored-by: Copilot ", "", "🤖 Generated with [Claude Code](https://claude.ai/code)", ].join("\n"), ), ).toBe("Details about Claude support.\n\n\nCo-authored-by: Alice "); }); it("preserves unknown identities, humans named after agents, and ordinary prose", () => { const message = [ "Co-authored-by: Claude ", "Co-authored-by: Alice ", "Co-authored-by: Release Bot ", "Generated by our new Claude integration.", "Generated with [Claude Code](https://example.com)", "", ].join("\n"); expect(removeAgentCredits(message)).toBe(message); }); it("preserves code fences and block quotes containing attribution examples", () => { const example = "Co-authored-by: Claude "; const message = `Example:\n\n\`\`\`text\n${example}\n\`\`\`\n\n> ${example}\n\n${example}`; expect(removeAgentCredits(message)).toBe( `Example:\n\n\`\`\`text\n${example}\n\`\`\`\n\n> ${example}`, ); }); it("preserves indented examples and whitespace on surviving lines", () => { const example = "Co-authored-by: Claude "; expect(removeAgentCredits(`Example:\n\n ${example}\n\n${example}\nDetails \n`)).toBe( `Example:\n\n ${example}\n\nDetails `, ); }); it.each(["``` text ```", " ```", "\t~~~"])( "removes trailers after a line that cannot open a fence: %s", (line) => { expect(removeAgentCredits(`${line}\n\nCo-authored-by: Claude `)).toBe( line, ); }, ); it.each(["```", "~~~"])("keeps examples after a false closing fence: %s", (fence) => { const example = "Co-authored-by: Claude "; const content = `${fence}text\n${fence} trailing text\n${example}\n ${fence}\n${example}\n${fence.slice(0, 2)}\n${example}\n ${fence}${fence[0]} \t`; expect(removeAgentCredits(`${content}\n\n${example}`)).toBe(content); }); it("preserves CRLF line endings", () => { expect( removeAgentCredits( "Details\r\n\r\nCo-authored-by: Claude \r\nCo-authored-by: Alice ", ), ).toBe("Details\r\n\r\nCo-authored-by: Alice "); }); it("returns an empty body when only agent credits remain", () => { expect( removeAgentCredits("Co-authored-by: Claude \n\nGenerated by Codex\n"), ).toBe(""); }); });