Skip to content

Commit c2f09d1

Browse files
committed
fix(ci): escape catch2 shard filters
- 对 shard 与二分过滤器中的 Catch2 测试名进行语法转义 - 添加逗号测试名回归检查 Signed-off-by: Fernandez <yuanhaon81@gmail.com>
1 parent ba3a2bf commit c2f09d1

2 files changed

Lines changed: 31 additions & 4 deletions

File tree

.github/workflows/nightly-build-test-sophon.yml

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,17 @@ jobs:
320320
require_pos_int COSMO_CATCH2_SHARD_TIMEOUT_SECONDS "$shard_timeout_seconds"
321321
require_pos_int COSMO_TEST_CASE_TIMEOUT_SECONDS "$case_timeout_seconds"
322322
323+
# --input-file parses each line as a Catch2 test specification. Escape
324+
# grammar characters so punctuation in a literal test name (notably
325+
# commas) cannot turn the generated filter into an invalid spec.
326+
write_catch2_test_spec() {
327+
local escaped="$1"
328+
escaped="${escaped//\\/\\\\}"
329+
escaped="${escaped//,/\\,}"
330+
escaped="${escaped//\"/\\\"}"
331+
printf '"%s"\n' "$escaped"
332+
}
333+
323334
# self-hosted runner 工作目录跨 run 复用,历史 run 的 bisect/shards 文件会累积,
324335
# 被 Upload step 整个目录打包上传,新旧混杂干扰诊断。每次 run 开始清空这两个目录。
325336
rm -rf "$shards_dir" "$bisect_dir"
@@ -403,12 +414,19 @@ jobs:
403414
n=${#shard_tests[@]}
404415
shards_run=$((shards_run + 1))
405416
417+
filter="$shards_dir/$idx.filter"
418+
: > "$filter"
419+
for name in "${shard_tests[@]}"; do
420+
[ -n "$name" ] || continue
421+
write_catch2_test_spec "$name" >> "$filter"
422+
done
423+
406424
echo
407425
echo "[$idx] shard with $n tests"
408426
409427
start_seconds="$(date +%s)"
410428
timeout --kill-after=10s "${shard_timeout_seconds}s" \
411-
./cosmo-tests --input-file "$input" --reporter "$reporter" \
429+
./cosmo-tests --input-file "$filter" --reporter "$reporter" \
412430
--warn UnmatchedTestSpec \
413431
> "$log" 2>&1
414432
status=$?
@@ -438,8 +456,8 @@ jobs:
438456
done
439457
440458
# 4) For any shard that timed out or crashed, re-run its tests one-per-process to
441-
# pinpoint the culprit. Single-spec here, so NoTestsRunExitCode=2 already
442-
# catches a no-match; --warn UnmatchedTestSpec kept for parity.
459+
# pinpoint the culprit. Use the same literal-name escaping as the shard run;
460+
# --warn UnmatchedTestSpec still catches a no-match.
443461
if [ "${#bisect_targets[@]}" -gt 0 ]; then
444462
echo
445463
echo "Bisecting ${#bisect_targets[@]} shard(s) per-test (${case_timeout_seconds}s/case)."
@@ -456,7 +474,7 @@ jobs:
456474
safe_name="${safe_name:-test}"
457475
log_file="$bisect_dir/${idx}_$(printf '%03d' "$number")_${safe_name}.log"
458476
filter_file="$bisect_dir/${idx}_$(printf '%03d' "$number")_${safe_name}.filter"
459-
printf '%s\n' "$name" > "$filter_file"
477+
write_catch2_test_spec "$name" > "$filter_file"
460478
461479
echo "[bisect #$idx $number/${#shard_tests[@]}] $name"
462480
start_seconds="$(date +%s)"

test/test_package_profile.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,15 @@ def test_nightly_sophon_build_retries_cargo_downloads(self) -> None:
178178
self.assertIn('CARGO_HTTP_TIMEOUT: "120"', build_job)
179179
self.assertIn('CARGO_NET_RETRY: "5"', build_job)
180180

181+
def test_nightly_sophon_escapes_generated_catch2_filters(self) -> None:
182+
workflow = (
183+
REPOSITORY / ".github/workflows/nightly-build-test-sophon.yml"
184+
).read_text(encoding="utf-8")
185+
186+
self.assertIn("write_catch2_test_spec()", workflow)
187+
self.assertIn('escaped="${escaped//,/\\\\,}"', workflow)
188+
self.assertEqual(workflow.count('write_catch2_test_spec "$name"'), 2)
189+
181190
def test_container_builds_bound_and_cache_npm_connections(self) -> None:
182191
npmrc = (REPOSITORY / "src/web/.npmrc").read_text(encoding="utf-8")
183192
self.assertIn("registry=https://registry.npmmirror.com/", npmrc)

0 commit comments

Comments
 (0)