-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcheck_test_parity.sh
More file actions
executable file
·163 lines (148 loc) · 4.14 KB
/
Copy pathcheck_test_parity.sh
File metadata and controls
executable file
·163 lines (148 loc) · 4.14 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
base_ref="${1:-upstream/main}"
head_ref="${2:-HEAD}"
if ! git rev-parse --verify "$base_ref" > /dev/null 2>&1; then
echo "Base ref '$base_ref' not found." >&2
exit 1
fi
if ! git rev-parse --verify "$head_ref" > /dev/null 2>&1; then
echo "Head ref '$head_ref' not found." >&2
exit 1
fi
test_files=()
while IFS= read -r file; do
if [[ -n "$file" ]]; then
test_files+=("$file")
fi
done < <(
git diff --name-only "$base_ref..$head_ref" -- tests | grep -E '\.py$' || true
)
if [[ ${#test_files[@]} -eq 0 ]]; then
echo "No changed test files under tests/ for $base_ref..$head_ref."
exit 0
fi
tmp_output="$(mktemp)"
tmp_tests="$(mktemp)"
tmp_counts="$(mktemp)"
tmp_missing_sync="$(mktemp)"
tmp_missing_async="$(mktemp)"
tmp_payload="$(mktemp)"
trap 'rm -f "$tmp_output" "$tmp_tests" "$tmp_counts" "$tmp_missing_sync" "$tmp_missing_async" "$tmp_payload"' EXIT
echo "Running pytest on changed tests:"
printf ' - %s\n' "${test_files[@]}"
uv run pytest -vv -rA -n auto "${test_files[@]}" | tee "$tmp_output"
awk '
{
line = $0;
sub(/^\[[^]]+\][[:space:]]+/, "", line);
if (line ~ /^(PASSED|FAILED|SKIPPED|XFAIL|XPASS|ERROR)[[:space:]]+tests\/.*::/) {
sub(/^(PASSED|FAILED|SKIPPED|XFAIL|XPASS|ERROR)[[:space:]]+/, "", line);
print line;
} else if (line ~ /^tests\/.*::.*[[:space:]]+(PASSED|FAILED|SKIPPED|XFAIL|XPASS|ERROR)$/) {
sub(/[[:space:]]+(PASSED|FAILED|SKIPPED|XFAIL|XPASS|ERROR)$/, "", line);
print line;
}
}
' "$tmp_output" > "$tmp_tests"
if [[ ! -s "$tmp_tests" ]]; then
echo "No test node IDs detected in pytest output; try rerunning with -vv." >&2
exit 1
fi
awk -v sync_file="$tmp_missing_sync" \
-v async_file="$tmp_missing_async" \
-v payload_file="$tmp_payload" \
-v counts_file="$tmp_counts" '
function is_async(nodeid) {
return (nodeid ~ /::test_.*async_/);
}
function normalize(nodeid) {
sub(/::test_live_async_/, "::test_live_", nodeid);
sub(/::test_async_/, "::test_", nodeid);
return nodeid;
}
{
total++;
if ($0 ~ /::test_.*(payload|validation)/) {
payload_like[$0] = 1;
}
if (is_async($0)) {
async_count++;
norm = normalize($0);
async_norm[norm] = 1;
async_orig[norm] = $0;
} else {
sync_count++;
norm = normalize($0);
sync_norm[norm] = 1;
sync_orig[norm] = $0;
}
}
END {
missing_sync = 0;
missing_async = 0;
for (n in async_norm) {
if (!(n in sync_norm)) {
missing_sync++;
print async_orig[n] >> sync_file;
}
}
for (n in sync_norm) {
if (!(n in async_norm)) {
missing_async++;
print sync_orig[n] >> async_file;
}
}
payload_count = 0;
for (t in payload_like) {
payload_count++;
print t >> payload_file;
}
print "total=" total > counts_file;
print "sync_count=" sync_count >> counts_file;
print "async_count=" async_count >> counts_file;
print "missing_sync=" missing_sync >> counts_file;
print "missing_async=" missing_async >> counts_file;
print "payload_count=" payload_count >> counts_file;
}
' "$tmp_tests"
total=0
sync_count=0
async_count=0
missing_sync=0
missing_async=0
payload_count=0
while IFS='=' read -r key value; do
case "$key" in
total) total="$value" ;;
sync_count) sync_count="$value" ;;
async_count) async_count="$value" ;;
missing_sync) missing_sync="$value" ;;
missing_async) missing_async="$value" ;;
payload_count) payload_count="$value" ;;
esac
done < "$tmp_counts"
echo ""
echo "Test parity report"
echo "Total tests: $total"
echo "Sync tests: $sync_count"
echo "Async tests: $async_count"
echo "Missing sync counterparts: $missing_sync"
if [[ "$missing_sync" -gt 0 ]]; then
sort "$tmp_missing_sync" | while read -r line; do
echo " - $line"
done
fi
echo "Missing async counterparts: $missing_async"
if [[ "$missing_async" -gt 0 ]]; then
sort "$tmp_missing_async" | while read -r line; do
echo " - $line"
done
fi
echo "Payload/validation-style tests (name contains payload/validation): $payload_count"
if [[ "$payload_count" -gt 0 ]]; then
sort "$tmp_payload" | while read -r line; do
echo " - $line"
done
fi