Files
codex/scripts/codex_package/test_cli.py
Adam Perry @ OpenAI 45528c5132 Allow overriding Codex package versions (#39298)
## What changed

- Add `--package-version` to set the version written to `codex-package.json`, while retaining the workspace package version as the default.
- Reject values that are not runtime-compatible semantic versions, including overflowing numeric components and numeric prerelease identifiers with leading zeroes.
- Document the new option.

## Testing

- Add unit coverage for valid release, prerelease, and build versions, plus malformed and out-of-range values.

GitOrigin-RevId: cee996a6721e3fac9bd88f0bc0302a7ec7d2b2fb
2026-08-18 22:16:48 +00:00

49 lines
1.3 KiB
Python

#!/usr/bin/env python3
import argparse
from pathlib import Path
import sys
import unittest
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
from codex_package.cli import parse_package_version
class PackageVersionTest(unittest.TestCase):
def test_accepts_release_prerelease_and_build_versions(self) -> None:
for version in (
"0.0.0",
"1.2.3",
"0.0.0-internal.deadbeef",
"1.2.3-alpha.1+build.01",
"18446744073709551615.0.0",
):
with self.subTest(version=version):
self.assertEqual(parse_package_version(version), version)
def test_rejects_versions_the_runtime_cannot_parse(self) -> None:
for version in (
"",
"1",
"1.2",
"1.2.3.4",
"v1.2.3",
"01.2.3",
"1.02.3",
"1.2.03",
"1.2.3-",
"1.2.3-alpha..1",
"1.2.3-01",
"1.2.3+",
"1.2.3+build..1",
"18446744073709551616.0.0",
):
with self.subTest(version=version):
with self.assertRaises(argparse.ArgumentTypeError):
parse_package_version(version)
if __name__ == "__main__":
unittest.main()