@@ -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)"
0 commit comments