-
Notifications
You must be signed in to change notification settings - Fork 104
[fix] dev tag for sea binary should never be used #326
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
+718
−377
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
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,85 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import importlib.util | ||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
|
|
||
| from stagehand.lib import sea_binary | ||
| from stagehand._version import __version__ | ||
|
|
||
|
|
||
| def _load_download_binary_module(): | ||
| script_path = Path(__file__).resolve().parents[1] / "scripts" / "download-binary.py" | ||
| spec = importlib.util.spec_from_file_location("download_binary_script", script_path) | ||
| assert spec is not None | ||
| assert spec.loader is not None | ||
|
|
||
| module = importlib.util.module_from_spec(spec) | ||
| spec.loader.exec_module(module) | ||
| return module | ||
|
|
||
|
|
||
| download_binary = _load_download_binary_module() | ||
|
|
||
|
|
||
| def test_resolve_binary_path_defaults_cache_version_to_package_version( | ||
| monkeypatch: pytest.MonkeyPatch, | ||
| tmp_path: Path, | ||
| ) -> None: | ||
| resource_path = tmp_path / "stagehand-test" | ||
| resource_path.write_bytes(b"binary") | ||
|
|
||
| captured: dict[str, object] = {} | ||
|
|
||
| monkeypatch.delenv("STAGEHAND_VERSION", raising=False) | ||
| def _fake_resource_binary_path(_filename: str) -> Path: | ||
| return resource_path | ||
|
|
||
| monkeypatch.setattr(sea_binary, "_resource_binary_path", _fake_resource_binary_path) | ||
|
|
||
| def _fake_copy_to_cache(*, src: Path, filename: str, version: str) -> Path: | ||
| captured["src"] = src | ||
| captured["filename"] = filename | ||
| captured["version"] = version | ||
| return tmp_path / "cache" / filename | ||
|
|
||
| monkeypatch.setattr(sea_binary, "_copy_to_cache", _fake_copy_to_cache) | ||
|
|
||
| resolved = sea_binary.resolve_binary_path() | ||
|
|
||
| assert resolved == tmp_path / "cache" / sea_binary.default_binary_filename() | ||
| assert captured["src"] == resource_path | ||
| assert captured["filename"] == sea_binary.default_binary_filename() | ||
| assert captured["version"] == __version__ | ||
|
|
||
|
|
||
| def test_parse_server_tag_rejects_prerelease_tags() -> None: | ||
| assert download_binary._parse_server_tag("stagehand-server-v3/v3.20.0-dev") is None | ||
| assert download_binary._parse_server_tag("stagehand-server-v3/v3.20.0+build.1") is None | ||
|
|
||
|
|
||
| def test_normalize_server_tag_rejects_prerelease_input() -> None: | ||
| try: | ||
| download_binary.normalize_server_tag("v3.20.0-dev") | ||
| except ValueError as exc: | ||
| assert "stable tag" in str(exc) | ||
| else: | ||
| raise AssertionError("Expected prerelease version input to be rejected") | ||
|
|
||
|
|
||
| def test_resolve_latest_server_tag_ignores_dev_releases( | ||
| monkeypatch: pytest.MonkeyPatch, | ||
| ) -> None: | ||
| releases = [ | ||
| {"tag_name": "stagehand-server-v3/v3.20.0-dev"}, | ||
| {"tag_name": "stagehand-server-v3/v3.19.1"}, | ||
| {"tag_name": "stagehand-server-v3/v3.19.0"}, | ||
| ] | ||
|
|
||
| def _fake_http_get_json(_url: str) -> list[dict[str, str]]: | ||
| return releases | ||
|
|
||
| monkeypatch.setattr(download_binary, "_http_get_json", _fake_http_get_json) | ||
|
|
||
| assert download_binary.resolve_latest_server_tag() == "stagehand-server-v3/v3.19.1" |
Oops, something went wrong.
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.