Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 23 additions & 10 deletions rules/ast-grep/stale-identity.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,29 @@ const allowedLegacyCleanupMatches = new Set([
`packages/sdk-python/tests/test_build.py:"${legacyDistributionName}-0.1.0.tar.gz",`,
]);

const findUnexpectedMatches = (stdout: string): string[] =>
stdout
.trim()
// Windows git writes CRLF; retaining the carriage return breaks the anchored parser below.
.split(/\r?\n/u)
Comment thread
abhinavkr26104 marked this conversation as resolved.
.filter(Boolean)
.flatMap((match) => {
const parsed = /^(?<file>[^:]+):\d+:(?<contents>.*)$/u.exec(match)?.groups;
if (!parsed?.file || parsed.contents === undefined) return [match];
const identity = `${parsed.file}:${parsed.contents.trim()}`;
return allowedLegacyCleanupMatches.has(identity) ? [] : [match];
});

describe("Retired package identities", () => {
it("accepts exact legacy cleanup matches with CRLF line endings", () => {
const output = [
`packages/sdk-python/scripts/build.py:18: "${legacyDistributionName}-*.whl",`,
`packages/sdk-python/tests/test_build.py:13: "${legacyDistributionName}-0.1.0.tar.gz",`,
].join("\r\n");

expect(findUnexpectedMatches(output)).toEqual([]);
});

it("does not reintroduce a Stagehand v4 package or test identity", async () => {
const pattern = ["stagehand", "[-_]v4"].join("");
let stdout = "";
Expand All @@ -27,16 +49,7 @@ describe("Retired package identities", () => {
if (grepError.code !== 1) throw error;
stdout = grepError.stdout ?? "";
}
const unexpected = stdout
.trim()
.split("\n")
.filter(Boolean)
.flatMap((match) => {
const parsed = /^(?<file>[^:]+):\d+:(?<contents>.*)$/u.exec(match)?.groups;
if (!parsed?.file || parsed.contents === undefined) return [match];
const identity = `${parsed.file}:${parsed.contents.trim()}`;
return allowedLegacyCleanupMatches.has(identity) ? [] : [match];
});
const unexpected = findUnexpectedMatches(stdout);

expect(
unexpected,
Expand Down