Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2import { removeAgentCredits } from "./mergeMessage.ts";
3β
4describe("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("removes the footer Claude Code writes today, which links to claude.com", () => {
25 expect(
26 removeAgentCredits(
27 [
28 "Details",
29 "",
30 "π€ Generated with [Claude Code](https://claude.com/claude-code)",
31 "",
32 "Co-Authored-By: Claude <noreply@anthropic.com>",
33 ].join("\n"),
34 ),
35 ).toBe("Details");
36 });
37β
38 it("preserves unknown identities, humans named after agents, and ordinary prose", () => {
39 const message = [
40 "Co-authored-by: Claude <claude@example.com>",
41 "Co-authored-by: Alice <noreply@github.com>",
42 "Co-authored-by: Release Bot <release@example.com>",
43 "Generated by our new Claude integration.",
44 "Generated with [Claude Code](https://example.com)",
45 "",
46 ].join("\n");
47 expect(removeAgentCredits(message)).toBe(message);
48 });
49β
50 it("preserves code fences and block quotes containing attribution examples", () => {
51 const example = "Co-authored-by: Claude <noreply@anthropic.com>";
52 const message = `Example:\n\n\`\`\`text\n${example}\n\`\`\`\n\n> ${example}\n\n${example}`;
53 expect(removeAgentCredits(message)).toBe(
54 `Example:\n\n\`\`\`text\n${example}\n\`\`\`\n\n> ${example}`,
55 );
56 });
57β
58 it.each(["``` text ```", " ```", "\t~~~"])(
59 "removes trailers after a line that cannot open a fence: %s",
60 (line) => {
61 expect(removeAgentCredits(`${line}\n\nCo-authored-by: Claude <noreply@anthropic.com>`)).toBe(
62 line,
63 );
64 },
65 );
66β
67 it.each(["```", "~~~"])("keeps examples after a false closing fence: %s", (fence) => {
68 const example = "Co-authored-by: Claude <noreply@anthropic.com>";
69 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`;
70 expect(removeAgentCredits(`${content}\n\n${example}`)).toBe(content);
71 });
72β
73 it("preserves CRLF line endings", () => {
74 expect(
75 removeAgentCredits(
76 "Details\r\n\r\nCo-authored-by: Claude <noreply@anthropic.com>\r\nCo-authored-by: Alice <alice@example.com>",
77 ),
78 ).toBe("Details\r\n\r\nCo-authored-by: Alice <alice@example.com>");
79 });
80β
81 it("returns an empty body when only agent credits remain", () => {
82 expect(
83 removeAgentCredits("Co-authored-by: Claude <noreply@anthropic.com>\n\nGenerated by Codex\n"),
84 ).toBe("");
85 });
86});