forked from earendil-works/pi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.sh
More file actions
executable file
·79 lines (70 loc) · 2.3 KB
/
Copy pathtest.sh
File metadata and controls
executable file
·79 lines (70 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env bash
set -euo pipefail
# Isolate user resources, credentials, temporary files, and tool configuration.
temp_parent="${TMPDIR:-/tmp}"
temp_parent="${temp_parent%/}"
test_root="$(mktemp -d "$temp_parent/pi-test.XXXXXX")"
git_askpass="$(type -P false)"
readonly temp_parent test_root git_askpass
mkdir -p "$test_root/home/.config" "$test_root/tmp" "$test_root/cache/npm"
# Mark the generated root so cleanup can verify ownership before deleting it.
touch "$test_root/.pi-test-owned" "$test_root/npm-userconfig" "$test_root/npm-globalconfig"
# Only remove the marked directory created above, never an unverified path.
cleanup() {
local status=$?
trap - EXIT
case "$test_root" in
"$temp_parent"/pi-test.*)
if [[ -d "$test_root" && ! -L "$test_root" && -f "$test_root/.pi-test-owned" ]]; then
rm -rf -- "$test_root"
else
printf "Refusing to remove unverified test directory: %s\n" "$test_root" >&2
[[ $status -ne 0 ]] || status=1
fi
;;
*)
printf "Refusing to remove unexpected test directory: %s\n" "$test_root" >&2
[[ $status -ne 0 ]] || status=1
;;
esac
exit "$status"
}
trap cleanup EXIT
# Start from an empty environment and allow only required platform and test settings.
test_env=(
"PATH=$PATH"
"PWD=$PWD"
"HOME=$test_root/home"
"USERPROFILE=$test_root/home"
"TMPDIR=$test_root/tmp"
"TMP=$test_root/tmp"
"TEMP=$test_root/tmp"
"XDG_CONFIG_HOME=$test_root/home/.config"
"XDG_CACHE_HOME=$test_root/cache"
"LANG=C"
"LC_ALL=C"
"TZ=UTC"
"GIT_CONFIG_NOSYSTEM=1"
"GIT_CONFIG_GLOBAL=/dev/null"
"GIT_TERMINAL_PROMPT=0"
"GIT_ASKPASS=$git_askpass"
"GIT_EDITOR=true"
"GIT_SEQUENCE_EDITOR=true"
"NPM_CONFIG_USERCONFIG=$test_root/npm-userconfig"
"NPM_CONFIG_GLOBALCONFIG=$test_root/npm-globalconfig"
"NPM_CONFIG_CACHE=$test_root/cache/npm"
"PI_NO_LOCAL_LLM=1"
"AWS_EC2_METADATA_DISABLED=true"
)
# Native Windows needs these inherited values to launch child processes.
for name in SystemRoot SYSTEMROOT WINDIR COMSPEC PATHEXT; do
value="${!name-}"
[[ -z "$value" ]] || test_env+=("$name=$value")
done
# Preserve CI detection only for runner behavior and test reporting.
for name in CI GITHUB_ACTIONS; do
value="${!name-}"
[[ -z "$value" ]] || test_env+=("$name=$value")
done
echo "Running tests without API keys in isolated home: $test_root/home"
env -i "${test_env[@]}" npm test