Skip to content

Commit 3125234

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 exposes a `learnEdits` relation (`file, line, operation, startColumn, endColumn, text`) describing the minimal source rewrite that makes the inline expectations match the actual query results. Replace edits use 1-based half-open `[startColumn, endColumn)` ranges. Equal boundaries represent insertion, and an end column of zero denotes replacement through the end of the line. Same-line inclusive CodeQL location ends convert to exclusive boundaries; locations ending on the following line use the to-EOL form. The relation 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. The Actions postprocessor supplies `#` for `.yml` and `.yaml` sources when implementing the same signature. 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 7879690 commit 3125234

1 file changed

Lines changed: 460 additions & 0 deletions

File tree

0 commit comments

Comments
 (0)