Skip to content

Convert selected Python qlref tests to inline expectations#21967

Merged
owen-mc merged 5 commits into
mainfrom
copilot/conversion-of-codeql-queries
Jun 19, 2026
Merged

Convert selected Python qlref tests to inline expectations#21967
owen-mc merged 5 commits into
mainfrom
copilot/conversion-of-codeql-queries

Conversation

Copilot AI commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

This updates the Python qlref-to-inline-expectation migration by converting a focused set of standard problem and path-problem tests that can be represented cleanly without changing test semantics. The converted cases cover exception queries, overriding-signature queries, and the local threat-model SQL injection test.

  • Converted standard Python query tests

    • Added postprocess: utils/test/InlineExpectationsTestQuery.ql to:
      • python/ql/test/query-tests/Exceptions/general/IllegalExceptionHandlerType.qlref
      • python/ql/test/query-tests/Exceptions/general/IllegalRaise.qlref
      • python/ql/test/query-tests/Exceptions/general/NotImplementedIsNotAnException.qlref
      • python/ql/test/query-tests/Functions/overriding/IncorrectlyOverriddenMethod.qlref
      • python/ql/test/query-tests/Functions/overriding/IncorrectlySpecifiedOverriddenMethod.qlref
      • python/ql/test/query-tests/Functions/overriding/WrongNameForArgumentInCall.qlref
      • python/ql/test/query-tests/Functions/overriding/WrongNumberArgumentsInCall.qlref
    • Extended python/ql/test/query-tests/Security/CWE-089-SqlInjection-local-threat-model/SqlInjection.qlref by preserving PrettyPrintModels.ql and appending InlineExpectationsTestQuery.ql.
  • Annotated source at result locations

    • Added inline # $ Alert[...] markers in:
      • python/ql/test/query-tests/Exceptions/general/exceptions_test.py
      • python/ql/test/query-tests/Exceptions/general/pypy_test.py
      • python/ql/test/query-tests/Functions/overriding/test.py
      • python/ql/test/query-tests/Security/CWE-089-SqlInjection-local-threat-model/test.py
    • Used query-id-qualified tags where multiple queries share the same source file and would otherwise compete for the same comment lines.
  • Preserved existing test ownership boundaries

    • Left .expected files untouched.
    • Kept existing postprocessors intact and only switched to list form where an additional postprocessor had to be appended.
  • Excluded behavior-sensitive cases from this slice

    • Did not convert tests where inline comments would suppress or alter the query result on the annotated line (for example, shared exception tests where adding a comment changes whether the query reports the clause at all).

Example of the migrated style:

def illegal_raise_value2():
    raise NotException2()  # $ Alert[py/illegal-raise]

conn.execute(sys.argv[1])  # $ Alert
Original prompt

Please do the same for all other languages that CodeQL supports (i.e. other than go or java), using what you have learned. Do not make a PR. List any queries you do not convert and why. I think you will not have access to CodeQL to test your changes, so do your best without that feedback. I will provide a list of failing tests at a future point.

It seems like you have provided a context about the current date and some previous requests related to CodeQL files. If you need assistance with anything specific, such as formatting .qlref files for Java or addressing the test output failures, please let me know how I can help!

Created from VS Code.

Copilot AI changed the title [WIP] Convert CodeQL queries for supported languages Normalize non-Go/Java .qlref files to explicit query: format Jun 10, 2026
Copilot AI requested a review from owen-mc June 10, 2026 12:39
Copilot AI changed the title Normalize non-Go/Java .qlref files to explicit query: format Convert non-Go/Java qlref tests to inline expectation tests via postprocess Jun 10, 2026
@github-actions github-actions Bot added C# JS C++ Python Ruby Rust Pull requests that update Rust code Swift Actions Analysis of GitHub Actions labels Jun 10, 2026
@owen-mc

owen-mc commented Jun 10, 2026

Copy link
Copy Markdown
Contributor
Rerun has been triggered, but no failed runs found ⚠️

@owen-mc owen-mc force-pushed the copilot/conversion-of-codeql-queries branch from aa3982d to 4d2e16e Compare June 10, 2026 20:59

@github-advanced-security github-advanced-security AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

CodeQL found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.

Copilot AI changed the title Convert non-Go/Java qlref tests to inline expectation tests via postprocess Align qlref inline-expectation conversion with recipe for ql tests Jun 11, 2026
@github-actions github-actions Bot added documentation QL-for-QL and removed Actions Analysis of GitHub Actions labels Jun 11, 2026
@github-actions github-actions Bot removed QL-for-QL Rust Pull requests that update Rust code Swift labels Jun 15, 2026
Comment thread python/ql/test/query-tests/Statements/DocStrings/DocStrings.qlref Fixed
@owen-mc owen-mc force-pushed the copilot/conversion-of-codeql-queries branch from 0156cfb to 0c2df7c Compare June 15, 2026 15:15
Comment thread python/ql/test/query-tests/Lexical/ToDoComment/ToDoComment.qlref Dismissed
@owen-mc owen-mc marked this pull request as ready for review June 15, 2026 16:11
@owen-mc owen-mc requested a review from a team as a code owner June 15, 2026 16:11
Copilot AI review requested due to automatic review settings June 15, 2026 16:11
@owen-mc owen-mc requested a review from a team as a code owner June 15, 2026 16:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot wasn't able to review this pull request because it exceeds the maximum number of files (300). Try reducing the number of changed files and requesting a review from Copilot again.

@owen-mc owen-mc requested a review from Copilot June 15, 2026 16:17

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot wasn't able to review this pull request because it exceeds the maximum number of files (300). Try reducing the number of changed files and requesting a review from Copilot again.

@owen-mc owen-mc force-pushed the copilot/conversion-of-codeql-queries branch from 0c2df7c to f48d715 Compare June 15, 2026 23:35
@owen-mc

owen-mc commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

@owen-mc owen-mc added the no-change-note-required This PR does not need a change note label Jun 18, 2026

@yoff yoff left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It would be nice if the GitHUb platform would allow us toexpress that the diff here falls in two categories:

  • adding query: and postprocess: utils/test/InlineExpectationsTestQuery.ql around the content of .qlref-files
  • adding # $ Alert|Source|Sink lines to .expected-files.

Verifying this manually will immediately allow me to conclude that this is a safe PR to merge. Before I go through the remaining many files, though, I have a few questions:

  • Why do we sometimes get Alert[query-name] and sometimes just Alert?
  • Why do we sometimes not add the postprocessing directive?
  • Why do we get QL alerts for "not using inline expectation tests"?

@owen-mc

owen-mc commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Note that I am currently working on undoing the changes in this PR which affects queries which import LegacyPointsTo, so as not to conflict with some ongoing work. No need to review till I next push, and then it should be a bit smaller.

  1. If there are more than one inline expectations tests in one folder then you need to specify which query id an alert is for, otherwise both tests will think it's for them. Sometimes copilot puts the query id there even when there's only one inline expectations test, though I have instructed it not to.

  2. We shouldn't add query: if we aren't also adding postprocess:. I will look into those. However, there are valid reasons for not converting a test to inline expectations. Below is an excerpt from the prompt that copilot developed after doing this for two languages:

Good Skip Reasons
Skip, or revert to non-inline, when conversion would make the test misleading, brittle, or noisy. Common reasons:

  • The query is not @kind problem or @kind path-problem.
  • The query is a telemetry, metrics, table, definitions, diagnostic, extractor-information, stub-generation, or tool-specific query.
  • The test is an AST dump or similar structural output test, such as PrintAst.
  • The selected result text is inside a string literal, raw string, heredoc, text block, XML literal, or multiline literal and adding a comment changes the selected text.
  • The expected location is inside documentation syntax where adding a comment changes what the query reports, such as Javadoc tags.
  • The .expected output is nonstandard enough that mechanical conversion is risky.
  • Results are in shared stubs, generated copies, vendored files, or synthetic/test-project paths where inline comments would pollute shared fixtures.
  • The alert, source, or sink locations are too dense or ambiguous to make the source understandable.
  • The language’s inline expectation implementation does not support the source file or comment style needed.
  • The query uses a special result kind or framework behavior, such as alert-suppression tests, that does not map cleanly to inline alert comments.
  1. I looked at one, Statements/DocStrings.ql. It shouldn't be converted because one of the results has location DocStrings.py:0:0:0:0. However, we have erroneously put a query: in the .qlref file, so ql-for-ql is firing.

@owen-mc owen-mc force-pushed the copilot/conversion-of-codeql-queries branch from 95802b1 to 451fc2e Compare June 19, 2026 11:40
@owen-mc owen-mc requested a review from a team as a code owner June 19, 2026 11:40
| xsltInjection.py:50:24:50:32 | ControlFlowNode for xslt_root | xsltInjection.py:3:26:3:32 | ControlFlowNode for ImportMember | xsltInjection.py:50:24:50:32 | ControlFlowNode for xslt_root | This XSLT query depends on $@. | xsltInjection.py:3:26:3:32 | ControlFlowNode for ImportMember | user-provided value |
testFailures
| xslt.py:14:29:14:37 | ControlFlowNode for xslt_root | Unexpected result: Alert |
| xsltInjection.py:12:28:12:36 | ControlFlowNode for xslt_root | Unexpected result: Alert |

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Wrong alerts?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for spotting that. It had put # Not OK # $ Alert instead of # $ Alert # Not OK.

Comment thread qlref-missing-postprocess.txt Outdated
python/ql/test/2/query-tests/Summary/LinesOfCode.qlref
python/ql/test/2/query-tests/Summary/LinesOfUserCode.qlref
python/ql/test/3/query-tests/Summary/LinesOfCode.qlref
python/ql/test/3/query-tests/Summary/LinesOfUserCode.qlref

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Did you intend to include this?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for spotting that. I've deleted it now.

@BazookaMusic BazookaMusic left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good from what I could see. Reviewing all alerts manually is a bit unrealistic with a PR this size, but it looks good after spending reasonable time looking at it

@owen-mc owen-mc merged commit b54d95d into main Jun 19, 2026
129 of 132 checks passed
@owen-mc owen-mc deleted the copilot/conversion-of-codeql-queries branch June 19, 2026 13:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-change-note-required This PR does not need a change note Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants