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 <alice@example.com>",
"Co-authored-by: Claude <noreply@anthropic.com>",
"* Co-authored-by: Codex <noreply@openai.com>",
"co-authored-by: Cursor <cursoragent@cursor.com>",
"Co-authored-by: Copilot <copilot@github.com>",
"",
"🤖 Generated with [Claude Code](https://claude.ai/code)",
].join("\n"),
),
).toBe("Details about Claude support.\n\n\nCo-authored-by: Alice <alice@example.com>");
});
it("removes the footer Claude Code writes today, which links to claude.com", () => {
expect(
removeAgentCredits(
[
"Details",
"",
"🤖 Generated with [Claude Code](https://claude.com/claude-code)",
"",
"Co-Authored-By: Claude <noreply@anthropic.com>",
].join("\n"),
),
).toBe("Details");
});
it("preserves unknown identities, humans named after agents, and ordinary prose", () => {
const message = [
"Co-authored-by: Claude <claude@example.com>",
"Co-authored-by: Alice <noreply@github.com>",
"Co-authored-by: Release Bot <release@example.com>",
"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 <noreply@anthropic.com>";
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.each(["``` text ```", " ```", "\t~~~"])(
"removes trailers after a line that cannot open a fence: %s",
(line) => {
expect(removeAgentCredits(`${line}\n\nCo-authored-by: Claude <noreply@anthropic.com>`)).toBe(
line,
);
},
);
it.each(["```", "~~~"])("keeps examples after a false closing fence: %s", (fence) => {
const example = "Co-authored-by: Claude <noreply@anthropic.com>";
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 <noreply@anthropic.com>\r\nCo-authored-by: Alice <alice@example.com>",
),
).toBe("Details\r\n\r\nCo-authored-by: Alice <alice@example.com>");
});
it("returns an empty body when only agent credits remain", () => {
expect(
removeAgentCredits("Co-authored-by: Claude <noreply@anthropic.com>\n\nGenerated by Codex\n"),
).toBe("");
});
});