-
Notifications
You must be signed in to change notification settings - Fork 290
Add conformance results invariant validator #2205
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
JelleZijlstra
wants to merge
4
commits into
python:main
Choose a base branch
from
JelleZijlstra:codex/conformance-results-validator
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
3 changes: 3 additions & 0 deletions
3
conformance/results/mypy/generics_defaults_specialization.toml
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| """ | ||
| Validate invariants for conformance result files. | ||
| """ | ||
|
|
||
| from pathlib import Path | ||
| import sys | ||
| import tomllib | ||
| from typing import Any | ||
|
|
||
| ALLOWED_RESULT_KEYS = frozenset( | ||
| { | ||
| "conformance_automated", | ||
| "conformant", | ||
| "errors_diff", | ||
| "ignore_errors", | ||
| "notes", | ||
| "output", | ||
| } | ||
| ) | ||
|
|
||
|
|
||
| def main() -> int: | ||
| results_dir = Path(__file__).resolve().parent.parent / "results" | ||
| issues: list[str] = [] | ||
| checked = 0 | ||
|
|
||
| for type_checker_dir in sorted(results_dir.iterdir()): | ||
| if not type_checker_dir.is_dir(): | ||
| continue | ||
| for file in sorted(type_checker_dir.iterdir()): | ||
| if file.name == "version.toml": | ||
| continue | ||
| checked += 1 | ||
| try: | ||
| with file.open("rb") as f: | ||
| info = tomllib.load(f) | ||
| except Exception as e: | ||
| issues.append(f"{file.relative_to(results_dir)}: failed to parse TOML ({e})") | ||
| continue | ||
|
|
||
| issues.extend(_validate_result(file, results_dir, info)) | ||
|
|
||
| if issues: | ||
| print(f"Found {len(issues)} invariant violation(s) across {checked} file(s):") | ||
| for issue in issues: | ||
| print(f"- {issue}") | ||
| return 1 | ||
|
|
||
| print(f"Validated {checked} conformance result file(s); no invariant violations found.") | ||
| return 0 | ||
|
|
||
|
|
||
| def _validate_result(file: Path, results_dir: Path, info: dict[str, Any]) -> list[str]: | ||
| issues: list[str] = [] | ||
| rel_path = file.relative_to(results_dir) | ||
|
|
||
| unknown_keys = sorted(set(info) - ALLOWED_RESULT_KEYS) | ||
| if unknown_keys: | ||
| issues.append( | ||
| f"{rel_path}: unrecognized key(s): {', '.join(repr(key) for key in unknown_keys)}" | ||
| ) | ||
|
|
||
| automated = info.get("conformance_automated") | ||
| if automated not in {"Pass", "Fail"}: | ||
| issues.append( | ||
| f"{rel_path}: conformance_automated must be 'Pass' or 'Fail' (got {automated!r})" | ||
| ) | ||
| return issues | ||
| automated_is_pass = automated == "Pass" | ||
|
|
||
| conformant = info.get("conformant") | ||
| if conformant is None: | ||
| if automated_is_pass: | ||
| conformant_is_pass = True | ||
| else: | ||
| issues.append( | ||
| f"{rel_path}: conformant is required when conformance_automated is 'Fail'" | ||
| ) | ||
| return issues | ||
| elif isinstance(conformant, str): | ||
| if conformant not in ("Pass", "Partial", "Unsupported"): | ||
| issues.append(f"{rel_path}: invalid conformance status {conformant!r}") | ||
| conformant_is_pass = conformant == "Pass" | ||
| else: | ||
| issues.append(f"{rel_path}: conformant must be a string when present") | ||
| return issues | ||
|
|
||
| if conformant_is_pass != automated_is_pass: | ||
| issues.append( | ||
| f"{rel_path}: conformant={conformant!r} does not match " | ||
| f"conformance_automated={automated!r}" | ||
| ) | ||
|
|
||
| if not conformant_is_pass: | ||
| notes = info.get("notes", "") | ||
| if not isinstance(notes, str) or not notes.strip(): | ||
| issues.append( | ||
| f"{rel_path}: notes must be present when checker is not fully conformant" | ||
| ) | ||
|
|
||
| return issues | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| raise SystemExit(main()) | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the only one I wonder about. Conformance is human-scored for a reason. In cases where a conformance test accidentally tests something unspecified and unrelated to the topic of the test, is it reasonable for a human scorer to mark
conformanceas"Pass"even ifconformance_automatedis"Fail"? (Ideally this would be temporary, pending a PR to improve the conformance suite.) Or do we want to prohibit this, in order to better motivate improving the conformance suite? It seems misleading to mark a test file as "Partial" due to an automated-scoring mismatch not actually related to the topic of the test.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think in that case, we should fix the test so the mismatch goes away.