-
Notifications
You must be signed in to change notification settings - Fork 67
[ML] Add test suite for PR pipeline generator #3197
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
edsavage
wants to merge
2
commits into
elastic:main
Choose a base branch
from
edsavage:add/pr-pipeline-tests
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.
+137
−0
Open
Changes from all commits
Commits
Show all changes
2 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| [pytest] | ||
| testpaths = unittest | ||
| pythonpath = . | ||
| addopts = -v | ||
|
|
||
| markers = | ||
| integration: requires git fetch from origin; opt-in via VERSION_BUMP_GIT_INTEGRATION=1 (see test file) |
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,136 @@ | ||
| #!/usr/bin/env python3 | ||
| # Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| # or more contributor license agreements. Licensed under the Elastic License | ||
| # 2.0 and the following additional limitation. Functionality enabled by the | ||
| # files subject to the Elastic License 2.0 may only be used in production when | ||
| # invoked by an Elasticsearch process with a license key installed that permits | ||
| # use of machine learning features. You may not use this file except in | ||
| # compliance with the Elastic License 2.0 and the foregoing additional | ||
| # limitation. | ||
|
|
||
| """Tests for .buildkite/pipeline.json.py (the PR build pipeline generator). | ||
|
|
||
| Exercises every label/comment code path that uses os.environ so that a missing | ||
| 'import os' (or similar name-error) is caught before it silently breaks CI on | ||
| backport PRs that carry labels like ci:run-qa-tests. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import json | ||
| import os | ||
| import subprocess | ||
| import sys | ||
| from pathlib import Path | ||
|
|
||
| _REPO_ROOT = Path(__file__).resolve().parents[2] | ||
| _PIPELINE = _REPO_ROOT / ".buildkite" / "pipeline.json.py" | ||
|
|
||
|
|
||
| def _run(extra_env: dict[str, str] | None = None, remove_keys: list[str] | None = None) -> dict: | ||
| """Run pipeline.json.py and return the parsed JSON output.""" | ||
| env = os.environ.copy() | ||
| # Strip any real CI env vars that would alter the code path under test. | ||
| for key in (remove_keys or []): | ||
| env.pop(key, None) | ||
| for key in ["GITHUB_PR_TRIGGER_COMMENT", "GITHUB_PR_LABELS", | ||
| "GITHUB_PR_COMMENT_VAR_ACTION", "GITHUB_PR_COMMENT_VAR_ARCH", | ||
| "GITHUB_PR_COMMENT_VAR_PLATFORM", "QAF_TESTS_TO_RUN"]: | ||
| env.pop(key, None) | ||
| if extra_env: | ||
| env.update(extra_env) | ||
| out = subprocess.check_output( | ||
| [sys.executable, str(_PIPELINE)], | ||
| cwd=str(_REPO_ROOT), | ||
| env=env, | ||
| text=True, | ||
| ) | ||
| return json.loads(out) | ||
|
|
||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # Label-triggered paths | ||
| # --------------------------------------------------------------------------- | ||
|
|
||
| def test_no_labels_builds_all_platforms() -> None: | ||
| pipeline = _run({"GITHUB_PR_LABELS": ""}) | ||
| steps = pipeline["steps"] | ||
| labels = [s.get("label", "") for s in steps] | ||
| assert any("Linux" in l for l in labels) | ||
| assert any("MacOS" in l for l in labels) | ||
| assert any("Windows" in l for l in labels) | ||
|
|
||
|
|
||
| def test_qa_label_produces_valid_json() -> None: | ||
| """ci:run-qa-tests triggers os.environ.get() — a missing 'import os' crashes here.""" | ||
| pipeline = _run({"GITHUB_PR_LABELS": "ci:run-qa-tests"}) | ||
| assert isinstance(pipeline, dict) | ||
| assert "steps" in pipeline | ||
| env = pipeline.get("env", {}) | ||
| assert "QAF_TESTS_TO_RUN" in env | ||
| assert "ml_cpp_pr" in env["QAF_TESTS_TO_RUN"] | ||
|
edsavage marked this conversation as resolved.
|
||
|
|
||
|
|
||
| def test_pytorch_label_produces_valid_json() -> None: | ||
| """ci:run-pytorch-tests is the other label that enters the os.environ code path.""" | ||
| pipeline = _run({"GITHUB_PR_LABELS": "ci:run-pytorch-tests"}) | ||
| assert isinstance(pipeline, dict) | ||
| assert "steps" in pipeline | ||
| env = pipeline.get("env", {}) | ||
| assert "QAF_TESTS_TO_RUN" in env | ||
| assert "pytorch_tests" in env["QAF_TESTS_TO_RUN"] | ||
|
|
||
|
|
||
| def test_qa_and_pytorch_labels_deduped() -> None: | ||
| pipeline = _run({"GITHUB_PR_LABELS": "ci:run-qa-tests,ci:run-pytorch-tests"}) | ||
| env = pipeline.get("env", {}) | ||
| suites = env.get("QAF_TESTS_TO_RUN", "").split(",") | ||
| assert suites.count("ml_cpp_pr") == 1 | ||
| assert suites.count("pytorch_tests") == 1 | ||
|
|
||
|
|
||
| def test_qa_label_with_qaf_override_env() -> None: | ||
| """QAF_TESTS_TO_RUN env override is split and forwarded, not appended whole.""" | ||
| pipeline = _run({ | ||
| "GITHUB_PR_LABELS": "ci:run-qa-tests", | ||
| "QAF_TESTS_TO_RUN": "suite_a,suite_b", | ||
| }) | ||
| env = pipeline.get("env", {}) | ||
| suites = env.get("QAF_TESTS_TO_RUN", "").split(",") | ||
| assert "suite_a" in suites | ||
| assert "suite_b" in suites | ||
| assert "ml_cpp_pr" not in suites | ||
|
|
||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # Comment-triggered paths | ||
| # --------------------------------------------------------------------------- | ||
|
|
||
| def test_comment_run_qa_tests_produces_valid_json() -> None: | ||
| pipeline = _run({ | ||
| "GITHUB_PR_TRIGGER_COMMENT": "buildkite run_qa_tests", | ||
| "GITHUB_PR_COMMENT_VAR_ACTION": "run_qa_tests", | ||
| }) | ||
| assert isinstance(pipeline, dict) | ||
| assert "steps" in pipeline | ||
|
|
||
|
|
||
| def test_comment_run_pytorch_tests_produces_valid_json() -> None: | ||
| pipeline = _run({ | ||
| "GITHUB_PR_TRIGGER_COMMENT": "buildkite run_pytorch_tests", | ||
| "GITHUB_PR_COMMENT_VAR_ACTION": "run_pytorch_tests", | ||
| }) | ||
| assert isinstance(pipeline, dict) | ||
| assert "steps" in pipeline | ||
|
|
||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # Output is always valid JSON with required top-level keys | ||
| # --------------------------------------------------------------------------- | ||
|
|
||
| def test_output_always_has_env_and_steps() -> None: | ||
| for labels in ["", "ci:run-qa-tests", "ci:run-pytorch-tests", | ||
| "ci:build-linux", "ci:build-macos", "ci:build-windows"]: | ||
| pipeline = _run({"GITHUB_PR_LABELS": labels}) | ||
| assert "steps" in pipeline, f"missing 'steps' for labels={labels!r}" | ||
| assert "env" in pipeline, f"missing 'env' for labels={labels!r}" | ||
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.
Uh oh!
There was an error while loading. Please reload this page.