80 lines
3.1 KiB
TypeScript
80 lines
3.1 KiB
TypeScript
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 <[email protected]>",
|
|
"Co-authored-by: Claude <[email protected]>",
|
|
"* Co-authored-by: Codex <[email protected]>",
|
|
"co-authored-by: Cursor <[email protected]>",
|
|
"Co-authored-by: Copilot <[email protected]>",
|
|
"",
|
|
"🤖 Generated with [Claude Code](https://claude.ai/code)",
|
|
].join("\n"),
|
|
),
|
|
).toBe("Details about Claude support.\n\n\nCo-authored-by: Alice <[email protected]>");
|
|
});
|
|
|
|
it("preserves unknown identities, humans named after agents, and ordinary prose", () => {
|
|
const message = [
|
|
"Co-authored-by: Claude <[email protected]>",
|
|
"Co-authored-by: Alice <[email protected]>",
|
|
"Co-authored-by: Release Bot <[email protected]>",
|
|
"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 <[email protected]>";
|
|
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 <[email protected]>";
|
|
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 <[email protected]>`)).toBe(
|
|
line,
|
|
);
|
|
},
|
|
);
|
|
|
|
it.each(["```", "~~~"])("keeps examples after a false closing fence: %s", (fence) => {
|
|
const example = "Co-authored-by: Claude <[email protected]>";
|
|
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 <[email protected]>\r\nCo-authored-by: Alice <[email protected]>",
|
|
),
|
|
).toBe("Details\r\n\r\nCo-authored-by: Alice <[email protected]>");
|
|
});
|
|
|
|
it("returns an empty body when only agent credits remain", () => {
|
|
expect(
|
|
removeAgentCredits("Co-authored-by: Claude <[email protected]>\n\nGenerated by Codex\n"),
|
|
).toBe("");
|
|
});
|
|
});
|