fix: context leak

This commit is contained in:
eric
2026-03-15 11:50:25 +01:00
parent 683de60603
commit f317a618b8
11 changed files with 115 additions and 67 deletions

View File

@@ -1 +1,3 @@
package(default_visibility = ["//visibility:public"])
exports_files(["nested_bazel_test.sh"])

View File

@@ -202,6 +202,7 @@ sh_test(
"//:repo_runtime_files",
"//bun:repo_runtime_files",
"//internal:repo_runtime_files",
"//tests:nested_bazel_test.sh",
"//tests/bundle_test/sourcemap_case:BUILD.bazel",
"//tests/bundle_test/sourcemap_case:entry.ts",
],
@@ -246,6 +247,7 @@ sh_test(
"//:repo_runtime_files",
"//bun:repo_runtime_files",
"//internal:repo_runtime_files",
"//tests:nested_bazel_test.sh",
],
env_inherit = ["PATH"],
)

View File

@@ -1,19 +1,15 @@
#!/usr/bin/env bash
set -euo pipefail
if command -v bazel >/dev/null 2>&1; then
bazel_cmd=(bazel)
elif command -v bazelisk >/dev/null 2>&1; then
bazel_cmd=(bazelisk)
else
echo "bazel or bazelisk is required on PATH" >&2
exit 1
fi
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
# shellcheck source=../nested_bazel_test.sh
source "${script_dir}/../nested_bazel_test.sh"
setup_nested_bazel_cmd
find_workspace_root() {
local candidate
local module_path
local script_dir
local search_dir
for candidate in \
"${TEST_SRCDIR:-}/${TEST_WORKSPACE:-}" \
@@ -32,8 +28,8 @@ find_workspace_root() {
fi
fi
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
candidate="$(cd "${script_dir}/../.." && pwd -P)"
search_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
candidate="$(cd "${search_dir}/../.." && pwd -P)"
if [[ -f "${candidate}/MODULE.bazel" ]]; then
printf '%s\n' "${candidate}"
return 0
@@ -45,6 +41,14 @@ find_workspace_root() {
rules_bun_root="$(find_workspace_root)"
cleanup() {
local status="$1"
trap - EXIT
shutdown_nested_bazel_workspace "${rules_bun_root}"
exit "${status}"
}
trap 'cleanup $?' EXIT
run_aquery() {
local mnemonic="$1"
local target="$2"

View File

@@ -1,19 +1,15 @@
#!/usr/bin/env bash
set -euo pipefail
if command -v bazel >/dev/null 2>&1; then
bazel_cmd=(bazel)
elif command -v bazelisk >/dev/null 2>&1; then
bazel_cmd=(bazelisk)
else
echo "bazel or bazelisk is required on PATH" >&2
exit 1
fi
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
# shellcheck source=../nested_bazel_test.sh
source "${script_dir}/../nested_bazel_test.sh"
setup_nested_bazel_cmd
find_workspace_root() {
local candidate
local module_path
local script_dir
local search_dir
for candidate in \
"${TEST_SRCDIR:-}/${TEST_WORKSPACE:-}" \
@@ -32,8 +28,8 @@ find_workspace_root() {
fi
fi
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
candidate="$(cd "${script_dir}/../.." && pwd -P)"
search_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
candidate="$(cd "${search_dir}/../.." && pwd -P)"
if [[ -f "${candidate}/MODULE.bazel" ]]; then
printf '%s\n' "${candidate}"
return 0
@@ -45,6 +41,14 @@ find_workspace_root() {
rules_bun_root="$(find_workspace_root)"
cleanup() {
local status="$1"
trap - EXIT
shutdown_nested_bazel_workspace "${rules_bun_root}"
exit "${status}"
}
trap 'cleanup $?' EXIT
bundle_output="$(
cd "${rules_bun_root}" &&
"${bazel_cmd[@]}" aquery 'mnemonic("BunBundle", //tests/bundle_test/sourcemap_case:sourcemap_bundle)' --output=textproto

View File

@@ -166,6 +166,7 @@ sh_test(
"//:repo_runtime_files",
"//bun:repo_runtime_files",
"//internal:repo_runtime_files",
"//tests:nested_bazel_test.sh",
],
env_inherit = ["PATH"],
)
@@ -201,6 +202,7 @@ sh_test(
"//:repo_runtime_files",
"//bun:repo_runtime_files",
"//internal:repo_runtime_files",
"//tests:nested_bazel_test.sh",
],
env_inherit = ["PATH"],
)
@@ -228,6 +230,7 @@ sh_test(
"//:repo_runtime_files",
"//bun:repo_runtime_files",
"//internal:repo_runtime_files",
"//tests:nested_bazel_test.sh",
],
env_inherit = ["PATH"],
)

View File

@@ -1,22 +1,24 @@
#!/usr/bin/env bash
set -euo pipefail
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
# shellcheck source=../nested_bazel_test.sh
source "${script_dir}/../nested_bazel_test.sh"
setup_nested_bazel_cmd
bun_path="$1"
if command -v bazel >/dev/null 2>&1; then
bazel_cmd=(bazel)
elif command -v bazelisk >/dev/null 2>&1; then
bazel_cmd=(bazelisk)
else
echo "bazel or bazelisk is required on PATH" >&2
exit 1
fi
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
rules_bun_root="$(cd "${script_dir}/../.." && pwd -P)"
workdir="$(mktemp -d)"
trap 'rm -rf "${workdir}"' EXIT
cleanup() {
local status="$1"
trap - EXIT
shutdown_nested_bazel_workspace "${fixture_dir:-}"
rm -rf "${workdir}"
exit "${status}"
}
trap 'cleanup $?' EXIT
fixture_dir="${workdir}/fixture"
mkdir -p "${fixture_dir}"

View File

@@ -1,22 +1,24 @@
#!/usr/bin/env bash
set -euo pipefail
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
# shellcheck source=../nested_bazel_test.sh
source "${script_dir}/../nested_bazel_test.sh"
setup_nested_bazel_cmd
bun_path="$1"
if command -v bazel >/dev/null 2>&1; then
bazel_cmd=(bazel)
elif command -v bazelisk >/dev/null 2>&1; then
bazel_cmd=(bazelisk)
else
echo "bazel or bazelisk is required on PATH" >&2
exit 1
fi
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
rules_bun_root="$(cd "${script_dir}/../.." && pwd -P)"
workdir="$(mktemp -d)"
trap 'rm -rf "${workdir}"' EXIT
cleanup() {
local status="$1"
trap - EXIT
shutdown_nested_bazel_workspace "${fixture_dir:-}"
rm -rf "${workdir}"
exit "${status}"
}
trap 'cleanup $?' EXIT
fixture_dir="${workdir}/fixture"
mkdir -p "${fixture_dir}"

View File

@@ -1,22 +1,24 @@
#!/usr/bin/env bash
set -euo pipefail
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
# shellcheck source=../nested_bazel_test.sh
source "${script_dir}/../nested_bazel_test.sh"
setup_nested_bazel_cmd
bun_path="${1:-bun}"
if command -v bazel >/dev/null 2>&1; then
bazel_cmd=(bazel)
elif command -v bazelisk >/dev/null 2>&1; then
bazel_cmd=(bazelisk)
else
echo "bazel or bazelisk is required on PATH" >&2
exit 1
fi
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
rules_bun_root="$(cd "${script_dir}/../.." && pwd -P)"
workdir="$(mktemp -d)"
trap 'rm -rf "${workdir}"' EXIT
cleanup() {
local status="$1"
trap - EXIT
shutdown_nested_bazel_workspace "${bazel_dir:-}"
rm -rf "${workdir}"
exit "${status}"
}
trap 'cleanup $?' EXIT
fixture_dir="${workdir}/fixture"
plain_dir="${workdir}/plain"

View File

@@ -0,0 +1,24 @@
#!/usr/bin/env bash
setup_nested_bazel_cmd() {
if command -v bazel >/dev/null 2>&1; then
bazel_cmd=(bazel)
elif command -v bazelisk >/dev/null 2>&1; then
bazel_cmd=(bazelisk)
else
echo "bazel or bazelisk is required on PATH" >&2
exit 1
fi
}
shutdown_nested_bazel_workspace() {
local workspace_dir="${1:-}"
if [[ -z ${workspace_dir} || ! -d ${workspace_dir} ]]; then
return 0
fi
(
cd "${workspace_dir}"
"${bazel_cmd[@]}" shutdown >/dev/null 2>&1
) || true
}

View File

@@ -65,6 +65,7 @@ sh_test(
"//internal:repo_runtime_files",
"//js:repo_runtime_files",
"//npm:repo_runtime_files",
"//tests:nested_bazel_test.sh",
],
env_inherit = ["PATH"],
)

View File

@@ -1,22 +1,24 @@
#!/usr/bin/env bash
set -euo pipefail
if command -v bazel >/dev/null 2>&1; then
bazel_bin="$(command -v bazel)"
elif command -v bazelisk >/dev/null 2>&1; then
bazel_bin="$(command -v bazelisk)"
else
echo "bazel or bazelisk is required on PATH" >&2
exit 1
fi
bun_path="${1:-bun}"
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
# shellcheck source=../nested_bazel_test.sh
source "${script_dir}/../nested_bazel_test.sh"
setup_nested_bazel_cmd
rules_bun_root="$(cd "${script_dir}/../.." && pwd -P)"
workdir="$(mktemp -d)"
trap 'rm -rf "${workdir}"' EXIT
cleanup() {
local status="$1"
trap - EXIT
shutdown_nested_bazel_workspace "${fixture_dir:-}"
rm -rf "${workdir}"
exit "${status}"
}
trap 'cleanup $?' EXIT
fixture_dir="${workdir}/fixture"
mkdir -p "${fixture_dir}"
@@ -100,7 +102,7 @@ EOF
output="$(
cd "${fixture_dir}" &&
"${bazel_bin}" run //:app
"${bazel_cmd[@]}" run //:app
)"
if [[ ${output} != *"compat:true"* ]]; then
@@ -110,7 +112,7 @@ fi
query_output="$(
cd "${fixture_dir}" &&
"${bazel_bin}" query //:npm__is_number
"${bazel_cmd[@]}" query //:npm__is_number
)"
if ! grep -Fxq "//:npm__is_number" <<<"${query_output}"; then
echo "expected npm_link_all_packages to create //:npm__is_number" >&2