mirror of
https://github.com/openai/codex.git
synced 2026-10-21 17:48:44 +00:00
fix code mode host packaging compatibility
This commit is contained in:
@@ -17,16 +17,12 @@ from codex_package.targets import TARGET_SPECS
|
||||
class PackageLayoutTest(unittest.TestCase):
|
||||
def test_app_server_package_places_code_mode_host_in_resources(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as temp_dir:
|
||||
for target in (
|
||||
"x86_64-unknown-linux-musl",
|
||||
"x86_64-pc-windows-msvc",
|
||||
):
|
||||
for target, spec in TARGET_SPECS.items():
|
||||
with self.subTest(target=target):
|
||||
root = Path(temp_dir) / target
|
||||
root.mkdir()
|
||||
package_dir = root / "package"
|
||||
package_dir.mkdir()
|
||||
spec = TARGET_SPECS[target]
|
||||
inputs = PackageInputs(
|
||||
entrypoint_bin=touch_executable(root / "codex-app-server"),
|
||||
code_mode_host_bin=touch_executable(
|
||||
|
||||
@@ -539,7 +539,6 @@ function Test-PackageContentsAreComplete {
|
||||
"codex-package.json",
|
||||
"bin\codex.exe",
|
||||
"codex-path\rg.exe",
|
||||
"codex-resources\codex-code-mode-host.exe",
|
||||
"codex-resources\codex-command-runner.exe",
|
||||
"codex-resources\codex-windows-sandbox-setup.exe"
|
||||
)
|
||||
@@ -549,7 +548,17 @@ function Test-PackageContentsAreComplete {
|
||||
}
|
||||
}
|
||||
|
||||
return $true
|
||||
$hostPaths = @(
|
||||
"codex-resources\codex-code-mode-host.exe",
|
||||
"bin\codex-code-mode-host.exe"
|
||||
)
|
||||
foreach ($name in $hostPaths) {
|
||||
if (Test-Path -LiteralPath (Join-Path $PackageDir $name) -PathType Leaf) {
|
||||
return $true
|
||||
}
|
||||
}
|
||||
|
||||
return $false
|
||||
}
|
||||
|
||||
function Test-LegacyPlatformNpmContentsAreComplete {
|
||||
|
||||
@@ -760,6 +760,15 @@ handle_conflicting_install() {
|
||||
fi
|
||||
}
|
||||
|
||||
package_code_mode_host_relative_path() {
|
||||
package_dir="$1"
|
||||
if [ -f "$package_dir/codex-resources/codex-code-mode-host" ]; then
|
||||
printf 'codex-resources/codex-code-mode-host\n'
|
||||
else
|
||||
printf 'bin/codex-code-mode-host\n'
|
||||
fi
|
||||
}
|
||||
|
||||
install_package_release() {
|
||||
release_dir="$1"
|
||||
archive_path="$2"
|
||||
@@ -769,9 +778,10 @@ install_package_release() {
|
||||
rm -rf "$stage_release"
|
||||
mkdir -p "$stage_release"
|
||||
tar -xzf "$archive_path" -C "$stage_release"
|
||||
code_mode_host_relative_path="$(package_code_mode_host_relative_path "$stage_release")"
|
||||
chmod 0755 \
|
||||
"$stage_release/bin/codex" \
|
||||
"$stage_release/codex-resources/codex-code-mode-host" \
|
||||
"$stage_release/$code_mode_host_relative_path" \
|
||||
"$stage_release/codex-path/rg"
|
||||
if [ -f "$stage_release/codex-resources/bwrap" ]; then
|
||||
chmod 0755 "$stage_release/codex-resources/bwrap"
|
||||
@@ -824,7 +834,8 @@ release_dir_is_complete() {
|
||||
package)
|
||||
[ -f "$release_dir/codex-package.json" ] &&
|
||||
[ -x "$release_dir/bin/codex" ] &&
|
||||
[ -x "$release_dir/codex-resources/codex-code-mode-host" ] &&
|
||||
{ [ -x "$release_dir/codex-resources/codex-code-mode-host" ] ||
|
||||
[ -x "$release_dir/bin/codex-code-mode-host" ]; } &&
|
||||
[ -x "$release_dir/codex-path/rg" ] ||
|
||||
return 1
|
||||
;;
|
||||
@@ -866,17 +877,23 @@ update_visible_command() {
|
||||
mkdir -p "$BIN_DIR"
|
||||
tmp_link="$BIN_DIR/.codex.$$"
|
||||
codex_relative_path="$(release_codex_relative_path "$release_dir")"
|
||||
code_mode_host_relative_path="$(package_code_mode_host_relative_path "$release_dir")"
|
||||
|
||||
replace_path_with_symlink "$BIN_PATH" "$CURRENT_LINK/$codex_relative_path" "$tmp_link"
|
||||
|
||||
if [ "$os" = "darwin" ] && [ -x "$release_dir/bin/codex-code-mode-host" ]; then
|
||||
if [ "$os" = "darwin" ] && [ -x "$release_dir/$code_mode_host_relative_path" ]; then
|
||||
replace_path_with_symlink \
|
||||
"$CODE_MODE_HOST_BIN_PATH" \
|
||||
"$CURRENT_LINK/bin/codex-code-mode-host" \
|
||||
"$CURRENT_LINK/$code_mode_host_relative_path" \
|
||||
"$tmp_link"
|
||||
elif [ "$(readlink "$CODE_MODE_HOST_BIN_PATH" 2>/dev/null || true)" = \
|
||||
"$CURRENT_LINK/bin/codex-code-mode-host" ]; then
|
||||
rm -f "$CODE_MODE_HOST_BIN_PATH"
|
||||
else
|
||||
existing_code_mode_host_target="$(readlink "$CODE_MODE_HOST_BIN_PATH" 2>/dev/null || true)"
|
||||
case "$existing_code_mode_host_target" in
|
||||
"$CURRENT_LINK/bin/codex-code-mode-host" | \
|
||||
"$CURRENT_LINK/codex-resources/codex-code-mode-host")
|
||||
rm -f "$CODE_MODE_HOST_BIN_PATH"
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
@@ -89,30 +89,38 @@ class InstallShTest(unittest.TestCase):
|
||||
self.assertNotIn("codex-package_SHA256SUMS", requests[1])
|
||||
|
||||
def test_macos_install_exposes_code_mode_host_beside_codex(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as temp_dir:
|
||||
root = Path(temp_dir)
|
||||
archive_path, checksum_path, metadata_json = create_package_release(root)
|
||||
for host_dir in ("codex-resources", "bin"):
|
||||
with (
|
||||
self.subTest(host_dir=host_dir),
|
||||
tempfile.TemporaryDirectory() as temp_dir,
|
||||
):
|
||||
root = Path(temp_dir)
|
||||
archive_path, checksum_path, metadata_json = create_package_release(
|
||||
root, host_dir=host_dir
|
||||
)
|
||||
|
||||
result, _requests = run_installer_in(
|
||||
root,
|
||||
VERSION,
|
||||
metadata_json=metadata_json,
|
||||
archive_path=archive_path,
|
||||
checksum_path=checksum_path,
|
||||
force_macos=True,
|
||||
)
|
||||
result, _requests = run_installer_in(
|
||||
root,
|
||||
VERSION,
|
||||
metadata_json=metadata_json,
|
||||
archive_path=archive_path,
|
||||
checksum_path=checksum_path,
|
||||
force_macos=True,
|
||||
)
|
||||
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
install_bin = root / "install-bin"
|
||||
current = root / "codex-home" / "packages" / "standalone" / "current"
|
||||
codex_path = install_bin / "codex"
|
||||
host_path = install_bin / "codex-code-mode-host"
|
||||
self.assertEqual(os.readlink(codex_path), str(current / "bin" / "codex"))
|
||||
self.assertEqual(
|
||||
os.readlink(host_path),
|
||||
str(current / "bin" / "codex-code-mode-host"),
|
||||
)
|
||||
self.assertTrue(os.access(host_path, os.X_OK))
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
install_bin = root / "install-bin"
|
||||
current = root / "codex-home" / "packages" / "standalone" / "current"
|
||||
codex_path = install_bin / "codex"
|
||||
host_path = install_bin / "codex-code-mode-host"
|
||||
self.assertEqual(
|
||||
os.readlink(codex_path), str(current / "bin" / "codex")
|
||||
)
|
||||
self.assertEqual(
|
||||
os.readlink(host_path),
|
||||
str(current / host_dir / "codex-code-mode-host"),
|
||||
)
|
||||
self.assertTrue(os.access(host_path, os.X_OK))
|
||||
|
||||
|
||||
def run_installer(
|
||||
@@ -241,9 +249,12 @@ def run_installer_in(
|
||||
return result, requests
|
||||
|
||||
|
||||
def create_package_release(root: Path) -> tuple[Path, Path, str]:
|
||||
def create_package_release(
|
||||
root: Path, *, host_dir: str = "codex-resources"
|
||||
) -> tuple[Path, Path, str]:
|
||||
package_dir = root / "package"
|
||||
(package_dir / "bin").mkdir(parents=True)
|
||||
(package_dir / host_dir).mkdir(exist_ok=True)
|
||||
(package_dir / "codex-path").mkdir()
|
||||
(package_dir / "codex-package.json").write_text("{}\n", encoding="utf-8")
|
||||
write_executable(
|
||||
@@ -251,7 +262,7 @@ def create_package_release(root: Path) -> tuple[Path, Path, str]:
|
||||
f"#!/bin/sh\nprintf 'codex-cli {VERSION}\\n'\n",
|
||||
)
|
||||
write_executable(
|
||||
package_dir / "bin" / "codex-code-mode-host",
|
||||
package_dir / host_dir / "codex-code-mode-host",
|
||||
"#!/bin/sh\nexit 0\n",
|
||||
)
|
||||
write_executable(package_dir / "codex-path" / "rg", "#!/bin/sh\nexit 0\n")
|
||||
|
||||
Reference in New Issue
Block a user