Skip to content

Commit fa9e048

Browse files
d10cCopilot
andcommitted
Support --learn for inline expectations via learnEdits
`codeql test run --learn` could previously only rewrite `.expected` files; inline expectations (the `// $ Alert` comments checked by `InlineExpectationsTest`) had to be fixed by hand. This teaches the shared test library to compute those source edits so the test runner can apply them. The `test-postprocess` query now exposes a `learnEdits` relation (`file, line, operation, startColumn, endColumn, text`) describing the minimal source rewrite that would make the inline expectations match the actual query results. It covers: - appending a fresh comment carrying every tag learned for a line that has an unexpected result and no existing comment to merge into; - rewriting an existing expectation comment as a whole so it matches the current results: dropping fixed-spurious tags, promoting a `MISSING:` expectation that now fires, clearing a stale `SPURIOUS:` annotation, and merging in freshly learned tags, re-rendering the remaining expectations (or deleting the comment when none remain); - preserving expectations this test does not own -- e.g. a tag annotated with a different query's id that shares the source file -- and any trailing regular note (`// $ Alert // note`); - recording any unexpected result, not just `Alert`. The comment syntax comes from the `getStartCommentMarker` / `getEndCommentMarker` markers added to `InputSig` in the previous commit, so `LearnEditsImpl` renders each edit in the target file's own syntax and stays language-agnostic. Edits are emitted as a query predicate rather than applied here: the engine consumes `learnEdits` only under `--learn` and ignores it otherwise, so ordinary `test run` output is unchanged. The supporting predicates are wrapped in a `private module LearnEditsImpl` so only the `query predicate learnEdits` is re-exposed. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 1adfa307-c48e-43f5-94e3-8286e4a8c083
1 parent 8f89558 commit fa9e048

1 file changed

Lines changed: 446 additions & 0 deletions

File tree

0 commit comments

Comments
 (0)