Skip to content

Overlay: check query packs for compatibility #2993

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

cklin
Copy link
Contributor

@cklin cklin commented Jul 25, 2025

This PR updates the init action to prevent overlay analysis (or overlay-base database construction) when one of the query packs involved does not support overlay analysis with the installed CodeQL CLI.

  • @alexet Please review the aspects concerning interaction with the CodeQL bundle
  • @mbg Please review all other aspects of the change

Merge / deployment checklist

  • Confirm this change is backwards compatible with existing workflows.
  • Confirm the readme has been updated if necessary.
  • Confirm the changelog has been updated if necessary.

@cklin cklin force-pushed the cklin/overlay-pack-check branch 4 times, most recently from 230fc32 to d0d4112 Compare July 29, 2025 18:58
@cklin cklin marked this pull request as ready for review July 29, 2025 19:20
@Copilot Copilot AI review requested due to automatic review settings July 29, 2025 19:20
@cklin cklin requested a review from a team as a code owner July 29, 2025 19:20
@cklin cklin requested review from mbg and alexet July 29, 2025 19:20
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds compatibility checking for query packs with overlay analysis in the CodeQL Action, preventing overlay analysis when query packs don't support the feature. The overlay minimum version is also updated from 2.20.5 to 2.22.2.

  • Implements pack compatibility checking that validates overlay version requirements
  • Refactors database initialization to support re-initialization when incompatible packs are found
  • Updates minimum CodeQL version for overlay support and adds comprehensive test coverage

Reviewed Changes

Copilot reviewed 14 out of 20 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/testing-utils.ts Adds overlayVersion parameter to makeVersionInfo utility for testing
src/overlay-database-utils.ts Updates minimum CodeQL version for overlay support from 2.20.5 to 2.22.2
src/init.ts Refactors database initialization and adds pack compatibility checking logic
src/init.test.ts Adds comprehensive tests for pack compatibility checking functionality
src/init-action.ts Integrates pack compatibility checking into the main initialization flow
src/config-utils.test.ts Updates test to use new minimum overlay version constant
src/codeql.ts Adds resolvePacks method interface and implementation
lib/* Generated JavaScript files mirroring the TypeScript changes
Comments suppressed due to low confidence (1)

src/init.test.ts:146

  • The type name PackInfo conflicts with the interface PackInfo exported from src/codeql.ts. Consider renaming this test-specific type to avoid confusion, such as TestPackInfo or MockPackInfo.
type PackInfo = {
  kind: "query" | "library";
  packinfoContents?: string;
};

src/init.ts Outdated
return true;
}

const packInfoPath = path.join(path.dirname(packInfo.path), ".packinfo");
Copy link
Preview

Copilot AI Jul 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hard-coded .packinfo filename is used multiple times in this function. Consider extracting it as a constant (e.g., PACK_INFO_FILENAME) to improve maintainability and reduce the risk of typos.

Suggested change
const packInfoPath = path.join(path.dirname(packInfo.path), ".packinfo");
const packInfoPath = path.join(path.dirname(packInfo.path), PACK_INFO_FILENAME);

Copilot uses AI. Check for mistakes.


const packInfoFileContents = JSON.parse(
fs.readFileSync(packInfoPath, "utf8"),
);
Copy link
Preview

Copilot AI Jul 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JSON parsing errors should be caught and provide more descriptive error messages. The current catch block at line 225 doesn't distinguish between file system errors and JSON parsing errors, which could make debugging more difficult.

Copilot uses AI. Check for mistakes.

Copy link
Contributor

@alexet alexet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't feel to me that resolve packs is quite the right command (although it looks like it will work).It feels like we should run resolve queries with --format startingpacks to find the query packs we care about, and then just use those.

But I am also not fully sure of all the subtleties of either choice.

@cklin
Copy link
Contributor Author

cklin commented Jul 31, 2025

It doesn't feel to me that resolve packs is quite the right command (although it looks like it will work).It feels like we should run resolve queries with --format startingpacks to find the query packs we care about, and then just use those.

But I am also not fully sure of all the subtleties of either choice.

Thanks for the suggestion!

When I first looked into the problem, I considered this approach but was unable to get it to work. While codeql resolve queries with --format startingpacks can map queries to their containing query packs, there does not seem to be a way to get the list of queries that would be used in the analysis and feed that into codeql resolve queries. I could see that codeql database init already computes that information (though a deep-plumbing subcommand) for internal use, but no easy way to obtain that information from outside the CodeQL CLI. Re-interpreting the Code Scanning config file in the action seems like a lot of work for relatively little gain.

Prompted by your suggestion, I looked again. This time I noticed that codeql database init actually generates config-queries.qls suite file with the list of queries, so all I need to do is to feed that suite file into codeql resolve queries, and I can get the list of query packs to check for overlay compatibility.

(There is the slight complication that codeql resolve queries --format startingpacks would also return query packs that have not been compiled. I will have to make the action ignore those query packs when checking for overlay compatibility.)

@cklin cklin marked this pull request as draft July 31, 2025 16:06
@cklin cklin force-pushed the cklin/overlay-pack-check branch from d0d4112 to f1a0360 Compare July 31, 2025 18:31
@cklin
Copy link
Contributor Author

cklin commented Jul 31, 2025

It doesn't feel to me that resolve packs is quite the right command (although it looks like it will work).It feels like we should run resolve queries with --format startingpacks to find the query packs we care about, and then just use those.

I updated the PR to use this approach to identify the query packs to check for overlay compatibility. Related changes:

  • I removed the commit that adds resolvePacks() to the CodeQL interface
  • Instead, there is now a commit to add resolveQueriesStartingPacks()
  • To avoid confusion, I removed the unused resolveQueries() from CodeQL
  • While I am at it, I also removed the unused packDownload() from CodeQL

The other commits remain the same as before. PTAL.

@cklin cklin marked this pull request as ready for review July 31, 2025 20:38
@cklin cklin requested a review from alexet July 31, 2025 20:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants