mirror of
https://github.com/openai/codex.git
synced 2026-10-24 18:18:41 +00:00
code-mode: provide host binary to cargo tests
This commit is contained in:
@@ -104,6 +104,13 @@ jobs:
|
||||
with:
|
||||
target: ${{ inputs.target }}
|
||||
|
||||
- name: Configure rusty_v8 artifact overrides and verify checksums
|
||||
if: ${{ runner.os != 'Windows' }}
|
||||
uses: ./.github/actions/setup-rusty-v8
|
||||
with:
|
||||
sandbox: "true"
|
||||
target: ${{ inputs.target }}
|
||||
|
||||
- name: Compute lockfile hash
|
||||
id: lockhash
|
||||
shell: bash
|
||||
@@ -199,13 +206,23 @@ jobs:
|
||||
--archive-file "${archive_dir}/${NEXTEST_ARCHIVE_FILE}"
|
||||
|
||||
- name: Build runtime test helpers
|
||||
if: ${{ runner.os == 'Linux' || runner.os == 'Windows' }}
|
||||
shell: bash
|
||||
run: |
|
||||
set -euo pipefail
|
||||
helper_dir="${RUNNER_TEMP}/${TEST_HELPERS_ARTIFACT}"
|
||||
mkdir -p "${helper_dir}"
|
||||
|
||||
host_name="codex-code-mode-host"
|
||||
if [[ "${RUNNER_OS}" == "Windows" ]]; then
|
||||
host_name="${host_name}.exe"
|
||||
fi
|
||||
cargo build \
|
||||
--target ${{ inputs.target }} \
|
||||
--profile ${{ inputs.profile }} \
|
||||
-p codex-code-mode-host \
|
||||
--bin codex-code-mode-host
|
||||
cp "target/${{ inputs.target }}/${{ inputs.profile }}/${host_name}" "${helper_dir}/"
|
||||
|
||||
if [[ "${RUNNER_OS}" == "Linux" ]]; then
|
||||
cargo build \
|
||||
--target ${{ inputs.target }} \
|
||||
@@ -213,7 +230,7 @@ jobs:
|
||||
-p codex-linux-sandbox \
|
||||
--bin codex-linux-sandbox
|
||||
cp "target/${{ inputs.target }}/${{ inputs.profile }}/codex-linux-sandbox" "${helper_dir}/"
|
||||
else
|
||||
elif [[ "${RUNNER_OS}" == "Windows" ]]; then
|
||||
cargo build \
|
||||
--target ${{ inputs.target }} \
|
||||
--profile ${{ inputs.profile }} \
|
||||
@@ -241,7 +258,6 @@ jobs:
|
||||
retention-days: 1
|
||||
|
||||
- name: Upload runtime test helpers
|
||||
if: ${{ runner.os == 'Linux' || runner.os == 'Windows' }}
|
||||
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
|
||||
with:
|
||||
name: ${{ env.TEST_HELPERS_ARTIFACT }}
|
||||
@@ -353,7 +369,6 @@ jobs:
|
||||
path: ${{ runner.temp }}/nextest-archive
|
||||
|
||||
- name: Download runtime test helpers
|
||||
if: ${{ runner.os == 'Linux' || runner.os == 'Windows' }}
|
||||
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
|
||||
with:
|
||||
name: ${{ env.TEST_HELPERS_ARTIFACT }}
|
||||
@@ -372,18 +387,43 @@ jobs:
|
||||
workspace_root="$(cygpath -w "${workspace_root}")"
|
||||
fi
|
||||
|
||||
helper_dir="${RUNNER_TEMP}/${TEST_HELPERS_ARTIFACT}"
|
||||
helper_target_dir="$(pwd)/target/${{ inputs.target }}/${{ inputs.profile }}"
|
||||
mkdir -p "${helper_target_dir}"
|
||||
host_name="codex-code-mode-host"
|
||||
if [[ "${RUNNER_OS}" == "Windows" ]]; then
|
||||
host_name="${host_name}.exe"
|
||||
fi
|
||||
cp "${helper_dir}/${host_name}" "${helper_target_dir}/"
|
||||
|
||||
host_path="${helper_target_dir}/${host_name}"
|
||||
if [[ "${RUNNER_OS}" == "Windows" ]]; then
|
||||
host_path="$(cygpath -w "${host_path}")"
|
||||
else
|
||||
chmod +x "${host_path}"
|
||||
fi
|
||||
|
||||
test_env=(
|
||||
"CARGO_BIN_EXE_codex-code-mode-host=${host_path}"
|
||||
"CARGO_BIN_EXE_codex_code_mode_host=${host_path}"
|
||||
)
|
||||
if [[ "${RUNNER_OS}" == "Linux" ]]; then
|
||||
helper_dir="${RUNNER_TEMP}/${TEST_HELPERS_ARTIFACT}"
|
||||
helper_target_dir="$(pwd)/target/${{ inputs.target }}/${{ inputs.profile }}"
|
||||
mkdir -p "${helper_target_dir}"
|
||||
cp "${helper_dir}/codex-linux-sandbox" "${helper_target_dir}/"
|
||||
chmod +x "${helper_target_dir}/codex-linux-sandbox"
|
||||
sandbox_helper="${helper_target_dir}/codex-linux-sandbox"
|
||||
test_env+=(
|
||||
"CARGO_BIN_EXE_codex-linux-sandbox=${sandbox_helper}"
|
||||
"CARGO_BIN_EXE_codex_linux_sandbox=${sandbox_helper}"
|
||||
)
|
||||
elif [[ "${RUNNER_OS}" == "Windows" ]]; then
|
||||
helper_dir="${RUNNER_TEMP}/${TEST_HELPERS_ARTIFACT}"
|
||||
helper_target_dir="$(pwd)/target/${{ inputs.target }}/${{ inputs.profile }}"
|
||||
mkdir -p "${helper_target_dir}"
|
||||
cp "${helper_dir}/codex-windows-sandbox-setup.exe" "${helper_target_dir}/"
|
||||
cp "${helper_dir}/codex-command-runner.exe" "${helper_target_dir}/"
|
||||
setup_helper="$(cygpath -w "${helper_target_dir}/codex-windows-sandbox-setup.exe")"
|
||||
command_runner="$(cygpath -w "${helper_target_dir}/codex-command-runner.exe")"
|
||||
test_env+=(
|
||||
"CARGO_BIN_EXE_codex_windows_sandbox_setup=${setup_helper}"
|
||||
"CARGO_BIN_EXE_codex_command_runner=${command_runner}"
|
||||
)
|
||||
fi
|
||||
|
||||
nextest_args=(
|
||||
@@ -397,27 +437,7 @@ jobs:
|
||||
nextest_args+=(--test-threads "${{ inputs.test_threads }}")
|
||||
fi
|
||||
|
||||
test_command=(cargo nextest "${nextest_args[@]}")
|
||||
if [[ "${RUNNER_OS}" == "Linux" ]]; then
|
||||
sandbox_helper="${helper_target_dir}/codex-linux-sandbox"
|
||||
test_command=(
|
||||
env
|
||||
"CARGO_BIN_EXE_codex-linux-sandbox=${sandbox_helper}"
|
||||
"CARGO_BIN_EXE_codex_linux_sandbox=${sandbox_helper}"
|
||||
cargo nextest "${nextest_args[@]}"
|
||||
)
|
||||
elif [[ "${RUNNER_OS}" == "Windows" ]]; then
|
||||
setup_helper="$(cygpath -w "${helper_target_dir}/codex-windows-sandbox-setup.exe")"
|
||||
command_runner="$(cygpath -w "${helper_target_dir}/codex-command-runner.exe")"
|
||||
test_command=(
|
||||
env
|
||||
"CARGO_BIN_EXE_codex_windows_sandbox_setup=${setup_helper}"
|
||||
"CARGO_BIN_EXE_codex_command_runner=${command_runner}"
|
||||
cargo nextest "${nextest_args[@]}"
|
||||
)
|
||||
fi
|
||||
|
||||
"${test_command[@]}"
|
||||
env "${test_env[@]}" cargo nextest "${nextest_args[@]}"
|
||||
env:
|
||||
RUST_BACKTRACE: 1
|
||||
RUST_MIN_STACK: "8388608" # 8 MiB
|
||||
|
||||
@@ -569,14 +569,12 @@ impl TestCodexBuilder {
|
||||
installation_id,
|
||||
/*attestation_provider*/ None,
|
||||
);
|
||||
let code_mode_session_provider =
|
||||
match codex_utils_cargo_bin::cargo_bin("codex-code-mode-host") {
|
||||
Ok(program) => IpcCodeModeSessionProvider::new(CodeModeHostCommand {
|
||||
program,
|
||||
args: Vec::new(),
|
||||
}),
|
||||
Err(_) => IpcCodeModeSessionProvider::default(),
|
||||
};
|
||||
let program = codex_utils_cargo_bin::cargo_bin("codex-code-mode-host")
|
||||
.context("codex-code-mode-host must be built for core integration tests")?;
|
||||
let code_mode_session_provider = IpcCodeModeSessionProvider::new(CodeModeHostCommand {
|
||||
program,
|
||||
args: Vec::new(),
|
||||
});
|
||||
let thread_manager =
|
||||
thread_manager.with_code_mode_session_provider(Arc::new(code_mode_session_provider));
|
||||
let thread_manager = Arc::new(thread_manager);
|
||||
|
||||
@@ -75,11 +75,11 @@ install:
|
||||
# there should be no need to add `--all-features`.
|
||||
[unix]
|
||||
test *args:
|
||||
RUST_MIN_STACK={{ rust_min_stack }} NEXTEST_PROFILE=local cargo nextest run --no-fail-fast "$@"
|
||||
RUST_MIN_STACK={{ rust_min_stack }} NEXTEST_PROFILE=local {{ python }} ../scripts/run-nextest.py "$@"
|
||||
|
||||
[windows]
|
||||
test *args:
|
||||
$env:RUST_MIN_STACK = "{{ rust_min_stack }}"; $env:NEXTEST_PROFILE = "local"; cargo nextest run --no-fail-fast @($args | Select-Object -Skip 1)
|
||||
$env:RUST_MIN_STACK = "{{ rust_min_stack }}"; $env:NEXTEST_PROFILE = "local"; {{ python }} ../scripts/run-nextest.py @($args | Select-Object -Skip 1)
|
||||
|
||||
# Run from the repository root so scripts that resolve paths from `cwd` see
|
||||
# the same layout they use in GitHub Actions.
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
"""Build runtime helpers and run the Codex nextest suite."""
|
||||
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
||||
|
||||
from codex_package.targets import REPO_ROOT
|
||||
from codex_package.targets import TARGET_SPECS
|
||||
from codex_package.v8 import resolve_codex_v8_cargo_env
|
||||
|
||||
|
||||
CODEX_RS_ROOT = REPO_ROOT / "codex-rs"
|
||||
|
||||
|
||||
def rustc_host_target() -> str:
|
||||
rustc = os.environ.get("RUSTC", "rustc")
|
||||
version = subprocess.run(
|
||||
[rustc, "-vV"],
|
||||
check=True,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
).stdout
|
||||
for line in version.splitlines():
|
||||
if line.startswith("host: "):
|
||||
return line.removeprefix("host: ")
|
||||
raise RuntimeError("rustc -vV did not report a host target")
|
||||
|
||||
|
||||
def main() -> int:
|
||||
target = rustc_host_target()
|
||||
try:
|
||||
spec = TARGET_SPECS[target]
|
||||
except KeyError as exc:
|
||||
raise RuntimeError(
|
||||
f"unsupported host target for code-mode tests: {target}"
|
||||
) from exc
|
||||
|
||||
env = {**os.environ, **resolve_codex_v8_cargo_env(spec)}
|
||||
cargo = os.environ.get("CARGO", "cargo")
|
||||
subprocess.run(
|
||||
[
|
||||
cargo,
|
||||
"build",
|
||||
"-p",
|
||||
"codex-code-mode-host",
|
||||
"--bin",
|
||||
"codex-code-mode-host",
|
||||
],
|
||||
cwd=CODEX_RS_ROOT,
|
||||
check=True,
|
||||
env=env,
|
||||
)
|
||||
return subprocess.run(
|
||||
[cargo, "nextest", "run", "--no-fail-fast", *sys.argv[1:]],
|
||||
cwd=CODEX_RS_ROOT,
|
||||
env=env,
|
||||
).returncode
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
Reference in New Issue
Block a user