Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added local annotations + added initial concurrency + added a limit o…
…n amount of times the annotation loop can run + fixed bugs
  • Loading branch information
terryluan12 committed Jan 11, 2026
commit e9265bd5c1ec10bb11bf91a84e2e2eca56d77d55
57 changes: 31 additions & 26 deletions scripts/update_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ EOF

if [[ $# -eq 0 ]]; then
usage
exit 1
fi


Expand Down Expand Up @@ -53,14 +52,14 @@ while [[ $# -gt 0 ]]; do
;;
-h|--help)
usage
return
exit 1
;;
-s|--check-skipped)
check_skip_flag=true
shift
;;
-t|--timeout)
timout="$2"
timeout="$2"
shift 2
;;
-a|--annotate)
Expand All @@ -79,17 +78,18 @@ rpython_path="$rpython_path/Lib/test"


update_tests() {
libraries=$1
local libraries=("$@")
for lib in "${libraries[@]}"
do
update_test "$lib"
update_test "$lib" &
done
wait
}

update_test() {
lib=$1
clib_path="$cpython_path/$lib"
rlib_path="$rpython_path/$lib"
local lib=$1
local clib_path="$cpython_path/$lib"
local rlib_path="$rpython_path/$lib"

if files_equal "$clib_path" "$rlib_path"; then
echo "No changes in $lib. Skipping..."
Expand All @@ -114,26 +114,27 @@ update_test() {
}

check_skips() {
libraries=$1
local libraries=("$@")
for lib in "${libraries[@]}"
do
check_skip "$lib"
check_skip "$lib" &
done
wait
}

check_skip() {
lib=$1
rlib_path="$rpython_path/$lib"
local lib=$1
local rlib_path="$rpython_path/$lib"

remove_skips $rlib_path

annotate_lib $lib $rlib_path
}

annotate_lib() {
lib=$(echo "$1" | sed 's/\//./g')
rlib_path=$2
output=$(rustpython $lib 2>&1)
local lib=$(echo "$1" | sed 's/\//./g')
local rlib_path=$2
local output=$(rustpython $lib 2>&1)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Declare and assign separately to capture exit status.

If rustpython fails (e.g., cargo run fails), the exit status is masked by the assignment. This could lead to processing invalid output.

Suggested fix
-    local output=$(rustpython $lib 2>&1)
+    local output
+    output=$(rustpython "$lib" 2>&1)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
local output=$(rustpython $lib 2>&1)
local output
output=$(rustpython "$lib" 2>&1)
🧰 Tools
🪛 Shellcheck (0.11.0)

[warning] 159-159: Declare and assign separately to avoid masking return values.

(SC2155)

🤖 Prompt for AI Agents
In @scripts/update_tests.sh at line 159, Replace the combined
declaration+assignment "local output=$(rustpython $lib 2>&1)" with a separate
declaration and capture so the command's exit status isn't masked: first declare
"local output" (and optionally "local rc"), then run "output=$(rustpython $lib
2>&1)" and immediately save the exit code with "rc=$?" (or check $?) before any
other commands; use the saved rc when deciding failure handling for the
rustpython invocation.


if grep -q "NO TESTS RAN" <<< "$output"; then
echo "No tests ran in $lib. skipping annotation"
Expand All @@ -142,7 +143,9 @@ annotate_lib() {

echo "Annotating $lib"

local attempts=0
while ! grep -q "Tests result: SUCCESS" <<< "$output"; do
((attempts++))
echo "$lib failing, annotating..."
readarray -t failed_tests <<< $(echo "$output" | awk '/^(FAIL:|ERROR:)/ {print $2}' | sort -u)

Expand All @@ -162,29 +165,31 @@ annotate_lib() {
fi

output=$(rustpython $lib 2>&1)

if [[ attempts -gt 10 ]]; then
echo "Issue annotating $lib"
break;
fi
done
}

files_equal() {
file1=$1
file2=$2
cmp --silent $file1 $file2 && files_equal=0 || files_equal=1
return $files_equal
[[ -f "$1" && -f "$2" ]] && cmp --silent "$1" "$2"
}
Comment on lines +201 to +250
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Declare and assign separately to avoid masking return values.

The combined declaration and assignment on line 204 masks the exit status of rustpython. If rustpython fails catastrophically, you won't detect it.

Also, the 15-attempt limit is reasonable but the logic could still get stuck if tests alternate between different failure modes.

Suggested fix for SC2155
 annotate_lib() {
     local lib=${1//\//.}
     local rlib_path=$2
-    local output=$(rustpython $lib 2>&1)
+    local output
+    output=$(rustpython "$lib" 2>&1)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
annotate_lib() {
local lib=${1//\//.}
local rlib_path=$2
local output=$(rustpython $lib 2>&1)
if grep -q "NO TESTS RAN" <<< "$output"; then
echo "No tests ran in $lib. skipping annotation"
return
fi
echo "Annotating $lib"
local attempts=0
while ! grep -q "Tests result: SUCCESS" <<< "$output"; do
((attempts++))
# echo "$lib failing, annotating..."
readarray -t failed_tests <<< "$(echo "$output" | awk '/^(FAIL:|ERROR:)/ {print $2}' | sort -u)"
# If the test fails/errors, then expectedFailure it
for test in "${failed_tests[@]}"
do
if already_failed $rlib_path $test; then
replace_expected_with_skip $rlib_path $test
else
add_above_test $rlib_path $test "$RUSTPYTHON_CANONICAL_EX_FAILURE"
fi
done
# If the test crashes/hangs, then skip it
if grep -q "\.\.\.$" <<< "$output"; then
crashing_test=$(echo "$output" | grep '\.\.\.$' | head -n 1 | awk '{print $1}')
if grep -q "Timeout" <<< "$output"; then
hanging=true
else
hanging=false
fi
apply_skip "$rlib_path" "$crashing_test" $hanging
fi
output=$(rustpython $lib 2>&1)
if [[ $attempts -gt 15 ]]; then
echo "Issue annotating $lib" >&2
return;
fi
done
echo "Successfully updated $lib"
unset SKIP_BACKUP
}
annotate_lib() {
local lib=${1//\//.}
local rlib_path=$2
local output
output=$(rustpython "$lib" 2>&1)
if grep -q "NO TESTS RAN" <<< "$output"; then
echo "No tests ran in $lib. skipping annotation"
return
fi
echo "Annotating $lib"
local attempts=0
while ! grep -q "Tests result: SUCCESS" <<< "$output"; do
((attempts++))
# echo "$lib failing, annotating..."
readarray -t failed_tests <<< "$(echo "$output" | awk '/^(FAIL:|ERROR:)/ {print $2}' | sort -u)"
# If the test fails/errors, then expectedFailure it
for test in "${failed_tests[@]}"
do
if already_failed $rlib_path $test; then
replace_expected_with_skip $rlib_path $test
else
add_above_test $rlib_path $test "$RUSTPYTHON_CANONICAL_EX_FAILURE"
fi
done
# If the test crashes/hangs, then skip it
if grep -q "\.\.\.$" <<< "$output"; then
crashing_test=$(echo "$output" | grep '\.\.\.$' | head -n 1 | awk '{print $1}')
if grep -q "Timeout" <<< "$output"; then
hanging=true
else
hanging=false
fi
apply_skip "$rlib_path" "$crashing_test" $hanging
fi
output=$(rustpython $lib 2>&1)
if [[ $attempts -gt 15 ]]; then
echo "Issue annotating $lib" >&2
return;
fi
done
echo "Successfully updated $lib"
unset SKIP_BACKUP
}
🧰 Tools
🪛 Shellcheck (0.11.0)

[warning] 204-204: Declare and assign separately to avoid masking return values.

(SC2155)

🤖 Prompt for AI Agents
In @scripts/update_tests.sh around lines 201 - 250, In annotate_lib, avoid
combining declaration and assignment for output (currently local
output=$(rustpython ...)) so the rustpython exit code isn’t masked; instead
declare local output first, run output=$(rustpython $lib 2>&1) and capture its
exit status ($?) immediately, logging and returning on a non-zero catastrophic
failure; also harden the retry loop around attempts by detecting unchanged or
oscillating output (e.g., keep previous_output and if output == previous_output
or it alternates between two states for multiple iterations then abort with an
error) so the while loop can’t hang indefinitely even within the 15-attempt cap.


rustpython() {
cargo run --release --features encodings,sqlite -- -m test -j 1 -u all --fail-env-changed --timeout 300 -v "$@"
cargo run --release --features encodings,sqlite -- -m test -j 1 -u all --fail-env-changed --timeout "$timeout" -v "$@"
}

add_above_test() {
file=$1
test=$2
line=$3
local file=$1
local test=$2
local line=$3
sed -i "s/^\([[:space:]]*\)def $test(/\1$line\n\1def $test(/" "$file"
}

remove_skips() {
rlib_path=$1
local rlib_path=$1

echo "Removing all skips from $rlib_path"

Expand All @@ -197,10 +202,10 @@ if ! $check_skip_flag; then
if [[ ${#libraries[@]} -eq 0 ]]; then
readarray -t libraries <<< $(find ${cpython_path} -type f -printf "%P\n")
fi
update_tests $libraries
update_tests "${libraries[@]}"
else
echo "Checking Skips"

readarray -t libraries <<< $(find ${rpython_path} -iname "test_*.py" -type f -printf "%P\n")
check_skips $libraries
check_skips "${libraries[@]}"
fi