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
This commit is contained in:
Michael Bolin
2026-10-07 04:24:56 +00:00
committed by copyberry
parent 18e28fe1b9
commit 5a3140176e
3 changed files with 64 additions and 39 deletions
+42 -36
View File
@@ -1,5 +1,6 @@
#!/usr/bin/env python3
import gzip
import hashlib
import json
from pathlib import Path
@@ -31,46 +32,51 @@ class ResolveZshBinTest(unittest.TestCase):
fetch.assert_not_called()
def test_uses_manifest_override(self) -> None:
with tempfile.TemporaryDirectory() as temp_dir:
root = Path(temp_dir)
archive = root / "codex-zsh.tar.gz"
source = root / "zsh"
source.write_bytes(b"standalone zsh")
with tarfile.open(archive, "w:gz") as tar:
tar.add(source, arcname="codex-zsh/bin/zsh")
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": "tar.gz",
"path": "codex-zsh/bin/zsh",
"providers": [{"url": archive.as_uri()}],
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",
)
),
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
)
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")
self.assertIsNotNone(zsh_bin)
assert zsh_bin is not None
self.assertEqual(zsh_bin.read_bytes(), b"standalone zsh")
if __name__ == "__main__":