From 974b6b312f10c2e2a55ce303f82801b3179279f3 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 27 Jun 2025 20:36:08 +0000 Subject: [PATCH 1/3] Initial plan From e904f8a02972805f848e6f1b5f21699c8cfb42d6 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 27 Jun 2025 20:46:21 +0000 Subject: [PATCH 2/3] Fix TypeScript to JavaScript mapping in CodeQL analysis Co-authored-by: felickz <1760475+felickz@users.noreply.github.com> --- src/services/codeqlService.ts | 4 ++ test_comprehensive_fix.js | 124 ++++++++++++++++++++++++++++++++++ test_fix_verification.js | 89 ++++++++++++++++++++++++ test_issue_scenario.js | 73 ++++++++++++++++++++ test_language_mapping.js | 32 +++++++++ test_mapping_logic.js | 67 ++++++++++++++++++ 6 files changed, 389 insertions(+) create mode 100644 test_comprehensive_fix.js create mode 100644 test_fix_verification.js create mode 100644 test_issue_scenario.js create mode 100644 test_language_mapping.js create mode 100644 test_mapping_logic.js diff --git a/src/services/codeqlService.ts b/src/services/codeqlService.ts index f34edb3..f4a3a36 100644 --- a/src/services/codeqlService.ts +++ b/src/services/codeqlService.ts @@ -136,6 +136,10 @@ export class CodeQLService { ); } + // Ensure languages are always mapped to CodeQL languages, even if manually configured + // This prevents issues where users might manually configure "typescript" instead of "javascript" + languages = this.mapLanguagesToCodeQL(languages); + this.logger.info( "CodeQLService", `Detected languages: [${languages.join(", ")}]` diff --git a/test_comprehensive_fix.js b/test_comprehensive_fix.js new file mode 100644 index 0000000..9ff7a39 --- /dev/null +++ b/test_comprehensive_fix.js @@ -0,0 +1,124 @@ +// Comprehensive test for the TypeScript to JavaScript mapping fix +// This test simulates the full flow from language detection to query pack resolution + +const languages = { + javascript: ["javascript", "typescript", "js", "ts", "jsx", "tsx"], + python: ["python", "py"], + java: ["java"], + csharp: ["csharp", "c#", "cs"], + cpp: ["cpp", "c++", "c", "cc", "cxx"], + go: ["go", "golang"], + ruby: ["ruby", "rb"], + swift: ["swift"], + kotlin: ["kotlin", "kt"], + scala: ["scala"], +}; + +function mapLanguagesToCodeQL(inputLanguages) { + const results = []; + const addedLanguages = new Set(); + + for (const language of inputLanguages) { + const lang = language.toLowerCase(); + + // Direct match with CodeQL language + if (languages[lang] && !addedLanguages.has(lang)) { + results.push(lang); + addedLanguages.add(lang); + continue; + } + + // Check if it's an alias for a CodeQL language + for (const [codeqlLang, aliases] of Object.entries(languages)) { + if (aliases.includes(lang) && !addedLanguages.has(codeqlLang)) { + results.push(codeqlLang); + addedLanguages.add(codeqlLang); + break; + } + } + } + + return [...new Set(results)]; // Remove any duplicates just in case +} + +// Simulate runLocalScan logic with the fix +function simulateRunLocalScan(configuredLanguages, githubLanguages) { + console.log('\n--- Simulating runLocalScan ---'); + console.log('Configured languages:', configuredLanguages); + console.log('GitHub languages:', githubLanguages); + + // Simulate the original logic + let languages = configuredLanguages || []; + if (!languages || languages.length === 0) { + languages = mapLanguagesToCodeQL(githubLanguages); + console.log('Languages after GitHub mapping:', languages); + } + + // Apply the fix: ensure languages are always mapped + languages = mapLanguagesToCodeQL(languages); + console.log('Final languages after fix:', languages); + + // Simulate the processing loop + for (const language of languages) { + console.log(`Processing language: ${language}`); + + // Simulate database path generation + const databasePath = `/path/to/databases/repo/${language}`; + console.log(` Database path: ${databasePath}`); + + // Simulate output path generation + const outputPath = `/path/to/results/repo-${language}-abcd1234.sarif`; + console.log(` Output path: ${outputPath}`); + + // Simulate query pack resolution + const queryPack = `codeql/${language}-queries`; + console.log(` Query pack: ${queryPack}`); + + // Simulate suite path + const suitePath = `${queryPack}:codeql-suites/${language}-code-scanning.qls`; + console.log(` Suite path: ${suitePath}`); + } + + return languages; +} + +console.log('=== Comprehensive Test for TypeScript to JavaScript Mapping Fix ==='); + +// Test case 1: The original problematic scenario +console.log('\nšŸ” Test Case 1: Original problematic scenario (auto-detection with TypeScript)'); +const result1 = simulateRunLocalScan([], ["TypeScript"]); +console.log('āœ… Expected: javascript-based paths'); +console.log('āœ… Result:', result1.includes('javascript') && !result1.includes('typescript') ? 'PASS' : 'FAIL'); + +// Test case 2: Mixed languages from GitHub +console.log('\nšŸ” Test Case 2: Mixed GitHub languages'); +const result2 = simulateRunLocalScan([], ["TypeScript", "Python", "JavaScript"]); +console.log('āœ… Expected: javascript and python'); +console.log('āœ… Result:', JSON.stringify(result2.sort()) === '["javascript","python"]' ? 'PASS' : 'FAIL'); + +// Test case 3: Manual configuration with typescript (edge case) +console.log('\nšŸ” Test Case 3: Manual typescript configuration'); +const result3 = simulateRunLocalScan(["typescript"], []); +console.log('āœ… Expected: javascript'); +console.log('āœ… Result:', JSON.stringify(result3) === '["javascript"]' ? 'PASS' : 'FAIL'); + +// Test case 4: Manual configuration with javascript (should still work) +console.log('\nšŸ” Test Case 4: Manual javascript configuration'); +const result4 = simulateRunLocalScan(["javascript"], []); +console.log('āœ… Expected: javascript'); +console.log('āœ… Result:', JSON.stringify(result4) === '["javascript"]' ? 'PASS' : 'FAIL'); + +// Test case 5: Mixed manual configuration +console.log('\nšŸ” Test Case 5: Mixed manual configuration'); +const result5 = simulateRunLocalScan(["typescript", "python", "javascript"], []); +console.log('āœ… Expected: javascript and python'); +console.log('āœ… Result:', JSON.stringify(result5.sort()) === '["javascript","python"]' ? 'PASS' : 'FAIL'); + +console.log('\nšŸ“‹ Summary:'); +console.log('- Fix ensures TypeScript always maps to JavaScript'); +console.log('- Database paths use correct language (javascript)'); +console.log('- Output files use correct language (javascript)'); +console.log('- Query packs use correct language (javascript-queries)'); +console.log('- Suite paths use correct language (javascript-code-scanning.qls)'); +console.log('- Fix works for both auto-detection and manual configuration'); +console.log('- Prevents the "codeql/typescript-queries" error'); \ No newline at end of file diff --git a/test_fix_verification.js b/test_fix_verification.js new file mode 100644 index 0000000..24a6380 --- /dev/null +++ b/test_fix_verification.js @@ -0,0 +1,89 @@ +// Test to verify the fix for the TypeScript to JavaScript mapping issue +const languages = { + javascript: ["javascript", "typescript", "js", "ts", "jsx", "tsx"], + python: ["python", "py"], + java: ["java"], + csharp: ["csharp", "c#", "cs"], + cpp: ["cpp", "c++", "c", "cc", "cxx"], + go: ["go", "golang"], + ruby: ["ruby", "rb"], + swift: ["swift"], + kotlin: ["kotlin", "kt"], + scala: ["scala"], +}; + +function mapLanguagesToCodeQL(inputLanguages) { + const results = []; + const addedLanguages = new Set(); + + for (const language of inputLanguages) { + const lang = language.toLowerCase(); + + // Direct match with CodeQL language + if (languages[lang] && !addedLanguages.has(lang)) { + results.push(lang); + addedLanguages.add(lang); + continue; + } + + // Check if it's an alias for a CodeQL language + for (const [codeqlLang, aliases] of Object.entries(languages)) { + if (aliases.includes(lang) && !addedLanguages.has(codeqlLang)) { + results.push(codeqlLang); + addedLanguages.add(codeqlLang); + break; + } + } + } + + return [...new Set(results)]; // Remove any duplicates just in case +} + +// Simulate the problematic scenarios and test the fix +console.log('Testing fix for TypeScript to JavaScript mapping issue...'); + +// Test case 1: Languages from GitHub detection (auto-detection) +console.log('\n1. Testing auto-detection scenario:'); +const githubDetected = ["TypeScript", "JavaScript"]; +let mappedFromGithub = mapLanguagesToCodeQL(githubDetected); +console.log('GitHub detected:', githubDetected); +console.log('First mapping:', mappedFromGithub); + +// Apply the fix: ensure languages are always mapped even if already in config +let finalLanguages = mapLanguagesToCodeQL(mappedFromGithub); +console.log('Final languages after fix:', finalLanguages); +console.log('Expected: ["javascript"]'); +console.log('Pass:', JSON.stringify(finalLanguages) === '["javascript"]'); + +// Test case 2: User manually configured "typescript" in settings +console.log('\n2. Testing manual configuration with typescript:'); +const manuallyConfigured = ["typescript"]; +let mappedManual = mapLanguagesToCodeQL(manuallyConfigured); +console.log('Manually configured:', manuallyConfigured); +console.log('Mapped result:', mappedManual); +console.log('Expected: ["javascript"]'); +console.log('Pass:', JSON.stringify(mappedManual) === '["javascript"]'); + +// Test case 3: Mixed configuration with both javascript and typescript +console.log('\n3. Testing mixed configuration:'); +const mixedConfig = ["javascript", "typescript", "python"]; +let mappedMixed = mapLanguagesToCodeQL(mixedConfig); +console.log('Mixed configuration:', mixedConfig); +console.log('Mapped result:', mappedMixed); +console.log('Expected: ["javascript", "python"]'); +console.log('Pass:', JSON.stringify(mappedMixed) === '["javascript","python"]'); + +// Test case 4: Edge case - typescript only (simulating the problematic scenario) +console.log('\n4. Testing TypeScript-only scenario:'); +const typescriptOnly = ["TypeScript"]; +let mappedTSOnly = mapLanguagesToCodeQL(typescriptOnly); +console.log('TypeScript only:', typescriptOnly); +console.log('Mapped result:', mappedTSOnly); +console.log('Expected: ["javascript"]'); +console.log('Pass:', JSON.stringify(mappedTSOnly) === '["javascript"]'); + +console.log('\nAll tests completed. The fix ensures that:'); +console.log('- TypeScript always maps to JavaScript for CodeQL analysis'); +console.log('- Both auto-detected and manually configured languages are properly mapped'); +console.log('- Duplicate languages are handled correctly'); +console.log('- The fix prevents the "typescript-queries" error'); \ No newline at end of file diff --git a/test_issue_scenario.js b/test_issue_scenario.js new file mode 100644 index 0000000..9901391 --- /dev/null +++ b/test_issue_scenario.js @@ -0,0 +1,73 @@ +// Test to reproduce the language mapping issue +// This simulates the flow in runLocalScan() + +const languages = { + javascript: ["javascript", "typescript", "js", "ts", "jsx", "tsx"], + python: ["python", "py"], + java: ["java"], + csharp: ["csharp", "c#", "cs"], + cpp: ["cpp", "c++", "c", "cc", "cxx"], + go: ["go", "golang"], + ruby: ["ruby", "rb"], + swift: ["swift"], + kotlin: ["kotlin", "kt"], + scala: ["scala"], +}; + +function mapLanguagesToCodeQL(inputLanguages) { + const results = []; + const addedLanguages = new Set(); + + for (const language of inputLanguages) { + const lang = language.toLowerCase(); + + // Direct match with CodeQL language + if (languages[lang] && !addedLanguages.has(lang)) { + results.push(lang); + addedLanguages.add(lang); + continue; + } + + // Check if it's an alias for a CodeQL language + for (const [codeqlLang, aliases] of Object.entries(languages)) { + if (aliases.includes(lang) && !addedLanguages.has(codeqlLang)) { + results.push(codeqlLang); + addedLanguages.add(codeqlLang); + break; + } + } + } + + return [...new Set(results)]; // Remove any duplicates just in case +} + +// Simulate the problematic scenario +console.log('Simulating the issue scenario...'); + +// Simulate GitHub API returning TypeScript as a language +const githubLanguages = ["TypeScript", "JavaScript"]; +console.log('GitHub languages detected:', githubLanguages); + +// Simulate the mapping that should happen +const mappedLanguages = mapLanguagesToCodeQL(githubLanguages); +console.log('Mapped languages:', mappedLanguages); + +// Expected result: should be ["javascript"] (only one entry since both TypeScript and JavaScript map to javascript) +console.log('Expected: ["javascript"]'); +console.log('Test passes:', JSON.stringify(mappedLanguages) === '["javascript"]'); + +// Check if there's an issue with duplicate handling +console.log('\nTesting duplicate handling...'); +const testDuplicates = mapLanguagesToCodeQL(["javascript", "typescript", "js", "ts"]); +console.log('Input: ["javascript", "typescript", "js", "ts"]'); +console.log('Output:', testDuplicates); +console.log('Expected: ["javascript"]'); +console.log('Test passes:', JSON.stringify(testDuplicates) === '["javascript"]'); + +// Test with only TypeScript +console.log('\nTesting TypeScript only...'); +const testTypescriptOnly = mapLanguagesToCodeQL(["TypeScript"]); +console.log('Input: ["TypeScript"]'); +console.log('Output:', testTypescriptOnly); +console.log('Expected: ["javascript"]'); +console.log('Test passes:', JSON.stringify(testTypescriptOnly) === '["javascript"]'); \ No newline at end of file diff --git a/test_language_mapping.js b/test_language_mapping.js new file mode 100644 index 0000000..620a82d --- /dev/null +++ b/test_language_mapping.js @@ -0,0 +1,32 @@ +// Test script to verify language mapping behavior +const { CodeQLService } = require('./out/services/codeqlService'); + +// Mock GitHub service for testing +const mockGitHubService = { + getRepositoryInfo: () => Promise.resolve({ owner: 'test', repo: 'test' }) +}; + +// Create CodeQL service instance +const codeqlService = new CodeQLService(mockGitHubService); + +// Test cases to verify the mapping +console.log('Testing language mapping...'); + +// Test 1: TypeScript should map to JavaScript +const typescriptLanguages = ['typescript', 'ts']; +const mappedTS = codeqlService.mapLanguagesToCodeQL(typescriptLanguages); +console.log('TypeScript languages:', typescriptLanguages, '-> Mapped to:', mappedTS); + +// Test 2: Mixed languages including TypeScript +const mixedLanguages = ['javascript', 'typescript', 'python', 'java']; +const mappedMixed = codeqlService.mapLanguagesToCodeQL(mixedLanguages); +console.log('Mixed languages:', mixedLanguages, '-> Mapped to:', mappedMixed); + +// Test 3: Direct JavaScript should still work +const jsLanguages = ['javascript', 'js']; +const mappedJS = codeqlService.mapLanguagesToCodeQL(jsLanguages); +console.log('JavaScript languages:', jsLanguages, '-> Mapped to:', mappedJS); + +// Test 4: Check all supported languages +const supportedLanguages = codeqlService.getLanguages(); +console.log('All supported CodeQL languages:', supportedLanguages); \ No newline at end of file diff --git a/test_mapping_logic.js b/test_mapping_logic.js new file mode 100644 index 0000000..b9a5e92 --- /dev/null +++ b/test_mapping_logic.js @@ -0,0 +1,67 @@ +// Simple test of the mapping logic without dependencies +const languages = { + javascript: ["javascript", "typescript", "js", "ts", "jsx", "tsx"], + python: ["python", "py"], + java: ["java"], + csharp: ["csharp", "c#", "cs"], + cpp: ["cpp", "c++", "c", "cc", "cxx"], + go: ["go", "golang"], + ruby: ["ruby", "rb"], + swift: ["swift"], + kotlin: ["kotlin", "kt"], + scala: ["scala"], +}; + +function mapLanguagesToCodeQL(inputLanguages) { + const results = []; + const addedLanguages = new Set(); + + for (const language of inputLanguages) { + const lang = language.toLowerCase(); + + // Direct match with CodeQL language + if (languages[lang] && !addedLanguages.has(lang)) { + results.push(lang); + addedLanguages.add(lang); + continue; + } + + // Check if it's an alias for a CodeQL language + for (const [codeqlLang, aliases] of Object.entries(languages)) { + if (aliases.includes(lang) && !addedLanguages.has(codeqlLang)) { + results.push(codeqlLang); + addedLanguages.add(codeqlLang); + break; + } + } + } + + return [...new Set(results)]; // Remove any duplicates just in case +} + +// Test the mapping logic +console.log('Testing language mapping logic...'); + +console.log('Test 1 - TypeScript should map to JavaScript:'); +const test1 = mapLanguagesToCodeQL(['TypeScript']); +console.log('Input: ["TypeScript"] -> Output:', test1); +console.log('Expected: ["javascript"], Actual:', test1); +console.log('Pass:', JSON.stringify(test1) === '["javascript"]'); + +console.log('\nTest 2 - typescript (lowercase) should map to JavaScript:'); +const test2 = mapLanguagesToCodeQL(['typescript']); +console.log('Input: ["typescript"] -> Output:', test2); +console.log('Expected: ["javascript"], Actual:', test2); +console.log('Pass:', JSON.stringify(test2) === '["javascript"]'); + +console.log('\nTest 3 - Mixed languages with TypeScript:'); +const test3 = mapLanguagesToCodeQL(['JavaScript', 'TypeScript', 'Python']); +console.log('Input: ["JavaScript", "TypeScript", "Python"] -> Output:', test3); +console.log('Expected: ["javascript", "python"], Actual:', test3); +console.log('Pass:', JSON.stringify(test3) === '["javascript","python"]'); + +console.log('\nTest 4 - ts extension should map to JavaScript:'); +const test4 = mapLanguagesToCodeQL(['ts']); +console.log('Input: ["ts"] -> Output:', test4); +console.log('Expected: ["javascript"], Actual:', test4); +console.log('Pass:', JSON.stringify(test4) === '["javascript"]'); \ No newline at end of file From 79ca3f92add58b0f8f114f720e33ae9da4b4fda9 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 27 Jun 2025 20:47:54 +0000 Subject: [PATCH 3/3] Clean up temporary test files and add gitignore rules Co-authored-by: felickz <1760475+felickz@users.noreply.github.com> --- .gitignore | 3 + test_comprehensive_fix.js | 124 -------------------------------------- test_fix_verification.js | 89 --------------------------- test_issue_scenario.js | 73 ---------------------- test_language_mapping.js | 32 ---------- test_mapping_logic.js | 67 -------------------- 6 files changed, 3 insertions(+), 385 deletions(-) delete mode 100644 test_comprehensive_fix.js delete mode 100644 test_fix_verification.js delete mode 100644 test_issue_scenario.js delete mode 100644 test_language_mapping.js delete mode 100644 test_mapping_logic.js diff --git a/.gitignore b/.gitignore index 7517ac8..f57b8c7 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,6 @@ node_modules .vscode-test *.vsix .DS_Store + +# Temporary test files +test_*.js diff --git a/test_comprehensive_fix.js b/test_comprehensive_fix.js deleted file mode 100644 index 9ff7a39..0000000 --- a/test_comprehensive_fix.js +++ /dev/null @@ -1,124 +0,0 @@ -// Comprehensive test for the TypeScript to JavaScript mapping fix -// This test simulates the full flow from language detection to query pack resolution - -const languages = { - javascript: ["javascript", "typescript", "js", "ts", "jsx", "tsx"], - python: ["python", "py"], - java: ["java"], - csharp: ["csharp", "c#", "cs"], - cpp: ["cpp", "c++", "c", "cc", "cxx"], - go: ["go", "golang"], - ruby: ["ruby", "rb"], - swift: ["swift"], - kotlin: ["kotlin", "kt"], - scala: ["scala"], -}; - -function mapLanguagesToCodeQL(inputLanguages) { - const results = []; - const addedLanguages = new Set(); - - for (const language of inputLanguages) { - const lang = language.toLowerCase(); - - // Direct match with CodeQL language - if (languages[lang] && !addedLanguages.has(lang)) { - results.push(lang); - addedLanguages.add(lang); - continue; - } - - // Check if it's an alias for a CodeQL language - for (const [codeqlLang, aliases] of Object.entries(languages)) { - if (aliases.includes(lang) && !addedLanguages.has(codeqlLang)) { - results.push(codeqlLang); - addedLanguages.add(codeqlLang); - break; - } - } - } - - return [...new Set(results)]; // Remove any duplicates just in case -} - -// Simulate runLocalScan logic with the fix -function simulateRunLocalScan(configuredLanguages, githubLanguages) { - console.log('\n--- Simulating runLocalScan ---'); - console.log('Configured languages:', configuredLanguages); - console.log('GitHub languages:', githubLanguages); - - // Simulate the original logic - let languages = configuredLanguages || []; - if (!languages || languages.length === 0) { - languages = mapLanguagesToCodeQL(githubLanguages); - console.log('Languages after GitHub mapping:', languages); - } - - // Apply the fix: ensure languages are always mapped - languages = mapLanguagesToCodeQL(languages); - console.log('Final languages after fix:', languages); - - // Simulate the processing loop - for (const language of languages) { - console.log(`Processing language: ${language}`); - - // Simulate database path generation - const databasePath = `/path/to/databases/repo/${language}`; - console.log(` Database path: ${databasePath}`); - - // Simulate output path generation - const outputPath = `/path/to/results/repo-${language}-abcd1234.sarif`; - console.log(` Output path: ${outputPath}`); - - // Simulate query pack resolution - const queryPack = `codeql/${language}-queries`; - console.log(` Query pack: ${queryPack}`); - - // Simulate suite path - const suitePath = `${queryPack}:codeql-suites/${language}-code-scanning.qls`; - console.log(` Suite path: ${suitePath}`); - } - - return languages; -} - -console.log('=== Comprehensive Test for TypeScript to JavaScript Mapping Fix ==='); - -// Test case 1: The original problematic scenario -console.log('\nšŸ” Test Case 1: Original problematic scenario (auto-detection with TypeScript)'); -const result1 = simulateRunLocalScan([], ["TypeScript"]); -console.log('āœ… Expected: javascript-based paths'); -console.log('āœ… Result:', result1.includes('javascript') && !result1.includes('typescript') ? 'PASS' : 'FAIL'); - -// Test case 2: Mixed languages from GitHub -console.log('\nšŸ” Test Case 2: Mixed GitHub languages'); -const result2 = simulateRunLocalScan([], ["TypeScript", "Python", "JavaScript"]); -console.log('āœ… Expected: javascript and python'); -console.log('āœ… Result:', JSON.stringify(result2.sort()) === '["javascript","python"]' ? 'PASS' : 'FAIL'); - -// Test case 3: Manual configuration with typescript (edge case) -console.log('\nšŸ” Test Case 3: Manual typescript configuration'); -const result3 = simulateRunLocalScan(["typescript"], []); -console.log('āœ… Expected: javascript'); -console.log('āœ… Result:', JSON.stringify(result3) === '["javascript"]' ? 'PASS' : 'FAIL'); - -// Test case 4: Manual configuration with javascript (should still work) -console.log('\nšŸ” Test Case 4: Manual javascript configuration'); -const result4 = simulateRunLocalScan(["javascript"], []); -console.log('āœ… Expected: javascript'); -console.log('āœ… Result:', JSON.stringify(result4) === '["javascript"]' ? 'PASS' : 'FAIL'); - -// Test case 5: Mixed manual configuration -console.log('\nšŸ” Test Case 5: Mixed manual configuration'); -const result5 = simulateRunLocalScan(["typescript", "python", "javascript"], []); -console.log('āœ… Expected: javascript and python'); -console.log('āœ… Result:', JSON.stringify(result5.sort()) === '["javascript","python"]' ? 'PASS' : 'FAIL'); - -console.log('\nšŸ“‹ Summary:'); -console.log('- Fix ensures TypeScript always maps to JavaScript'); -console.log('- Database paths use correct language (javascript)'); -console.log('- Output files use correct language (javascript)'); -console.log('- Query packs use correct language (javascript-queries)'); -console.log('- Suite paths use correct language (javascript-code-scanning.qls)'); -console.log('- Fix works for both auto-detection and manual configuration'); -console.log('- Prevents the "codeql/typescript-queries" error'); \ No newline at end of file diff --git a/test_fix_verification.js b/test_fix_verification.js deleted file mode 100644 index 24a6380..0000000 --- a/test_fix_verification.js +++ /dev/null @@ -1,89 +0,0 @@ -// Test to verify the fix for the TypeScript to JavaScript mapping issue -const languages = { - javascript: ["javascript", "typescript", "js", "ts", "jsx", "tsx"], - python: ["python", "py"], - java: ["java"], - csharp: ["csharp", "c#", "cs"], - cpp: ["cpp", "c++", "c", "cc", "cxx"], - go: ["go", "golang"], - ruby: ["ruby", "rb"], - swift: ["swift"], - kotlin: ["kotlin", "kt"], - scala: ["scala"], -}; - -function mapLanguagesToCodeQL(inputLanguages) { - const results = []; - const addedLanguages = new Set(); - - for (const language of inputLanguages) { - const lang = language.toLowerCase(); - - // Direct match with CodeQL language - if (languages[lang] && !addedLanguages.has(lang)) { - results.push(lang); - addedLanguages.add(lang); - continue; - } - - // Check if it's an alias for a CodeQL language - for (const [codeqlLang, aliases] of Object.entries(languages)) { - if (aliases.includes(lang) && !addedLanguages.has(codeqlLang)) { - results.push(codeqlLang); - addedLanguages.add(codeqlLang); - break; - } - } - } - - return [...new Set(results)]; // Remove any duplicates just in case -} - -// Simulate the problematic scenarios and test the fix -console.log('Testing fix for TypeScript to JavaScript mapping issue...'); - -// Test case 1: Languages from GitHub detection (auto-detection) -console.log('\n1. Testing auto-detection scenario:'); -const githubDetected = ["TypeScript", "JavaScript"]; -let mappedFromGithub = mapLanguagesToCodeQL(githubDetected); -console.log('GitHub detected:', githubDetected); -console.log('First mapping:', mappedFromGithub); - -// Apply the fix: ensure languages are always mapped even if already in config -let finalLanguages = mapLanguagesToCodeQL(mappedFromGithub); -console.log('Final languages after fix:', finalLanguages); -console.log('Expected: ["javascript"]'); -console.log('Pass:', JSON.stringify(finalLanguages) === '["javascript"]'); - -// Test case 2: User manually configured "typescript" in settings -console.log('\n2. Testing manual configuration with typescript:'); -const manuallyConfigured = ["typescript"]; -let mappedManual = mapLanguagesToCodeQL(manuallyConfigured); -console.log('Manually configured:', manuallyConfigured); -console.log('Mapped result:', mappedManual); -console.log('Expected: ["javascript"]'); -console.log('Pass:', JSON.stringify(mappedManual) === '["javascript"]'); - -// Test case 3: Mixed configuration with both javascript and typescript -console.log('\n3. Testing mixed configuration:'); -const mixedConfig = ["javascript", "typescript", "python"]; -let mappedMixed = mapLanguagesToCodeQL(mixedConfig); -console.log('Mixed configuration:', mixedConfig); -console.log('Mapped result:', mappedMixed); -console.log('Expected: ["javascript", "python"]'); -console.log('Pass:', JSON.stringify(mappedMixed) === '["javascript","python"]'); - -// Test case 4: Edge case - typescript only (simulating the problematic scenario) -console.log('\n4. Testing TypeScript-only scenario:'); -const typescriptOnly = ["TypeScript"]; -let mappedTSOnly = mapLanguagesToCodeQL(typescriptOnly); -console.log('TypeScript only:', typescriptOnly); -console.log('Mapped result:', mappedTSOnly); -console.log('Expected: ["javascript"]'); -console.log('Pass:', JSON.stringify(mappedTSOnly) === '["javascript"]'); - -console.log('\nAll tests completed. The fix ensures that:'); -console.log('- TypeScript always maps to JavaScript for CodeQL analysis'); -console.log('- Both auto-detected and manually configured languages are properly mapped'); -console.log('- Duplicate languages are handled correctly'); -console.log('- The fix prevents the "typescript-queries" error'); \ No newline at end of file diff --git a/test_issue_scenario.js b/test_issue_scenario.js deleted file mode 100644 index 9901391..0000000 --- a/test_issue_scenario.js +++ /dev/null @@ -1,73 +0,0 @@ -// Test to reproduce the language mapping issue -// This simulates the flow in runLocalScan() - -const languages = { - javascript: ["javascript", "typescript", "js", "ts", "jsx", "tsx"], - python: ["python", "py"], - java: ["java"], - csharp: ["csharp", "c#", "cs"], - cpp: ["cpp", "c++", "c", "cc", "cxx"], - go: ["go", "golang"], - ruby: ["ruby", "rb"], - swift: ["swift"], - kotlin: ["kotlin", "kt"], - scala: ["scala"], -}; - -function mapLanguagesToCodeQL(inputLanguages) { - const results = []; - const addedLanguages = new Set(); - - for (const language of inputLanguages) { - const lang = language.toLowerCase(); - - // Direct match with CodeQL language - if (languages[lang] && !addedLanguages.has(lang)) { - results.push(lang); - addedLanguages.add(lang); - continue; - } - - // Check if it's an alias for a CodeQL language - for (const [codeqlLang, aliases] of Object.entries(languages)) { - if (aliases.includes(lang) && !addedLanguages.has(codeqlLang)) { - results.push(codeqlLang); - addedLanguages.add(codeqlLang); - break; - } - } - } - - return [...new Set(results)]; // Remove any duplicates just in case -} - -// Simulate the problematic scenario -console.log('Simulating the issue scenario...'); - -// Simulate GitHub API returning TypeScript as a language -const githubLanguages = ["TypeScript", "JavaScript"]; -console.log('GitHub languages detected:', githubLanguages); - -// Simulate the mapping that should happen -const mappedLanguages = mapLanguagesToCodeQL(githubLanguages); -console.log('Mapped languages:', mappedLanguages); - -// Expected result: should be ["javascript"] (only one entry since both TypeScript and JavaScript map to javascript) -console.log('Expected: ["javascript"]'); -console.log('Test passes:', JSON.stringify(mappedLanguages) === '["javascript"]'); - -// Check if there's an issue with duplicate handling -console.log('\nTesting duplicate handling...'); -const testDuplicates = mapLanguagesToCodeQL(["javascript", "typescript", "js", "ts"]); -console.log('Input: ["javascript", "typescript", "js", "ts"]'); -console.log('Output:', testDuplicates); -console.log('Expected: ["javascript"]'); -console.log('Test passes:', JSON.stringify(testDuplicates) === '["javascript"]'); - -// Test with only TypeScript -console.log('\nTesting TypeScript only...'); -const testTypescriptOnly = mapLanguagesToCodeQL(["TypeScript"]); -console.log('Input: ["TypeScript"]'); -console.log('Output:', testTypescriptOnly); -console.log('Expected: ["javascript"]'); -console.log('Test passes:', JSON.stringify(testTypescriptOnly) === '["javascript"]'); \ No newline at end of file diff --git a/test_language_mapping.js b/test_language_mapping.js deleted file mode 100644 index 620a82d..0000000 --- a/test_language_mapping.js +++ /dev/null @@ -1,32 +0,0 @@ -// Test script to verify language mapping behavior -const { CodeQLService } = require('./out/services/codeqlService'); - -// Mock GitHub service for testing -const mockGitHubService = { - getRepositoryInfo: () => Promise.resolve({ owner: 'test', repo: 'test' }) -}; - -// Create CodeQL service instance -const codeqlService = new CodeQLService(mockGitHubService); - -// Test cases to verify the mapping -console.log('Testing language mapping...'); - -// Test 1: TypeScript should map to JavaScript -const typescriptLanguages = ['typescript', 'ts']; -const mappedTS = codeqlService.mapLanguagesToCodeQL(typescriptLanguages); -console.log('TypeScript languages:', typescriptLanguages, '-> Mapped to:', mappedTS); - -// Test 2: Mixed languages including TypeScript -const mixedLanguages = ['javascript', 'typescript', 'python', 'java']; -const mappedMixed = codeqlService.mapLanguagesToCodeQL(mixedLanguages); -console.log('Mixed languages:', mixedLanguages, '-> Mapped to:', mappedMixed); - -// Test 3: Direct JavaScript should still work -const jsLanguages = ['javascript', 'js']; -const mappedJS = codeqlService.mapLanguagesToCodeQL(jsLanguages); -console.log('JavaScript languages:', jsLanguages, '-> Mapped to:', mappedJS); - -// Test 4: Check all supported languages -const supportedLanguages = codeqlService.getLanguages(); -console.log('All supported CodeQL languages:', supportedLanguages); \ No newline at end of file diff --git a/test_mapping_logic.js b/test_mapping_logic.js deleted file mode 100644 index b9a5e92..0000000 --- a/test_mapping_logic.js +++ /dev/null @@ -1,67 +0,0 @@ -// Simple test of the mapping logic without dependencies -const languages = { - javascript: ["javascript", "typescript", "js", "ts", "jsx", "tsx"], - python: ["python", "py"], - java: ["java"], - csharp: ["csharp", "c#", "cs"], - cpp: ["cpp", "c++", "c", "cc", "cxx"], - go: ["go", "golang"], - ruby: ["ruby", "rb"], - swift: ["swift"], - kotlin: ["kotlin", "kt"], - scala: ["scala"], -}; - -function mapLanguagesToCodeQL(inputLanguages) { - const results = []; - const addedLanguages = new Set(); - - for (const language of inputLanguages) { - const lang = language.toLowerCase(); - - // Direct match with CodeQL language - if (languages[lang] && !addedLanguages.has(lang)) { - results.push(lang); - addedLanguages.add(lang); - continue; - } - - // Check if it's an alias for a CodeQL language - for (const [codeqlLang, aliases] of Object.entries(languages)) { - if (aliases.includes(lang) && !addedLanguages.has(codeqlLang)) { - results.push(codeqlLang); - addedLanguages.add(codeqlLang); - break; - } - } - } - - return [...new Set(results)]; // Remove any duplicates just in case -} - -// Test the mapping logic -console.log('Testing language mapping logic...'); - -console.log('Test 1 - TypeScript should map to JavaScript:'); -const test1 = mapLanguagesToCodeQL(['TypeScript']); -console.log('Input: ["TypeScript"] -> Output:', test1); -console.log('Expected: ["javascript"], Actual:', test1); -console.log('Pass:', JSON.stringify(test1) === '["javascript"]'); - -console.log('\nTest 2 - typescript (lowercase) should map to JavaScript:'); -const test2 = mapLanguagesToCodeQL(['typescript']); -console.log('Input: ["typescript"] -> Output:', test2); -console.log('Expected: ["javascript"], Actual:', test2); -console.log('Pass:', JSON.stringify(test2) === '["javascript"]'); - -console.log('\nTest 3 - Mixed languages with TypeScript:'); -const test3 = mapLanguagesToCodeQL(['JavaScript', 'TypeScript', 'Python']); -console.log('Input: ["JavaScript", "TypeScript", "Python"] -> Output:', test3); -console.log('Expected: ["javascript", "python"], Actual:', test3); -console.log('Pass:', JSON.stringify(test3) === '["javascript","python"]'); - -console.log('\nTest 4 - ts extension should map to JavaScript:'); -const test4 = mapLanguagesToCodeQL(['ts']); -console.log('Input: ["ts"] -> Output:', test4); -console.log('Expected: ["javascript"], Actual:', test4); -console.log('Pass:', JSON.stringify(test4) === '["javascript"]'); \ No newline at end of file