Repository navigation
fix: keep consumer fixtures clean under strict Pyright #4204
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
Merged
+84
−21
Merged
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,24 +1,30 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| set -e | ||
| set -euo pipefail | ||
|
|
||
| cd "$(dirname "$0")/.." | ||
| base=$(git rev-parse --verify --end-of-options "${1:?expected a base revision}^{commit}") | ||
|
|
||
| echo "==> Detecting breaking changes" | ||
|
|
||
| TEST_PATHS=( | ||
| tests/api_resources | ||
| tests/test_client.py | ||
| tests/test_response.py | ||
| tests/test_legacy_response.py | ||
| ) | ||
| # Keep today's callers Pyright-clean before they become tomorrow's baseline. | ||
| echo '==> Checking current callers against the candidate SDK' | ||
| uv run --locked --all-extras scripts/run-pyright | ||
|
|
||
| for PATHSPEC in "${TEST_PATHS[@]}"; do | ||
| # Try to check out previous versions of the test files | ||
| # with the current SDK. | ||
| git checkout "$1" -- "${PATHSPEC}" 2>/dev/null || true | ||
| done | ||
| # If the tests are identical, the first run already checked the base callers. | ||
| # A change confined to tests and this script has no new SDK to compare. | ||
| test_changes=$(git diff --name-only "$base" -- tests) | ||
| other_changes=$(git diff --name-only "$base" -- . ':(exclude)tests' ':(exclude)scripts/detect-breaking-changes') | ||
| if [[ -z "$test_changes" || -z "$other_changes" ]]; then | ||
| exit 0 | ||
| fi | ||
|
|
||
| # Check unchanged previous-version callers with Pyright. Repository development | ||
| # uses ty; this isolated gate protects consumers who use another checker. | ||
| uv run --locked --all-extras scripts/run-pyright | ||
| # Check the complete base test tree, including its helpers, against today's | ||
| # src and checker configuration. Leave the working tree and Git index intact. | ||
| echo '==> Checking previous callers against the candidate SDK' | ||
| snapshot=$(mktemp -d) | ||
| trap 'rm -rf -- "$snapshot"' EXIT | ||
| git archive "$base" tests | tar -x -C "$snapshot" | ||
| ln -s "$PWD/src" "$snapshot/src" | ||
| mkdir "$snapshot/scripts" | ||
| config=scripts/pyrightconfig.breaking-changes.json | ||
| cp "$config" "$snapshot/$config" | ||
| PYRIGHT_PROJECT="$snapshot/$config" uv run --locked --all-extras scripts/run-pyright | ||
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,57 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import os | ||
| import shutil | ||
| import subprocess | ||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
|
|
||
|
|
||
| @pytest.mark.skipif(os.name != "posix", reason="The compatibility gate runs in Bash on CI") | ||
| @pytest.mark.parametrize("also_change", [None, "src/model.py", "pyproject.toml"]) | ||
| def test_compatibility_gate_selects_callers(tmp_path: Path, also_change: str | None) -> None: | ||
| scripts = tmp_path / "scripts" | ||
| scripts.mkdir() | ||
| gate = scripts / "detect-breaking-changes" | ||
| shutil.copy(Path(__file__).resolve().parents[1] / "scripts" / gate.name, gate) | ||
| (scripts / "pyrightconfig.breaking-changes.json").write_text("{}") | ||
| (tmp_path / "tests").mkdir() | ||
| (tmp_path / "src").mkdir() | ||
| (tmp_path / "src/model.py").write_text("original SDK\n") | ||
| caller = tmp_path / "tests/caller.py" | ||
| caller.write_text("previous caller\n") | ||
|
|
||
| # Record the checker inputs to exercise the real Git and snapshot routing. | ||
| uv = tmp_path / "uv" | ||
| uv.write_text( | ||
| "#!/bin/sh\nset -eu\nconfig=${PYRIGHT_PROJECT:-scripts/pyrightconfig.breaking-changes.json}\n" | ||
| 'root=$(dirname "$config")/..\ncat "$root/tests/caller.py" "$root/src/model.py"\n' | ||
| ) | ||
| uv.chmod(0o755) | ||
| subprocess.run(["git", "init", "--quiet"], cwd=tmp_path, check=True) | ||
| subprocess.run(["git", "add", "."], cwd=tmp_path, check=True) | ||
| subprocess.run( | ||
| ["git", "-c", "user.name=Test", "-c", "user.email=test@example.org", "commit", "--no-gpg-sign", "-qm", "base"], | ||
| cwd=tmp_path, | ||
| check=True, | ||
| ) | ||
|
|
||
| caller.write_text("current caller\n") | ||
| if also_change is not None: | ||
| (tmp_path / also_change).write_text("changed input\n") | ||
| subprocess.run(["git", "add", also_change], cwd=tmp_path, check=True) | ||
| result = subprocess.run( | ||
| [str(gate), "HEAD"], | ||
| cwd=tmp_path, | ||
| env={**os.environ, "PATH": f"{tmp_path}{os.pathsep}{os.environ['PATH']}"}, | ||
| text=True, | ||
| capture_output=True, | ||
| check=True, | ||
| ) | ||
| sdk = "changed input" if also_change == "src/model.py" else "original SDK" | ||
| expected = ["current caller", sdk] | ||
| if also_change is not None: | ||
| expected.extend(["previous caller", sdk]) | ||
| assert [line for line in result.stdout.splitlines() if not line.startswith("==>")] == expected | ||
| assert caller.read_text() == "current caller\n" |
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.
Uh oh!
There was an error while loading. Please reload this page.