|
4 | 4 |
|
5 | 5 | import { describe, it, expect, vi, beforeEach } from 'vitest'; |
6 | 6 | import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'fs'; |
7 | | -import { join } from 'path'; |
| 7 | +import { dirname, join } from 'path'; |
8 | 8 | import { McpServer } from '@modelcontextprotocol/sdk/server/mcp'; |
9 | 9 | import { z } from 'zod'; |
10 | 10 | import { |
@@ -705,6 +705,10 @@ describe('registerCLITool handler behavior', () => { |
705 | 705 | expect(existsSync(dilFilePath)).toBe(true); |
706 | 706 | const fileContent = readFileSync(dilFilePath, 'utf8'); |
707 | 707 | expect(fileContent).toBe(dilContent); |
| 708 | + |
| 709 | + // Clean up generated .dil file and its containing log directory |
| 710 | + const dilDir = dirname(dilFilePath); |
| 711 | + rmSync(dilDir, { recursive: true, force: true }); |
708 | 712 | }); |
709 | 713 |
|
710 | 714 | it('should not save DIL file when dump-dil is explicitly false for codeql_query_compile', async () => { |
@@ -736,6 +740,35 @@ describe('registerCLITool handler behavior', () => { |
736 | 740 | expect(result.content[0].text).not.toContain('DIL file:'); |
737 | 741 | }); |
738 | 742 |
|
| 743 | + it('should not save DIL file when --no-dump-dil is in additionalArgs for codeql_query_compile', async () => { |
| 744 | + const definition: CLIToolDefinition = { |
| 745 | + name: 'codeql_query_compile', |
| 746 | + description: 'Compile query', |
| 747 | + command: 'codeql', |
| 748 | + subcommand: 'query compile', |
| 749 | + inputSchema: { |
| 750 | + query: z.string(), |
| 751 | + 'dump-dil': z.boolean().optional(), |
| 752 | + additionalArgs: z.array(z.string()).optional() |
| 753 | + } |
| 754 | + }; |
| 755 | + |
| 756 | + registerCLITool(mockServer, definition); |
| 757 | + |
| 758 | + const handler = (mockServer.registerTool as ReturnType<typeof vi.fn>).mock.calls[0][2]; |
| 759 | + |
| 760 | + executeCodeQLCommand.mockResolvedValueOnce({ |
| 761 | + stdout: 'Compilation successful', |
| 762 | + stderr: '', |
| 763 | + success: true |
| 764 | + }); |
| 765 | + |
| 766 | + const result = await handler({ query: '/path/to/MyQuery.ql', additionalArgs: ['--no-dump-dil'] }); |
| 767 | + |
| 768 | + // Response should NOT contain DIL file path since --no-dump-dil disables DIL |
| 769 | + expect(result.content[0].text).not.toContain('DIL file:'); |
| 770 | + }); |
| 771 | + |
739 | 772 | it('should pass format to CLI for codeql_bqrs_interpret', async () => { |
740 | 773 | const definition: CLIToolDefinition = { |
741 | 774 | name: 'codeql_bqrs_interpret', |
|
0 commit comments