Skip to content

Commit 54f30be

Browse files
committed
Implement changes for PR review comments
1 parent 70e7021 commit 54f30be

File tree

4 files changed

+48
-28
lines changed

4 files changed

+48
-28
lines changed

extensions/vscode/test/codeql/cli-resolver.test.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, it, expect, vi, beforeEach } from 'vitest';
1+
import { afterEach, describe, it, expect, vi, beforeEach } from 'vitest';
22
import { CliResolver } from '../../src/codeql/cli-resolver';
33

44
// Mock child_process
@@ -171,8 +171,10 @@ describe('CliResolver', () => {
171171
const storagePath = '/mock/globalStorage/github.vscode-codeql';
172172
const binaryName = process.platform === 'win32' ? 'codeql.exe' : 'codeql';
173173

174+
let originalEnv: string | undefined;
175+
174176
beforeEach(() => {
175-
const originalEnv = process.env.CODEQL_PATH;
177+
originalEnv = process.env.CODEQL_PATH;
176178
delete process.env.CODEQL_PATH;
177179

178180
// Make `which codeql` fail
@@ -190,14 +192,14 @@ describe('CliResolver', () => {
190192

191193
// All known filesystem locations fail
192194
vi.mocked(access).mockRejectedValue(new Error('ENOENT'));
195+
});
193196

194-
return () => {
195-
if (originalEnv === undefined) {
196-
delete process.env.CODEQL_PATH;
197-
} else {
198-
process.env.CODEQL_PATH = originalEnv;
199-
}
200-
};
197+
afterEach(() => {
198+
if (originalEnv === undefined) {
199+
delete process.env.CODEQL_PATH;
200+
} else {
201+
process.env.CODEQL_PATH = originalEnv;
202+
}
201203
});
202204

203205
it('should resolve from distribution.json hint', async () => {

server/dist/codeql-development-mcp-server.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38212,12 +38212,14 @@ function getVsCodeGlobalStorageCandidates() {
3821238212
function discoverVsCodeCodeQLDistribution() {
3821338213
const globalStorageCandidates = getVsCodeGlobalStorageCandidates();
3821438214
for (const gsRoot of globalStorageCandidates) {
38215-
const codeqlStorage = join4(gsRoot, "github.vscode-codeql");
38216-
if (!existsSync2(codeqlStorage)) continue;
38217-
const hintResult = discoverFromDistributionJson(codeqlStorage);
38218-
if (hintResult) return hintResult;
38219-
const scanResult = discoverFromDistributionScan(codeqlStorage);
38220-
if (scanResult) return scanResult;
38215+
for (const dirName of VSCODE_CODEQL_STORAGE_DIR_NAMES) {
38216+
const codeqlStorage = join4(gsRoot, dirName);
38217+
if (!existsSync2(codeqlStorage)) continue;
38218+
const hintResult = discoverFromDistributionJson(codeqlStorage);
38219+
if (hintResult) return hintResult;
38220+
const scanResult = discoverFromDistributionScan(codeqlStorage);
38221+
if (scanResult) return scanResult;
38222+
}
3822138223
}
3822238224
return void 0;
3822338225
}
@@ -38524,7 +38526,7 @@ async function validateCommandExists(command) {
3852438526
return false;
3852538527
}
3852638528
}
38527-
var execFileAsync, ALLOWED_COMMANDS, testCommands, SAFE_ENV_VARS, SAFE_ENV_PREFIXES, DANGEROUS_CONTROL_CHARS, resolvedCodeQLDir, resolvedBinaryResult, CODEQL_BINARY_NAME, VSCODE_APP_NAMES, FRESH_PROCESS_SUBCOMMANDS;
38529+
var execFileAsync, ALLOWED_COMMANDS, testCommands, SAFE_ENV_VARS, SAFE_ENV_PREFIXES, DANGEROUS_CONTROL_CHARS, resolvedCodeQLDir, resolvedBinaryResult, CODEQL_BINARY_NAME, VSCODE_APP_NAMES, VSCODE_CODEQL_STORAGE_DIR_NAMES, FRESH_PROCESS_SUBCOMMANDS;
3852838530
var init_cli_executor = __esm({
3852938531
"src/lib/cli-executor.ts"() {
3853038532
"use strict";
@@ -38575,6 +38577,7 @@ var init_cli_executor = __esm({
3857538577
resolvedCodeQLDir = null;
3857638578
CODEQL_BINARY_NAME = process.platform === "win32" ? "codeql.exe" : "codeql";
3857738579
VSCODE_APP_NAMES = ["Code", "Code - Insiders", "VSCodium"];
38580+
VSCODE_CODEQL_STORAGE_DIR_NAMES = ["github.vscode-codeql", "GitHub.vscode-codeql"];
3857838581
FRESH_PROCESS_SUBCOMMANDS = /* @__PURE__ */ new Set([
3857938582
"database analyze",
3858038583
"database create",

server/src/lib/cli-executor.ts

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,14 @@ const CODEQL_BINARY_NAME = process.platform === 'win32' ? 'codeql.exe' : 'codeql
128128
*/
129129
const VSCODE_APP_NAMES = ['Code', 'Code - Insiders', 'VSCodium'];
130130

131+
/**
132+
* Possible directory names for the vscode-codeql extension's global storage.
133+
* VS Code lowercases the extension ID on some platforms/versions, but the
134+
* extension's publisher casing (`GitHub`) may also appear on disk. We check
135+
* both to ensure discovery works on case-sensitive filesystems.
136+
*/
137+
const VSCODE_CODEQL_STORAGE_DIR_NAMES = ['github.vscode-codeql', 'GitHub.vscode-codeql'];
138+
131139
/**
132140
* Compute candidate VS Code global-storage root directories for the current
133141
* platform. Returns an array of absolute paths that may or may not exist.
@@ -155,7 +163,11 @@ export function getVsCodeGlobalStorageCandidates(): string[] {
155163
* extension, if present.
156164
*
157165
* The vscode-codeql extension stores its managed CLI in:
158-
* `<globalStorage>/github.vscode-codeql/distribution<N>/codeql/codeql`
166+
* `<globalStorage>/<extensionDirName>/distribution<N>/codeql/codeql`
167+
*
168+
* where `<extensionDirName>` may be `github.vscode-codeql` (lowercased by
169+
* some VS Code versions) or `GitHub.vscode-codeql` (original publisher casing).
170+
* Both casings are checked to ensure discovery works on case-sensitive filesystems.
159171
*
160172
* A `distribution.json` file in the storage root contains a `folderIndex`
161173
* property that identifies the current distribution directory. We use that
@@ -168,18 +180,21 @@ export function discoverVsCodeCodeQLDistribution(): string | undefined {
168180
const globalStorageCandidates = getVsCodeGlobalStorageCandidates();
169181

170182
for (const gsRoot of globalStorageCandidates) {
171-
// The extension ID is always lowercased on disk by VS Code
172-
const codeqlStorage = join(gsRoot, 'github.vscode-codeql');
183+
// Check both casings: VS Code may lowercase the extension ID on disk,
184+
// but the original publisher casing (GitHub.vscode-codeql) can also appear.
185+
for (const dirName of VSCODE_CODEQL_STORAGE_DIR_NAMES) {
186+
const codeqlStorage = join(gsRoot, dirName);
173187

174-
if (!existsSync(codeqlStorage)) continue;
188+
if (!existsSync(codeqlStorage)) continue;
175189

176-
// Fast path: read distribution.json for the exact folder index
177-
const hintResult = discoverFromDistributionJson(codeqlStorage);
178-
if (hintResult) return hintResult;
190+
// Fast path: read distribution.json for the exact folder index
191+
const hintResult = discoverFromDistributionJson(codeqlStorage);
192+
if (hintResult) return hintResult;
179193

180-
// Fallback: scan distribution* directories
181-
const scanResult = discoverFromDistributionScan(codeqlStorage);
182-
if (scanResult) return scanResult;
194+
// Fallback: scan distribution* directories
195+
const scanResult = discoverFromDistributionScan(codeqlStorage);
196+
if (scanResult) return scanResult;
197+
}
183198
}
184199

185200
return undefined;

server/test/src/lib/cli-executor.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import { describe, it, expect, beforeAll, afterAll, afterEach } from 'vitest';
66
import { writeFileSync, rmSync, chmodSync, mkdirSync, existsSync } from 'fs';
77
import { execFileSync } from 'child_process';
8-
import { join } from 'path';
8+
import { isAbsolute, join } from 'path';
99
import { createProjectTempDir } from '../../../src/utils/temp-dir';
1010
import {
1111
buildCodeQLArgs,
@@ -810,7 +810,7 @@ describe('getVsCodeGlobalStorageCandidates', () => {
810810
it('should return absolute paths', () => {
811811
const candidates = getVsCodeGlobalStorageCandidates();
812812
for (const candidate of candidates) {
813-
expect(candidate.startsWith('/')).toBe(true);
813+
expect(isAbsolute(candidate)).toBe(true);
814814
}
815815
});
816816

0 commit comments

Comments
 (0)