Prevent stable release pointers from moving backward (#51186)

## Why

Publishing an older stable version should not replace a newer release as the default download or installation target.

## What changed

- Compare stable versions before marking a GitHub release as latest, allowing same-version reruns to finish publication.
- Guard npm `latest` and platform dist-tags, publishing older versions under separate `release-<version>-<tag>` tags.
- Check R2's `latest` channel before updating it or the installer aliases, while allowing same-version reruns to repair interrupted installer updates.
- Reject invalid existing stable release metadata and consolidate GitHub latest and canary checks in `releases.py`.

## Testing

Add regression tests for stable version ordering, same-version reruns, npm package and platform tags, and invalid channel metadata. All 21 tests in `.github/scripts/test_releases.py` pass.

GitOrigin-RevId: e6bad3ee163b279ac1661b9070712a41eedd50ff
This commit is contained in:
andrewgu-oai
2026-10-05 22:19:18 +00:00
committed by copyberry
parent aa6635ece5
commit 5cbcf810e5
6 changed files with 185 additions and 66 deletions
+83 -11
View File
@@ -8,7 +8,8 @@ import unittest
from unittest.mock import patch
from npm_alpha_tag import npm_alpha_tag
from releases import is_valid_release_version, should_update_version
import publish_r2_release as r2
from releases import is_valid_release_version, should_make_latest, should_update_version
class VersionComparisonTest(unittest.TestCase):
@@ -61,10 +62,32 @@ class VersionComparisonTest(unittest.TestCase):
class NpmAlphaTagTest(unittest.TestCase):
def write_package(self, tarball: Path, package: str) -> None:
content = json.dumps({"name": package}).encode()
with tarfile.open(tarball, "w:gz") as archive:
info = tarfile.TarInfo("package/package.json")
info.size = len(content)
archive.addfile(info, io.BytesIO(content))
def test_published_tags_across_packages_and_platforms(self) -> None:
# Each package/tag reads its own registry value, even after a partially
# published release. Also exercise a missing pointer and dotted hotfix.
cases = [
(
"@openai/codex-sdk",
"latest",
"0.100.0",
"0.99.9",
"release-0.99.9-latest",
),
(
"@openai/codex",
"linux-x64",
"0.99.9-linux-x64",
"0.100.0",
"linux-x64",
),
("@openai/codex-responses-api-proxy", "latest", None, "0.100.0", "latest"),
(
"@openai/codex",
"alpha",
@@ -101,16 +124,19 @@ class NpmAlphaTagTest(unittest.TestCase):
"release-0.158.0-alpha.10.1-alpha",
),
("@openai/codex-sdk", "alpha", None, "0.158.0-alpha.10", "alpha"),
(
"@openai/codex",
"alpha-linux-x64",
"broken-linux-x64",
"0.158.0-alpha.10",
"alpha-linux-x64",
),
]
with tempfile.TemporaryDirectory() as tmpdir:
tarball = Path(tmpdir) / "package.tgz"
for package, tag, current, version, expected in cases:
with self.subTest(package=package, tag=tag, version=version):
content = json.dumps({"name": package}).encode()
with tarfile.open(tarball, "w:gz") as archive:
info = tarfile.TarInfo("package/package.json")
info.size = len(content)
archive.addfile(info, io.BytesIO(content))
self.write_package(tarball, package)
tags = {tag: current} if current is not None else {}
result = subprocess.CompletedProcess([], 0, json.dumps(tags))
with patch(
@@ -131,14 +157,26 @@ class NpmAlphaTagTest(unittest.TestCase):
text=True,
)
def test_stable_tags_reject_malformed_and_prerelease_versions(self) -> None:
with tempfile.TemporaryDirectory() as tmpdir:
tarball = Path(tmpdir) / "package.tgz"
self.write_package(tarball, "@openai/codex")
for tag, current in (
("latest", "broken"),
("linux-x64", "0.100.0-alpha.1-linux-x64"),
):
with self.subTest(tag=tag, current=current):
result = subprocess.CompletedProcess(
[], 0, json.dumps({tag: current})
)
with patch("npm_alpha_tag.subprocess.run", return_value=result):
with self.assertRaises(ValueError):
npm_alpha_tag(tarball, "0.99.9", tag)
def test_registry_failure_prevents_publish(self) -> None:
with tempfile.TemporaryDirectory() as tmpdir:
tarball = Path(tmpdir) / "package.tgz"
content = b'{"name": "@openai/codex"}'
with tarfile.open(tarball, "w:gz") as archive:
info = tarfile.TarInfo("package/package.json")
info.size = len(content)
archive.addfile(info, io.BytesIO(content))
self.write_package(tarball, "@openai/codex")
with patch(
"npm_alpha_tag.subprocess.run",
side_effect=subprocess.CalledProcessError(1, "npm"),
@@ -147,5 +185,39 @@ class NpmAlphaTagTest(unittest.TestCase):
npm_alpha_tag(tarball, "0.158.0-alpha.10", "alpha")
class StablePublicationTests(unittest.TestCase):
def test_github_latest_orders_numerically_and_allows_equal_reruns(self):
latest = {"tag_name": "rust-v0.100.0", "draft": False, "prerelease": False}
self.assertFalse(should_make_latest("0.99.9", latest))
self.assertTrue(should_make_latest("0.100.0", latest))
self.assertTrue(should_make_latest("0.101.0", latest))
def test_github_latest_rejects_unpublished_or_unreadable_metadata(self):
for latest in (
{},
{"tag_name": "rust-vunknown", "draft": False, "prerelease": False},
{"tag_name": "rust-v0.100.0", "draft": True, "prerelease": False},
{"tag_name": "rust-v0.100.0", "draft": False, "prerelease": True},
):
with self.subTest(latest=latest):
with self.assertRaises(ValueError):
should_make_latest("0.99.9", latest)
def test_r2_checks_its_channel_and_only_repairs_unreadable_prereleases(self):
with patch.object(r2, "run_command") as command:
command.return_value = '{"tag_name":"rust-v0.100.0"}'
self.assertFalse(r2.should_update_channel("endpoint", "0.99.9", "latest"))
self.assertTrue(r2.should_update_channel("endpoint", "0.100.0", "latest"))
self.assertIn(
"s3://releases/codex/channels/latest", command.call_args.args[0]
)
command.return_value = "invalid"
with self.assertRaises(r2.PublishError):
r2.should_update_channel("endpoint", "0.99.9", "latest")
self.assertTrue(
r2.should_update_channel("endpoint", "0.99.9-alpha.1", "prerelease")
)
if __name__ == "__main__":
unittest.main()