Skip to content

Commit c0e0278

Browse files
committed
Refactor server/src/**/*.ts code for maintainability
1 parent 79d3a38 commit c0e0278

8 files changed

Lines changed: 1119 additions & 1018 deletions

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

Lines changed: 546 additions & 518 deletions
Large diffs are not rendered by default.

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

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/src/lib/cli-executor.ts

Lines changed: 9 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ import { basename, delimiter, dirname, isAbsolute, join } from 'path';
88
import { homedir } from 'os';
99
import { promisify } from 'util';
1010
import { logger } from '../utils/logger';
11-
import { workspaceRootDir, packageRootDir as pkgRootDir } from '../utils/package-paths';
11+
import { setActualCodeqlVersion, warnOnVersionMismatch } from './codeql-version';
12+
13+
// Re-export version functions so existing callers don't break
14+
export { getActualCodeqlVersion, getTargetCodeqlVersion } from './codeql-version';
1215

1316
const execFileAsync = promisify(execFile);
1417

@@ -367,58 +370,13 @@ export function resetResolvedCodeQLBinary(): void {
367370
resolvedBinaryResult = undefined;
368371
}
369372

370-
/**
371-
* The actual CodeQL CLI version string (set after startup validation).
372-
* Use this for cache keys — it reflects what actually ran the query.
373-
*/
374-
let actualCodeqlVersion: string | undefined;
375-
376-
/**
377-
* The target CodeQL CLI version the MCP server was built against
378-
* (read from .codeql-version at the repo root).
379-
*/
380-
let targetCodeqlVersion: string | undefined;
381-
382-
/**
383-
* Get the actual CodeQL CLI version detected at startup.
384-
* Returns 'unknown' if not yet validated.
385-
*/
386-
export function getActualCodeqlVersion(): string {
387-
return actualCodeqlVersion ?? 'unknown';
388-
}
389-
390-
/**
391-
* Get the target CodeQL CLI version from .codeql-version.
392-
* Returns 'unknown' if the file is missing.
393-
*/
394-
export function getTargetCodeqlVersion(): string {
395-
if (targetCodeqlVersion !== undefined) return targetCodeqlVersion;
396-
try {
397-
for (const root of [workspaceRootDir, pkgRootDir]) {
398-
const versionFile = join(root, '.codeql-version');
399-
if (existsSync(versionFile)) {
400-
targetCodeqlVersion = readFileSync(versionFile, 'utf8').trim();
401-
return targetCodeqlVersion;
402-
}
403-
}
404-
} catch {
405-
// Fall through
406-
}
407-
targetCodeqlVersion = 'unknown';
408-
return targetCodeqlVersion;
409-
}
410-
411373
/**
412374
* Validate that the resolved CodeQL binary is actually callable.
413375
*
414376
* Runs `codeql version --format=terse` and verifies the process exits
415-
* successfully. This catches the case where `CODEQL_PATH` is unset and
416-
* `codeql` is not on PATH — the server would otherwise start normally
417-
* but every tool invocation would fail.
418-
*
419-
* Stores the actual version for later retrieval via getActualCodeqlVersion().
420-
* Warns (but does not fail) if the actual version differs from the target
421-
* version in .codeql-version.
377+
* successfully. Stores the actual version for later retrieval via
378+
* getActualCodeqlVersion(). Warns (but does not fail) if the actual
379+
* version differs from the target version in .codeql-version.
422380
*
423381
* @returns The version string reported by the CodeQL CLI.
424382
* @throws Error if the binary is not reachable or returns a non-zero exit code.
@@ -438,16 +396,10 @@ export async function validateCodeQLBinaryReachable(): Promise<string> {
438396
const version = stdout.trim();
439397

440398
// Store the actual CLI version for cache keys and diagnostics
441-
actualCodeqlVersion = version;
399+
setActualCodeqlVersion(version);
442400

443401
// Compare with target version and warn on mismatch
444-
const target = getTargetCodeqlVersion();
445-
if (target !== 'unknown' && version !== target && `v${version}` !== target && version !== `v${target}`) {
446-
logger.warn(
447-
`CodeQL CLI version mismatch: detected ${version}, MCP server targets ${target}. ` +
448-
`The server will continue, but query results may differ from expected behavior.`
449-
);
450-
}
402+
warnOnVersionMismatch(version);
451403

452404
return version;
453405
} catch (err: unknown) {

0 commit comments

Comments
 (0)