[red-knot] Add GitHub PR annotations when mdtests fail in CI#17150
Merged
AlexWaygood merged 5 commits intomainfrom Apr 2, 2025
Merged
[red-knot] Add GitHub PR annotations when mdtests fail in CI#17150AlexWaygood merged 5 commits intomainfrom
AlexWaygood merged 5 commits intomainfrom
Conversation
Contributor
|
Contributor
|
MichaReiser
reviewed
Apr 2, 2025
MichaReiser
reviewed
Apr 2, 2025
Member
MichaReiser
left a comment
There was a problem hiding this comment.
This is cool.
I don't think this should be a cargo feature, I'd use an environment variable instead. It would also be great if we can avoid that it has to run as its own job
MichaReiser
reviewed
Apr 2, 2025
MichaReiser
reviewed
Apr 2, 2025
89564e9 to
ff28416
Compare
5a3b914 to
e81f60f
Compare
e81f60f to
494ef81
Compare
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
Member
Author
Member
Author
|
The PR is again ready for re-review :-) |
MichaReiser
approved these changes
Apr 2, 2025
Member
MichaReiser
left a comment
There was a problem hiding this comment.
Thanks, and sorry for the back and forth.
Member
Author
|
No worries, and thank you for the review. It's much better for your suggestions! |
dcreager
added a commit
that referenced
this pull request
Apr 3, 2025
* origin/main: (35 commits) [red-knot] Callable types are disjoint from literals (#17160) [red-knot] Fix inference for `pow` between two literal integers (#17161) [red-knot] Add GitHub PR annotations when mdtests fail in CI (#17150) [red-knot] Fix equivalence of differently ordered unions that contain `Callable` types (#17145) [red-knot] Add initial set of tests for unreachable code (#17159) [`airflow`] Move `AIR302` to `AIR301` and `AIR303` to `AIR302` (#17151) ruff_db: simplify lifetimes on `DiagnosticDisplay` [red-knot] Detect division-by-zero in unions and intersections (#17157) [`airflow`] Add autofix infrastructure to `AIR302` name checks (#16965) [`flake8-bandit`] Mark `str` and `list[str]` literals as trusted input (`S603`) (#17136) [`airflow`] Add autofix for `AIR302` attribute checks (#16977) [`airflow`] Extend `AIR302` with additional symbols (#17085) [`airflow`] Move `AIR301` to `AIR002` (#16978) [`airflow`] Add autofix for `AIR302` method checks (#16976) ruff_db: switch diagnostic rendering over to `std::fmt::Display` [red-knot] Add 'Goto type definition' to the playground (#17055) red_knot_ide: update snapshots red_knot_python_semantic: remove comment about `TypeCheckDiagnostic` ruff_db: delete most of the old diagnostic code red_knot: use `Diagnostic` inside of red knot ...
dcreager
added a commit
that referenced
this pull request
Apr 3, 2025
* origin/main: (82 commits) [red-knot] Fix more [redundant-cast] false positives (#17170) [red-knot] Three-argument type-calls take 'str' as the first argument (#17168) Control flow: `return` and `raise` (#17121) Bump 0.11.3 (#17173) [red-knot] Improve `Debug` implementation for `semantic_index::SymbolTable` (#17172) [red-knot] Fix `str(…)` calls (#17163) [red-knot] visibility_constraint analysis for match cases (#17077) [red-knot] Fix playground crashes when diagnostics are stale (#17165) [red-knot] Callable types are disjoint from literals (#17160) [red-knot] Fix inference for `pow` between two literal integers (#17161) [red-knot] Add GitHub PR annotations when mdtests fail in CI (#17150) [red-knot] Fix equivalence of differently ordered unions that contain `Callable` types (#17145) [red-knot] Add initial set of tests for unreachable code (#17159) [`airflow`] Move `AIR302` to `AIR301` and `AIR303` to `AIR302` (#17151) ruff_db: simplify lifetimes on `DiagnosticDisplay` [red-knot] Detect division-by-zero in unions and intersections (#17157) [`airflow`] Add autofix infrastructure to `AIR302` name checks (#16965) [`flake8-bandit`] Mark `str` and `list[str]` literals as trusted input (`S603`) (#17136) [`airflow`] Add autofix for `AIR302` attribute checks (#16977) [`airflow`] Extend `AIR302` with additional symbols (#17085) ...
maxmynter
pushed a commit
to maxmynter/ruff
that referenced
this pull request
Apr 3, 2025
…sh#17150) ## Summary This PR adds a CI job that causes GitHub to add annotations to a PR diff when mdtest assertions fail. For example: <details> <summary>Screenshot</summary>  </details> ## Motivation Debugging mdtest failures locally is currently a really nice experience: - Errors are displayed with pretty colours, which makes them much more readable - If you run the test from inside an IDE, you can CTRL-click on a path and jump directly to the line that had the failing assertion - If you use [`mdtest.py`](https://github.com/astral-sh/ruff/blob/main/crates/red_knot_python_semantic/mdtest.py), you don't even need to recompile anything after changing an assertion in an mdtest, amd the test results instantly live-update with each change to the MarkDown file Debugging mdtest failures in CI is much more unpleasant, however. Sometimes an error message is just > [static-assert-error] Argument evaluates to `False` ...which doesn't tell you very much unless you navigate to the line in question that has the failing mdtest assertion. The line in question might not even be touched by the PR, and even if it is, it can be hard to find the line if the PR touches many files. Unlike locally, you can't click on the error and jump straight to the line that contains the failing assertion. You also don't get colourised output in CI (https://github.com/astral-sh/ruff/issues/13939). GitHub PR annotations should make it really easy to debug why mdtests are failing on PRs, making PR review much easier. ## Test Plan I opened a PR to my fork [here](https://github.com/AlexWaygood/ruff/pull/11/files) with some bogus changes to an mdtest to show what it looks like when there are failures in CI and this job has been added. Scroll down to `crates/red_knot_python_semantic/resources/mdtest/type_properties/is_equivalent_to.md` on the "files changed" tab for that PR to see the annotations.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
This PR adds a CI job that causes GitHub to add annotations to a PR diff when mdtest assertions fail. For example:
Screenshot
Motivation
Debugging mdtest failures locally is currently a really nice experience:
mdtest.py, you don't even need to recompile anything after changing an assertion in an mdtest, amd the test results instantly live-update with each change to the MarkDown fileDebugging mdtest failures in CI is much more unpleasant, however. Sometimes an error message is just
...which doesn't tell you very much unless you navigate to the line in question that has the failing mdtest assertion. The line in question might not even be touched by the PR, and even if it is, it can be hard to find the line if the PR touches many files. Unlike locally, you can't click on the error and jump straight to the line that contains the failing assertion. You also don't get colourised output in CI (astral-sh/ty#235).
GitHub PR annotations should make it really easy to debug why mdtests are failing on PRs, making PR review much easier.
How it works
A new
mdtest_github_output_formatfeature is added to thered_knot_python_semanticcrate. When the feature is enabled, mdtest failures are printed to the terminal using a format that causes GitHub to attach annotations to the PR diff. If the feature is not enabled, mdtest failures are printed using the same format that they were before, since that's what is best for local development.A new CI job is added to
ci.yamlthat runs only red-knot's mdtests with this feature flag enabled. The job takes around 1m40s to run to completion on GitHub'subuntu-latestrunner. The job only runs on PRs (not pushes tomainor onworkflow_dispatchevents), and only runs if red-knot-related code changes as part of the PR.Test Plan
I opened a PR to my fork here with some bogus changes to an mdtest to show what it looks like when there are failures in CI and this job has been added. Scroll down to
crates/red_knot_python_semantic/resources/mdtest/type_properties/is_equivalent_to.mdon the "files changed" tab for that PR to see the annotations.