mirror of
https://github.com/openai/codex.git
synced 2026-12-03 00:41:03 +00:00
## Why A terminal's startup color reply can arrive in pieces across the handoff from the startup probe to the live input reader. If the reader treats the leading Escape as a key, the rest of the reply can leak into the composer or trigger a shortcut. A standalone Escape still needs to dismiss reverse history search and leave subsequent typing intact. ## What changed Pass the outstanding foreground and background color queries to Crossterm along with replayed input and the remainder of a two-second reply window measured from the query. Track each completed reply, including valid replies consumed inside bracketed paste. Update the Crossterm pin and let the input drain at screen transitions wait for an ambiguous Escape to resolve within that window. ## Testing Add parser and PTY regression tests for replies completed during probing, split across the handoff, or started in the live reader. Cover bracketed paste, idle Escape followed by typing, and the distinction between a reply's BEL terminator and the editor shortcut. Run the timing-sensitive PTY cases serially in a dedicated Linux Bazel target. GitOrigin-RevId: b7d7db6f7d57866aad18e5bc99c32773ad25f95c
203 lines
5.8 KiB
Smarty
203 lines
5.8 KiB
Smarty
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
resolve_runfile() {
|
|
local logical_path="$1"
|
|
local workspace_logical_path="${logical_path}"
|
|
if [[ -n "${TEST_WORKSPACE:-}" ]]; then
|
|
workspace_logical_path="${TEST_WORKSPACE}/${logical_path}"
|
|
fi
|
|
|
|
for runfiles_root in "${RUNFILES_DIR:-}" "${TEST_SRCDIR:-}"; do
|
|
if [[ -n "${runfiles_root}" && -e "${runfiles_root}/${logical_path}" ]]; then
|
|
printf '%s\n' "${runfiles_root}/${logical_path}"
|
|
return 0
|
|
fi
|
|
if [[ -n "${runfiles_root}" && -e "${runfiles_root}/${workspace_logical_path}" ]]; then
|
|
printf '%s\n' "${runfiles_root}/${workspace_logical_path}"
|
|
return 0
|
|
fi
|
|
done
|
|
|
|
local manifest="${RUNFILES_MANIFEST_FILE:-}"
|
|
if [[ -z "${manifest}" ]]; then
|
|
if [[ -f "$0.runfiles_manifest" ]]; then
|
|
manifest="$0.runfiles_manifest"
|
|
elif [[ -f "$0.exe.runfiles_manifest" ]]; then
|
|
manifest="$0.exe.runfiles_manifest"
|
|
fi
|
|
fi
|
|
|
|
if [[ -n "${manifest}" && -f "${manifest}" ]]; then
|
|
local resolved=""
|
|
resolved="$(awk -v key="${logical_path}" '$1 == key { $1 = ""; sub(/^ /, ""); print; exit }' "${manifest}")"
|
|
if [[ -z "${resolved}" ]]; then
|
|
resolved="$(awk -v key="${workspace_logical_path}" '$1 == key { $1 = ""; sub(/^ /, ""); print; exit }' "${manifest}")"
|
|
fi
|
|
if [[ -n "${resolved}" ]]; then
|
|
printf '%s\n' "${resolved}"
|
|
return 0
|
|
fi
|
|
fi
|
|
|
|
echo "failed to resolve runfile: $logical_path" >&2
|
|
return 1
|
|
}
|
|
|
|
workspace_root_marker="$(resolve_runfile "__WORKSPACE_ROOT_MARKER__")"
|
|
workspace_root="$(dirname "$(dirname "$(dirname "${workspace_root_marker}")")")"
|
|
test_bin="$(resolve_runfile "__TEST_BIN__")"
|
|
RUNFILE_ENV_ARGS=()
|
|
|
|
__RUNFILE_ENV_EXPORTS__
|
|
|
|
run_test_bin() {
|
|
if (( ${#RUNFILE_ENV_ARGS[@]} > 0 )); then
|
|
env "${RUNFILE_ENV_ARGS[@]}" "${test_bin}" "$@"
|
|
else
|
|
"${test_bin}" "$@"
|
|
fi
|
|
}
|
|
|
|
exec_test_bin() {
|
|
if (( ${#RUNFILE_ENV_ARGS[@]} > 0 )); then
|
|
exec env "${RUNFILE_ENV_ARGS[@]}" "${test_bin}" "$@"
|
|
else
|
|
exec "${test_bin}" "$@"
|
|
fi
|
|
}
|
|
|
|
libtest_args=("$@")
|
|
if [[ ${#libtest_args[@]} -eq 0 && -n "${TESTBRIDGE_TEST_ONLY:-}" ]]; then
|
|
libtest_args+=("${TESTBRIDGE_TEST_ONLY}")
|
|
fi
|
|
|
|
test_shard_index() {
|
|
local test_name="$1"
|
|
# FNV-1a 32-bit hash. Keep this stable so adding one test does not reshuffle
|
|
# unrelated tests between shards.
|
|
local hash=2166136261
|
|
local byte
|
|
local char
|
|
local i
|
|
local LC_ALL=C
|
|
|
|
for ((i = 0; i < ${#test_name}; i++)); do
|
|
char="${test_name:i:1}"
|
|
printf -v byte "%d" "'$char"
|
|
hash=$(( ((hash ^ byte) * 16777619) & 0xffffffff ))
|
|
done
|
|
|
|
echo $(( hash % TOTAL_SHARDS ))
|
|
}
|
|
|
|
partition_cases="${CODEX_BAZEL_INCLUDE_CASES:-${CODEX_BAZEL_EXCLUDE_CASES:-}}"
|
|
|
|
run_selected_libtest() {
|
|
if [[ -n "${TEST_SHARD_STATUS_FILE:-}" && "${TEST_TOTAL_SHARDS:-0}" != "0" ]]; then
|
|
touch "${TEST_SHARD_STATUS_FILE}"
|
|
fi
|
|
|
|
# Some targets configure a fixed libtest concurrency. Keep that setting
|
|
# without treating it as an explicit request to override case selection.
|
|
if [[ -n "${partition_cases}" && "${libtest_args[0]:-}" == --test-threads=* ]]; then
|
|
export RUST_TEST_THREADS="${libtest_args[0]#*=}"
|
|
libtest_args=("${libtest_args[@]:1}")
|
|
fi
|
|
|
|
# Extra libtest args are usually ad-hoc local filters. Preserve those exactly
|
|
# rather than combining them with generated exact filters.
|
|
if [[ ${#libtest_args[@]} -gt 0 ]]; then
|
|
exec_test_bin "${libtest_args[@]}"
|
|
fi
|
|
|
|
local has_shards=0
|
|
if [[ -n "${TOTAL_SHARDS}" && "${TOTAL_SHARDS}" != "0" ]]; then
|
|
has_shards=1
|
|
fi
|
|
|
|
if [[ "${has_shards}" == "1" && -z "${SHARD_INDEX}" ]]; then
|
|
echo "TEST_SHARD_INDEX or RULES_RUST_TEST_SHARD_INDEX must be set when sharding is enabled" >&2
|
|
exit 1
|
|
fi
|
|
|
|
local list_output
|
|
local test_list
|
|
list_output="$(run_test_bin --list --format terse)"
|
|
test_list="$(printf '%s\n' "${list_output}" | grep ': test$' | sed 's/: test$//' | LC_ALL=C sort || true)"
|
|
|
|
if [[ -n "${partition_cases}" ]]; then
|
|
# Check the complete list before sharding. An exact name belongs to one
|
|
# launcher only, and a renamed or removed case must update the partition.
|
|
test_list="$(awk -v cases="${partition_cases}" -v want_local="${CODEX_BAZEL_INCLUDE_CASES:+1}" '
|
|
BEGIN {
|
|
split(cases, names, ",")
|
|
for (i in names) selected[names[i]] = 0
|
|
}
|
|
{
|
|
local_case = ($0 in selected)
|
|
if (local_case) selected[$0]++
|
|
if (local_case == (want_local == "1")) print
|
|
}
|
|
END {
|
|
for (name in selected) {
|
|
if (!selected[name]) {
|
|
print "Missing local libtest case: " name > "/dev/stderr"
|
|
exit 1
|
|
}
|
|
}
|
|
}
|
|
' <<< "${test_list}")"
|
|
fi
|
|
|
|
if [[ -z "${test_list}" ]]; then
|
|
exit 0
|
|
fi
|
|
|
|
local skip_filters="${CODEX_BAZEL_TEST_SKIP_FILTERS:-}"
|
|
|
|
local shard_tests=()
|
|
local test_name
|
|
while IFS= read -r test_name; do
|
|
local skip=0
|
|
if [[ -n "${skip_filters}" ]]; then
|
|
local filter
|
|
local old_ifs="${IFS}"
|
|
IFS=','
|
|
for filter in ${skip_filters}; do
|
|
if [[ -n "${filter}" && "${test_name}" == *"${filter}"* ]]; then
|
|
skip=1
|
|
break
|
|
fi
|
|
done
|
|
IFS="${old_ifs}"
|
|
fi
|
|
if [[ "${skip}" == "1" ]]; then
|
|
continue
|
|
fi
|
|
if [[ "${has_shards}" == "0" || $(test_shard_index "${test_name}") == "${SHARD_INDEX}" ]]; then
|
|
shard_tests+=("${test_name}")
|
|
fi
|
|
done <<< "${test_list}"
|
|
|
|
if [[ ${#shard_tests[@]} -eq 0 ]]; then
|
|
exit 0
|
|
fi
|
|
|
|
exec_test_bin "${shard_tests[@]}" --exact
|
|
}
|
|
|
|
__WORKSPACE_ROOT_SETUP__
|
|
|
|
TOTAL_SHARDS="${RULES_RUST_TEST_TOTAL_SHARDS:-${TEST_TOTAL_SHARDS:-}}"
|
|
SHARD_INDEX="${RULES_RUST_TEST_SHARD_INDEX:-${TEST_SHARD_INDEX:-}}"
|
|
if [[ -n "${partition_cases}" || -n "${CODEX_BAZEL_TEST_SKIP_FILTERS:-}" || ( -n "${TOTAL_SHARDS}" && "${TOTAL_SHARDS}" != "0" ) ]]; then
|
|
run_selected_libtest
|
|
fi
|
|
|
|
if [[ ${#libtest_args[@]} -gt 0 ]]; then
|
|
exec_test_bin "${libtest_args[@]}"
|
|
else
|
|
exec_test_bin
|
|
fi
|