| 1 | import { describe, expect, it } from "vite-plus/test"; |
| 2 | import { removeAgentCredits } from "./mergeMessage.ts"; |
| 3 | |
| 4 | describe("removeAgentCredits", () => { |
| 5 | it("removes recognized agent trailers and generated footers, keeping human co-authors", () => { |
| 6 | expect( |
| 7 | removeAgentCredits( |
| 8 | [ |
| 9 | "Details about Claude support.", |
| 10 | "", |
| 11 | "", |
| 12 | "Co-authored-by: Alice <alice@example.com>", |
| 13 | "Co-authored-by: Claude <noreply@anthropic.com>", |
| 14 | "* Co-authored-by: Codex <noreply@openai.com>", |
| 15 | "co-authored-by: Cursor <cursoragent@cursor.com>", |
| 16 | "Co-authored-by: Copilot <copilot@github.com>", |
| 17 | "", |
| 18 | "🤖 Generated with [Claude Code](https://claude.ai/code)", |
| 19 | ].join("\n"), |
| 20 | ), |
| 21 | ).toBe("Details about Claude support.\n\n\nCo-authored-by: Alice <alice@example.com>"); |
| 22 | }); |
| 23 | |
| 24 | it("preserves unknown identities, humans named after agents, and ordinary prose", () => { |
| 25 | const message = [ |
| 26 | "Co-authored-by: Claude <claude@example.com>", |
| 27 | "Co-authored-by: Alice <noreply@github.com>", |
| 28 | "Co-authored-by: Release Bot <release@example.com>", |
| 29 | "Generated by our new Claude integration.", |
| 30 | "Generated with [Claude Code](https://example.com)", |
| 31 | "", |
| 32 | ].join("\n"); |
| 33 | expect(removeAgentCredits(message)).toBe(message); |
| 34 | }); |
| 35 | |
| 36 | it("preserves code fences and block quotes containing attribution examples", () => { |
| 37 | const example = "Co-authored-by: Claude <noreply@anthropic.com>"; |
| 38 | const message = `Example:\n\n\`\`\`text\n${example}\n\`\`\`\n\n> ${example}\n\n${example}`; |
| 39 | expect(removeAgentCredits(message)).toBe( |
| 40 | `Example:\n\n\`\`\`text\n${example}\n\`\`\`\n\n> ${example}`, |
| 41 | ); |
| 42 | }); |
| 43 | |
| 44 | it("preserves indented examples and whitespace on surviving lines", () => { |
| 45 | const example = "Co-authored-by: Claude <noreply@anthropic.com>"; |
| 46 | expect(removeAgentCredits(`Example:\n\n ${example}\n\n${example}\nDetails \n`)).toBe( |
| 47 | `Example:\n\n ${example}\n\nDetails `, |
| 48 | ); |
| 49 | }); |
| 50 | |
| 51 | it.each(["``` text ```", " ```", "\t~~~"])( |
| 52 | "removes trailers after a line that cannot open a fence: %s", |
| 53 | (line) => { |
| 54 | expect(removeAgentCredits(`${line}\n\nCo-authored-by: Claude <noreply@anthropic.com>`)).toBe( |
| 55 | line, |
| 56 | ); |
| 57 | }, |
| 58 | ); |
| 59 | |
| 60 | it.each(["```", "~~~"])("keeps examples after a false closing fence: %s", (fence) => { |
| 61 | const example = "Co-authored-by: Claude <noreply@anthropic.com>"; |
| 62 | 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`; |
| 63 | expect(removeAgentCredits(`${content}\n\n${example}`)).toBe(content); |
| 64 | }); |
| 65 | |
| 66 | it("preserves CRLF line endings", () => { |
| 67 | expect( |
| 68 | removeAgentCredits( |
| 69 | "Details\r\n\r\nCo-authored-by: Claude <noreply@anthropic.com>\r\nCo-authored-by: Alice <alice@example.com>", |
| 70 | ), |
| 71 | ).toBe("Details\r\n\r\nCo-authored-by: Alice <alice@example.com>"); |
| 72 | }); |
| 73 | |
| 74 | it("returns an empty body when only agent credits remain", () => { |
| 75 | expect( |
| 76 | removeAgentCredits("Co-authored-by: Claude <noreply@anthropic.com>\n\nGenerated by Codex\n"), |
| 77 | ).toBe(""); |
| 78 | }); |
| 79 | }); |