mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 10:40:43 +00:00
ci: guard unused dead-code files
This commit is contained in:
57
test/scripts/check-deadcode-unused-files.test.ts
Normal file
57
test/scripts/check-deadcode-unused-files.test.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
checkUnusedFiles,
|
||||
compareUnusedFilesToAllowlist,
|
||||
parseKnipCompactUnusedFiles,
|
||||
} from "../../scripts/check-deadcode-unused-files.mjs";
|
||||
|
||||
describe("check-deadcode-unused-files", () => {
|
||||
it("parses the compact Knip unused-file section", () => {
|
||||
expect(
|
||||
parseKnipCompactUnusedFiles(`
|
||||
> openclaw@2026.4.27 deadcode:knip /repo
|
||||
> pnpm dlx knip --reporter compact --files
|
||||
|
||||
Unused files (2)
|
||||
src/b.ts: src/b.ts
|
||||
src/a.ts: src/a.ts
|
||||
|
||||
Unused dependencies (1)
|
||||
left-pad: package.json
|
||||
`),
|
||||
).toEqual(["src/a.ts", "src/b.ts"]);
|
||||
});
|
||||
|
||||
it("parses Knip's files-only compact output", () => {
|
||||
expect(parseKnipCompactUnusedFiles("src/b.ts: src/b.ts\nsrc/a.ts: src/a.ts\n")).toEqual([
|
||||
"src/a.ts",
|
||||
"src/b.ts",
|
||||
]);
|
||||
});
|
||||
|
||||
it("reports unexpected and stale allowlist entries", () => {
|
||||
expect(
|
||||
compareUnusedFilesToAllowlist(["src/a.ts", "src/new.ts"], ["src/a.ts", "src/old.ts"]),
|
||||
).toMatchObject({
|
||||
unexpected: ["src/new.ts"],
|
||||
stale: ["src/old.ts"],
|
||||
duplicateAllowedCount: 0,
|
||||
allowlistIsSorted: true,
|
||||
});
|
||||
});
|
||||
|
||||
it("accepts exactly allowlisted unused files", () => {
|
||||
expect(checkUnusedFiles("Unused files (1)\nsrc/a.ts: src/a.ts\n", ["src/a.ts"])).toMatchObject({
|
||||
ok: true,
|
||||
message: "",
|
||||
});
|
||||
});
|
||||
|
||||
it("rejects unsorted allowlists", () => {
|
||||
expect(
|
||||
compareUnusedFilesToAllowlist(["src/a.ts", "src/b.ts"], ["src/b.ts", "src/a.ts"]),
|
||||
).toMatchObject({
|
||||
allowlistIsSorted: false,
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user