-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add --tools filter to issues command #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,8 +2,10 @@ import { describe, it, expect, vi, beforeEach } from "vitest"; | |
| import { Command } from "commander"; | ||
| import { registerIssuesCommand } from "./issues"; | ||
| import { AnalysisService } from "../api/client/services/AnalysisService"; | ||
| import { ToolsService } from "../api/client/services/ToolsService"; | ||
|
|
||
| vi.mock("../api/client/services/AnalysisService"); | ||
| vi.mock("../api/client/services/ToolsService"); | ||
| vi.mock("../utils/credentials", () => ({ loadCredentials: vi.fn(() => null) })); | ||
| vi.spyOn(console, "log").mockImplementation(() => {}); | ||
|
|
||
|
|
@@ -612,6 +614,159 @@ describe("issues command", () => { | |
| ); | ||
| }); | ||
|
|
||
| describe("--tools filter", () => { | ||
| const mockToolList = { | ||
| data: [ | ||
| { uuid: "uuid-eslint", name: "ESLint", shortName: "eslint", prefix: "ESLint_" }, | ||
| { uuid: "uuid-eslint9", name: "ESLint 9", shortName: "eslint9", prefix: "ESLint9_" }, | ||
| { uuid: "uuid-semgrep", name: "Semgrep", shortName: "semgrep", prefix: "Semgrep_" }, | ||
| { uuid: "uuid-markdownlint", name: "Markdownlint", shortName: "markdownlint", prefix: "Markdownlint_" }, | ||
| { uuid: "uuid-remarklint", name: "Remarklint", shortName: "remarklint", prefix: "Remarklint_" }, | ||
| ], | ||
| pagination: undefined, | ||
| }; | ||
|
|
||
| it("should pass a UUID directly to body.toolUuids", async () => { | ||
| vi.mocked(AnalysisService.searchRepositoryIssues).mockResolvedValue({ | ||
| data: [], | ||
| } as any); | ||
|
|
||
| const program = createProgram(); | ||
| await program.parseAsync([ | ||
| "node", "test", "issues", "gh", "test-org", "test-repo", | ||
| "--tools", "a1b2c3d4-e5f6-7890-abcd-ef1234567890", | ||
| ]); | ||
|
|
||
| expect(ToolsService.listTools).not.toHaveBeenCalled(); | ||
| expect(AnalysisService.searchRepositoryIssues).toHaveBeenCalledWith( | ||
| "gh", "test-org", "test-repo", undefined, 100, | ||
| { toolUuids: ["a1b2c3d4-e5f6-7890-abcd-ef1234567890"] }, | ||
| ); | ||
| }); | ||
|
|
||
| it("should resolve an exact tool name to its UUID", async () => { | ||
| vi.mocked(ToolsService.listTools).mockResolvedValue(mockToolList as any); | ||
| vi.mocked(AnalysisService.searchRepositoryIssues).mockResolvedValue({ | ||
| data: [], | ||
| } as any); | ||
|
|
||
| const program = createProgram(); | ||
| await program.parseAsync([ | ||
| "node", "test", "issues", "gh", "test-org", "test-repo", | ||
| "--tools", "eslint", | ||
| ]); | ||
|
|
||
| expect(ToolsService.listTools).toHaveBeenCalled(); | ||
| expect(AnalysisService.searchRepositoryIssues).toHaveBeenCalledWith( | ||
| "gh", "test-org", "test-repo", undefined, 100, | ||
| { toolUuids: ["uuid-eslint"] }, | ||
| ); | ||
| }); | ||
|
|
||
| it("should resolve a shortName match to its UUID", async () => { | ||
| vi.mocked(ToolsService.listTools).mockResolvedValue(mockToolList as any); | ||
| vi.mocked(AnalysisService.searchRepositoryIssues).mockResolvedValue({ | ||
| data: [], | ||
| } as any); | ||
|
|
||
| const program = createProgram(); | ||
| await program.parseAsync([ | ||
| "node", "test", "issues", "gh", "test-org", "test-repo", | ||
| "--tools", "semgrep", | ||
| ]); | ||
|
|
||
| expect(AnalysisService.searchRepositoryIssues).toHaveBeenCalledWith( | ||
| "gh", "test-org", "test-repo", undefined, 100, | ||
| { toolUuids: ["uuid-semgrep"] }, | ||
| ); | ||
| }); | ||
|
|
||
| it("should resolve a substring match via prefix when only one tool matches", async () => { | ||
| vi.mocked(ToolsService.listTools).mockResolvedValue(mockToolList as any); | ||
| vi.mocked(AnalysisService.searchRepositoryIssues).mockResolvedValue({ | ||
| data: [], | ||
| } as any); | ||
|
|
||
| const program = createProgram(); | ||
| // "eslint9" matches shortName "eslint9" exactly | ||
| await program.parseAsync([ | ||
| "node", "test", "issues", "gh", "test-org", "test-repo", | ||
| "--tools", "eslint9", | ||
| ]); | ||
|
|
||
| expect(AnalysisService.searchRepositoryIssues).toHaveBeenCalledWith( | ||
| "gh", "test-org", "test-repo", undefined, 100, | ||
| { toolUuids: ["uuid-eslint9"] }, | ||
| ); | ||
| }); | ||
|
|
||
| it("should error when tool name is ambiguous", async () => { | ||
| vi.mocked(ToolsService.listTools).mockResolvedValue(mockToolList as any); | ||
|
|
||
| const mockExit = vi.spyOn(process, "exit").mockImplementation(() => { | ||
| throw new Error("process.exit called"); | ||
| }); | ||
| const mockStderr = vi.spyOn(console, "error").mockImplementation(() => {}); | ||
|
|
||
| const program = createProgram(); | ||
| await expect( | ||
| program.parseAsync([ | ||
| "node", "test", "issues", "gh", "test-org", "test-repo", | ||
| "--tools", "mark", | ||
|
Comment on lines
+721
to
+733
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ⚪ LOW RISK Nitpick: The new test cases for the Try running the following prompt in your IDE agent:
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The existing test suite in this file follows the same inline pattern. Introducing abstractions in tests reduces readability — keeping it as-is for consistency. |
||
| ]), | ||
| ).rejects.toThrow("process.exit called"); | ||
|
|
||
| expect(mockStderr).toHaveBeenCalledWith( | ||
| expect.stringContaining("ambiguous"), | ||
| ); | ||
|
|
||
| mockExit.mockRestore(); | ||
| mockStderr.mockRestore(); | ||
| }); | ||
|
|
||
| it("should error when tool name is not found", async () => { | ||
| vi.mocked(ToolsService.listTools).mockResolvedValue(mockToolList as any); | ||
|
|
||
| const mockExit = vi.spyOn(process, "exit").mockImplementation(() => { | ||
| throw new Error("process.exit called"); | ||
| }); | ||
| const mockStderr = vi.spyOn(console, "error").mockImplementation(() => {}); | ||
|
|
||
| const program = createProgram(); | ||
| await expect( | ||
| program.parseAsync([ | ||
| "node", "test", "issues", "gh", "test-org", "test-repo", | ||
| "--tools", "nonexistent", | ||
| ]), | ||
| ).rejects.toThrow("process.exit called"); | ||
|
|
||
| expect(mockStderr).toHaveBeenCalledWith( | ||
| expect.stringContaining('not found'), | ||
| ); | ||
|
|
||
| mockExit.mockRestore(); | ||
| mockStderr.mockRestore(); | ||
| }); | ||
|
|
||
| it("should handle mixed UUIDs and tool names", async () => { | ||
| vi.mocked(ToolsService.listTools).mockResolvedValue(mockToolList as any); | ||
| vi.mocked(AnalysisService.searchRepositoryIssues).mockResolvedValue({ | ||
| data: [], | ||
| } as any); | ||
|
|
||
| const program = createProgram(); | ||
| await program.parseAsync([ | ||
| "node", "test", "issues", "gh", "test-org", "test-repo", | ||
| "--tools", "a1b2c3d4-e5f6-7890-abcd-ef1234567890,semgrep", | ||
| ]); | ||
|
|
||
| expect(AnalysisService.searchRepositoryIssues).toHaveBeenCalledWith( | ||
| "gh", "test-org", "test-repo", undefined, 100, | ||
| { toolUuids: ["a1b2c3d4-e5f6-7890-abcd-ef1234567890", "uuid-semgrep"] }, | ||
| ); | ||
| }); | ||
| }); | ||
|
|
||
| it("should fail when CODACY_API_TOKEN is not set", async () => { | ||
| delete process.env.CODACY_API_TOKEN; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| import { describe, it, expect, vi, beforeEach } from "vitest"; | ||
| import { formatAnalysisStatus } from "./formatting"; | ||
| import { formatAnalysisStatus, resolveToolUuids } from "./formatting"; | ||
|
|
||
| // Mock ansis to return raw text for easier testing | ||
| vi.mock("ansis", () => ({ | ||
|
|
@@ -92,3 +92,92 @@ describe("formatAnalysisStatus", () => { | |
| expect(result).toBe("Never"); | ||
| }); | ||
| }); | ||
|
|
||
| describe("resolveToolUuids", () => { | ||
| const mockTools = [ | ||
| { uuid: "uuid-eslint", name: "ESLint", shortName: "eslint", prefix: "ESLint_" }, | ||
| { uuid: "uuid-eslint9", name: "ESLint 9", shortName: "eslint9", prefix: "ESLint9_" }, | ||
| { uuid: "uuid-semgrep", name: "Semgrep", shortName: "semgrep", prefix: "Semgrep_" }, | ||
| { uuid: "uuid-markdownlint", name: "Markdownlint", shortName: "markdownlint", prefix: "Markdownlint_" }, | ||
| { uuid: "uuid-remarklint", name: "Remarklint", shortName: "remarklint", prefix: "Remarklint_" }, | ||
| ] as any[]; | ||
|
|
||
| const fetchTools = vi.fn(async () => mockTools); | ||
|
|
||
| beforeEach(() => { | ||
| fetchTools.mockClear(); | ||
| }); | ||
|
|
||
| it("should pass UUIDs through without fetching tools", async () => { | ||
| const result = await resolveToolUuids( | ||
| ["a1b2c3d4-e5f6-7890-abcd-ef1234567890"], | ||
| fetchTools, | ||
| ); | ||
| expect(result).toEqual(["a1b2c3d4-e5f6-7890-abcd-ef1234567890"]); | ||
| expect(fetchTools).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it("should resolve exact name match (case-insensitive)", async () => { | ||
| const result = await resolveToolUuids(["eslint"], fetchTools); | ||
| expect(result).toEqual(["uuid-eslint"]); | ||
| }); | ||
|
|
||
| it("should resolve exact shortName match (case-insensitive)", async () => { | ||
| const result = await resolveToolUuids(["eslint9"], fetchTools); | ||
| expect(result).toEqual(["uuid-eslint9"]); | ||
| }); | ||
|
|
||
| it("should resolve a unique substring match via name", async () => { | ||
| const result = await resolveToolUuids(["semgr"], fetchTools); | ||
| expect(result).toEqual(["uuid-semgrep"]); | ||
| }); | ||
|
|
||
| it("should error on ambiguous substring match", async () => { | ||
| const mockExit = vi.spyOn(process, "exit").mockImplementation(() => { | ||
| throw new Error("process.exit called"); | ||
| }); | ||
| vi.spyOn(console, "error").mockImplementation(() => {}); | ||
|
|
||
| await expect(resolveToolUuids(["mark"], fetchTools)).rejects.toThrow( | ||
| "process.exit called", | ||
| ); | ||
|
|
||
| expect(console.error).toHaveBeenCalledWith( | ||
| expect.stringContaining("ambiguous"), | ||
| ); | ||
|
|
||
| mockExit.mockRestore(); | ||
| (console.error as any).mockRestore(); | ||
| }); | ||
|
Comment on lines
+135
to
+139
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch — fixing the spy references. |
||
|
|
||
| it("should error when tool is not found", async () => { | ||
| const mockExit = vi.spyOn(process, "exit").mockImplementation(() => { | ||
| throw new Error("process.exit called"); | ||
| }); | ||
| vi.spyOn(console, "error").mockImplementation(() => {}); | ||
|
|
||
| await expect(resolveToolUuids(["zzz"], fetchTools)).rejects.toThrow( | ||
| "process.exit called", | ||
| ); | ||
|
|
||
| expect(console.error).toHaveBeenCalledWith( | ||
| expect.stringContaining("not found"), | ||
| ); | ||
|
|
||
| mockExit.mockRestore(); | ||
| (console.error as any).mockRestore(); | ||
| }); | ||
|
|
||
| it("should handle mixed UUIDs and names, fetching tools only once", async () => { | ||
| const result = await resolveToolUuids( | ||
| ["a1b2c3d4-e5f6-7890-abcd-ef1234567890", "semgrep", "eslint"], | ||
| fetchTools, | ||
| ); | ||
| expect(result).toEqual([ | ||
| "a1b2c3d4-e5f6-7890-abcd-ef1234567890", | ||
| "uuid-semgrep", | ||
| "uuid-eslint", | ||
| ]); | ||
| expect(fetchTools).toHaveBeenCalledTimes(1); | ||
| }); | ||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right — renaming to reflect what it actually tests, and adding a separate test for true substring/prefix matching.