Resolve ml-queries from directory

Previously, there was a bug where quick eval queries would crash when
the eval snippet is in a library file.

The problem was that the `codeql resolve queries` command fails when
passed a library file. The fix is to avoid passing the library file at
all. Instead, pass the directory. This is safe because the resolve
queries command only needs to know which query pack the file is
contained in. Passing in the parent directory is the same as passing in
a file in this particular case.
This commit is contained in:
Andrew Eisenberg
2022-06-30 08:36:55 -07:00
parent ebad1844df
commit 70f74d3baf
2 changed files with 3 additions and 4 deletions

View File

@@ -606,7 +606,8 @@ export class CodeQLCliServer implements Disposable {
/** Resolves the ML models that should be available when evaluating a query. */
async resolveMlModels(additionalPacks: string[], queryPath: string): Promise<MlModelsInfo> {
const args = await this.cliConstraints.supportsPreciseResolveMlModels()
? [...this.getAdditionalPacksArg(additionalPacks), queryPath]
// use the dirname of the path so that we can handle query libraries
? [...this.getAdditionalPacksArg(additionalPacks), path.dirname(queryPath)]
: this.getAdditionalPacksArg(additionalPacks);
return await this.runJsonCodeQlCliCommand<MlModelsInfo>(
['resolve', 'ml-models'],

View File

@@ -789,9 +789,7 @@ export async function compileAndRunQueryAgainstDatabase(
const metadata = await tryGetQueryMetadata(cliServer, qlProgram.queryPath);
let availableMlModels: cli.MlModelInfo[] = [];
if (!initialInfo.queryPath.endsWith('.ql')) {
void logger.log('Quick evaluation within a query library does not currently support using ML models. Continuing without any ML models.');
} else if (!await cliServer.cliConstraints.supportsResolveMlModels()) {
if (!await cliServer.cliConstraints.supportsResolveMlModels()) {
void logger.log('Resolving ML models is unsupported by this version of the CLI. Running the query without any ML models.');
} else {
try {