Files
codex/scripts/codex_package/test_zsh.py
T
Michael Bolin 5a3140176e Expose package assembly helpers and support gzip DotSlash artifacts (#51575)
## What changed

- Extract `create_parser()`, `assemble_package()`, and `archive_package()` from the packaging CLI so callers can assemble a package directory, add files, and archive it separately.
- Support DotSlash artifacts with `format: "gz"` by decompressing the executable directly to its destination.

## Testing

Extend the zsh manifest override test to verify executable contents for both `tar.gz` and `gz` artifacts.

GitOrigin-RevId: 3542b795eea1f2320bef1402d575a9396be43df2
2026-10-07 04:24:56 +00:00

84 lines
3.2 KiB
Python

#!/usr/bin/env python3
import gzip
import hashlib
import json
from pathlib import Path
import sys
import tarfile
import tempfile
import unittest
from unittest.mock import patch
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
from codex_package.targets import TARGET_SPECS
from codex_package.zsh import resolve_zsh_bin
class ResolveZshBinTest(unittest.TestCase):
def test_uses_prebuilt_executable_override(self) -> None:
with tempfile.TemporaryDirectory() as temp_dir:
signed_zsh = Path(temp_dir) / "signed-zsh"
signed_zsh.write_bytes(b"signed zsh binary")
signed_zsh.chmod(0o755)
with patch("codex_package.zsh.fetch_dotslash_executable") as fetch:
zsh_bin = resolve_zsh_bin(
TARGET_SPECS["aarch64-apple-darwin"], zsh_bin=signed_zsh
)
self.assertEqual(zsh_bin, signed_zsh.resolve())
fetch.assert_not_called()
def test_uses_manifest_override(self) -> None:
for archive_format in ("tar.gz", "gz"):
with self.subTest(archive_format=archive_format):
with tempfile.TemporaryDirectory() as temp_dir:
root = Path(temp_dir)
archive = root / f"codex-zsh.{archive_format}"
source = root / "zsh"
source.write_bytes(b"standalone zsh")
if archive_format == "gz":
archive.write_bytes(gzip.compress(source.read_bytes()))
else:
with tarfile.open(archive, "w:gz") as tar:
tar.add(source, arcname="codex-zsh/bin/zsh")
manifest = root / "codex-zsh"
manifest.write_text(
json.dumps(
{
"platforms": {
"linux-x86_64": {
"size": archive.stat().st_size,
"hash": "sha256",
"digest": hashlib.sha256(
archive.read_bytes()
).hexdigest(),
"format": archive_format,
"path": "codex-zsh/bin/zsh",
"providers": [{"url": archive.as_uri()}],
}
}
}
),
encoding="utf-8",
)
with patch(
"codex_package.dotslash.default_cache_root",
return_value=root / "cache",
):
zsh_bin = resolve_zsh_bin(
TARGET_SPECS["x86_64-unknown-linux-musl"], manifest
)
self.assertIsNotNone(zsh_bin)
assert zsh_bin is not None
self.assertEqual(zsh_bin.read_bytes(), b"standalone zsh")
if __name__ == "__main__":
unittest.main()