Skip to content

[inline-learn lib 3/3] Add direct MakeTest inline learning - #23013

Draft
d10c wants to merge 2 commits into
d10c/multi-query-ql-reconciliationfrom
d10c/direct-ql-maketest-learning
Draft

d10c wants to merge 2 commits into
d10c/multi-query-ql-reconciliationfrom
d10c/direct-ql-maketest-learning

Conversation

@d10c

@d10c d10c commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

What problem does it solve?

Inline-expectation learning needs to work for direct test .ql queries that use MakeTest, not only for .qlref tests with a postprocessor.

Why is the problem a problem?

Direct tests have no .qlref ownership metadata or postprocessing stage. Without an explicit direct-query protocol, they cannot emit source edits while preserving their ordinary result relations.

How does the solution work?

Direct learning plans emit the same six-column learnEdits relation consumed by the test runner. Exact main-schema recognition avoids treating metadata or @id queries as edit producers. Shared edit emission is reused, while direct and postprocessing plans remain separate because their discovery, identity, output, and reconciliation contracts differ.

Why does the solution solve the problem?

The direct query computes edits from its own MakeTest expectations and returns them through the runner's established relation shape. Ordinary query results remain available for expected-output comparison.

Why is this a good solution?

It adds direct support without pretending that direct queries and tagged .qlref cohorts have interchangeable membership semantics. Mixed or multiple producers can therefore be rejected safely until a generalized source-owner contract is designed.

Testing

Python and Java library fixtures cover direct edit generation and ordinary result preservation. They were exercised with plain, learn, repeated-learn, and plain verification runs.

Stack: follows #23012 in Stack #23015.

@d10c
d10c added this pull request to stack #23014 November 4, 2026 12:42
@d10c
d10c removed this pull request from stack #23014 November 4, 2026 12:45
@d10c
d10c added this pull request to stack #23015 November 4, 2026 12:45
@d10c d10c changed the title d10c/direct ql maketest learning Add direct MakeTest inline learning Nov 4, 2026
@d10c
d10c requested an auto review from Copilot November 4, 2026 12:46

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.

🟡 Changes recommended

Critical issues remain: appending expectations can break Python continuation lines, and unvalidated result values can be misparsed or introduce newlines that damage source code.

2 open issues
What changed in this PR

Adds inline-expectation learning for direct .ql tests using MakeTest, reusing the existing learnEdits protocol while keeping direct-query reconciliation separate from .qlref postprocessing.

Changes:

  • Extracts shared comment rendering and edit emission.
  • Adds a conservative direct-learning plan and explicit expected-tag alias support.
  • Adds Python and Java fixtures with matching direct-test expectations.
File Description
shared/​util/​codeql/​util/​test/​InlineExpectationsTest.qll Adds direct learning and shared edit-emission helpers.
python/​ql/​test/​library-tests/​InlineExpectationsTest/​learn-edits/​Test.ql Defines a direct test with tag aliases.
python/​ql/​test/​library-tests/​InlineExpectationsTest/​learn-edits/​test.py Supplies matching alias and foreign annotations.
python/​ql/​test/​library-tests/​InlineExpectationsTest/​learn-edits/​Test.expected Records empty expected output for the Python fixture.
java/​ql/​test/​library-tests/​InlineExpectationsTest/​learn-edits/​Test.ql Defines a direct test for a source method.
java/​ql/​test/​library-tests/​InlineExpectationsTest/​learn-edits/​Test.java Supplies a method with a matching annotation.
java/​ql/​test/​library-tests/​InlineExpectationsTest/​learn-edits/​Test.expected Records empty expected output for the Java fixture.

Review effort: Balanced (auto)

Comment on lines +627 to +628
parseRelativeUrl(Impl::getRelativeUrl(actualResult.getLocation()), relativePath, line, _,
line, _) and
) and
parseRelativeUrl(Impl::getRelativeUrl(actualResult.getLocation()), relativePath, line, _,
line, _) and
text = actualResult.getExpectationText()
@d10c d10c changed the title Add direct MakeTest inline learning [inline-learn lib 3/3] Add direct MakeTest inline learning Nov 4, 2026
d10c and others added 2 commits November 4, 2026 14:11
Expose the learnEdits protocol from direct MakeTest queries without relying on query metadata or @id. Share edit emission with qlref postprocessing while restricting direct reconciliation to safe line-comment syntax and leaving unsupported forms for verification.

Add Python and Java fixtures covering custom expected tags, foreign tags, standard tags, and missing query IDs.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: e860263a-9e7b-4451-8b4a-3b5d119a962c
Require generated expectation atoms to round-trip through the inline grammar before emitting an edit. Let language implementations reject unsafe end-of-line appends, and conservatively disable Python appends where explicit continuation lines cannot be distinguished at this seam.

Cover unsafe hash, whitespace, newline, and Python continuation cases through the public learnEdits relation.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 1adfa307-c48e-43f5-94e3-8286e4a8c083
@d10c
d10c force-pushed the d10c/direct-ql-maketest-learning branch from 2a07a02 to ae1a0d7 Compare November 4, 2026 14:01

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants