generated from amazon-archives/__template_Custom
-
Notifications
You must be signed in to change notification settings - Fork 26
chore: formalize and test conformance test file naming #115
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
crowecawcaw
wants to merge
1
commit into
OpenJobDescription:mainline
Choose a base branch
from
crowecawcaw:filenames
base: mainline
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| name: Conformance Test Suite Validation | ||
|
|
||
| on: | ||
| push: | ||
| branches: [ mainline ] | ||
| paths: | ||
| - conformance-tests/** | ||
| pull_request: | ||
| branches: [ mainline ] | ||
| paths: | ||
| - conformance-tests/** | ||
| workflow_dispatch: | ||
|
|
||
| jobs: | ||
| validate-naming: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v6 | ||
|
|
||
| - name: Setup Python | ||
| uses: actions/setup-python@v6 | ||
| with: | ||
| python-version: '3.12' | ||
|
|
||
| - name: Validate conformance test suite | ||
| working-directory: conformance-tests | ||
| run: python test_conformance_suite.py |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,102 @@ | ||
| #!/usr/bin/env python3 | ||
| """Validates that all conformance test filenames follow the naming convention documented in README.md. | ||
|
|
||
| The naming scheme is: | ||
| [<doc>-][<section>]--<description>[.invalid][.test].<ext> | ||
|
|
||
| - Base spec tests (under base/): no doc prefix, section required (leading number). | ||
| - Extension tests: doc prefix required (chunk, redact, etc.), section optional. | ||
| - If an extension test is testing a base spec rule, it uses base spec naming (leading number, no doc prefix). | ||
| """ | ||
|
|
||
| import re | ||
| import sys | ||
| from pathlib import Path | ||
|
|
||
| CONFORMANCE_DIR = Path(__file__).parent | ||
|
|
||
| # Map extension directory names to their doc prefix | ||
| EXTENSION_DOC_PREFIX = { | ||
| "TASK_CHUNKING": "chunk", | ||
| "REDACTED_ENV_VARS": "redact", | ||
| } | ||
|
|
||
| # Base spec pattern: starts with a digit (section number) | ||
| # <section>--<description>[.invalid][.test].<ext> | ||
| BASE_RE = re.compile( | ||
| r"^(?P<section>\d+(?:\.\d+)*)--(?P<desc>[a-z0-9]+(?:-[a-z0-9]+)*)(?P<invalid>\.invalid)?(?P<test>\.test)?\.(?P<ext>yaml|json)$" | ||
| ) | ||
|
|
||
| # Extension pattern: starts with a doc prefix | ||
| # <doc>[-<section>]--<description>[.invalid][.test].<ext> | ||
| def extension_re(prefix: str) -> re.Pattern: | ||
| return re.compile( | ||
| rf"^{re.escape(prefix)}(?:-(?P<section>\d+(?:\.\d+)*))?--(?P<desc>[a-z0-9]+(?:-[a-z0-9]+)*)(?P<invalid>\.invalid)?(?P<test>\.test)?\.(?P<ext>yaml|json)$" | ||
| ) | ||
|
|
||
|
|
||
| def validate_filename(name: str, component: str, test_type: str) -> list[str]: | ||
| """Returns a list of error strings (empty if valid).""" | ||
| errors = [] | ||
|
|
||
| if component == "base": | ||
| m = BASE_RE.match(name) | ||
| if not m: | ||
| errors.append(f"does not match base naming pattern: [<section>]--<description>[.invalid][.test].<ext>") | ||
| return errors | ||
| else: | ||
| prefix = EXTENSION_DOC_PREFIX.get(component) | ||
| if prefix is None: | ||
| errors.append(f"unknown extension directory '{component}', add it to EXTENSION_DOC_PREFIX") | ||
| return errors | ||
| ext_pattern = extension_re(prefix) | ||
| m = BASE_RE.match(name) or ext_pattern.match(name) | ||
| if not m: | ||
| errors.append( | ||
| f"does not match naming pattern: " | ||
| f"<section>--<desc>... (base spec rule) or " | ||
| f"{prefix}[-<section>]--<desc>... (extension)" | ||
| ) | ||
| return errors | ||
|
|
||
| if test_type == "jobs" and not m.group("test"): | ||
| errors.append("files in jobs/ must have .test suffix") | ||
| if test_type in ("job_templates", "env_templates") and m.group("test"): | ||
| errors.append(f"files in {test_type}/ must not have .test suffix") | ||
|
|
||
| return errors | ||
|
|
||
|
|
||
| def main() -> int: | ||
| failures = [] | ||
|
|
||
| for spec_dir in sorted(CONFORMANCE_DIR.iterdir()): | ||
| if not spec_dir.is_dir() or not spec_dir.name[0].isdigit(): | ||
| continue | ||
| for component_dir in sorted(spec_dir.iterdir()): | ||
| if not component_dir.is_dir(): | ||
| continue | ||
| component = component_dir.name | ||
| for test_type in ("job_templates", "env_templates", "jobs"): | ||
| type_dir = component_dir / test_type | ||
| if not type_dir.is_dir(): | ||
| continue | ||
| for f in sorted(type_dir.iterdir()): | ||
| if not f.is_file(): | ||
| continue | ||
| errs = validate_filename(f.name, component, test_type) | ||
| for e in errs: | ||
| failures.append(f"{f.relative_to(CONFORMANCE_DIR)}: {e}") | ||
|
|
||
| if failures: | ||
| print(f"FAIL: {len(failures)} file(s) with invalid names:\n") | ||
| for msg in failures: | ||
| print(f" {msg}") | ||
| return 1 | ||
|
|
||
| print("OK: all conformance test filenames are valid") | ||
| return 0 | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| sys.exit(main()) |
Oops, something went wrong.
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.
The redaction and chunk extensions add language to the existing spec though, they don't introduce any new ones. Shouldn't the
chunk-3.4.1.5-*just be3.4.1.5-*still?