Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

ci(rust-coverage): run nextest suites sequentially and preserve partial coverage

Steven Enamakel3b0d049a4c4a
diff --git a/scripts/ci/rust-coverage.sh b/scripts/ci/rust-coverage.sh
index f96cb13ca9..566fae6346 100755
--- a/scripts/ci/rust-coverage.sh
+++ b/scripts/ci/rust-coverage.sh
@@ -33,19 +33,33 @@ llvm_cov() {
bash scripts/ci-cancel-aware.sh cargo llvm-cov "$@"
;;
*)
- bash scripts/ci-cancel-aware.sh cargo llvm-cov \
- --features "${CORE_PRODUCT_FEATURES}" "$@"
+ if [ "${OH_COV_RUNNER:-cargo}" = "nextest" ]; then
+ bash scripts/ci-cancel-aware.sh cargo llvm-cov nextest --profile ci --no-tests=fail \
+ --features "${CORE_PRODUCT_FEATURES}" "$@"
+ else
+ bash scripts/ci-cancel-aware.sh cargo llvm-cov \
+ --features "${CORE_PRODUCT_FEATURES}" "$@"
+ fi
;;
esac
}
llvm_cov_package() {
- bash scripts/ci-cancel-aware.sh cargo llvm-cov "$@"
+ if [ "${OH_COV_RUNNER:-cargo}" = "nextest" ]; then
+ bash scripts/ci-cancel-aware.sh cargo llvm-cov nextest --profile ci --no-tests=fail "$@"
+ else
+ bash scripts/ci-cancel-aware.sh cargo llvm-cov "$@"
+ fi
}
llvm_cov_product_facade() {
- bash scripts/ci-cancel-aware.sh cargo llvm-cov \
- --features "${CORE_PRODUCT_FEATURES}" "$@"
+ if [ "${OH_COV_RUNNER:-cargo}" = "nextest" ]; then
+ bash scripts/ci-cancel-aware.sh cargo llvm-cov nextest --profile ci --no-tests=fail \
+ --features "${CORE_PRODUCT_FEATURES}" "$@"
+ else
+ bash scripts/ci-cancel-aware.sh cargo llvm-cov \
+ --features "${CORE_PRODUCT_FEATURES}" "$@"
+ fi
}
llvm_cov_embed() {
@@ -182,41 +196,27 @@ fi
log "running complete instrumented Rust suite (runner: ${OH_COV_RUNNER:-cargo})"
llvm_cov clean --workspace
-UNIT_PID=""
+# Keep the private invocations sequential in the configured coverage target.
+# Each package retains its own feature resolution; instrumentation is merged
+# once after all suites, including successful suites before a failure.
+COVERAGE_REPORTED=0
+preserve_coverage() {
+ local status=$?
+ trap - EXIT INT TERM HUP
+ if [ "${COVERAGE_REPORTED}" = "0" ]; then
+ log "preserving partial coverage into ${OUT} (exit ${status})"
+ CI_CANCEL_WATCHDOG=0 llvm_cov report --lcov --output-path "${OUT}" || \
+ log "partial coverage report unavailable; retaining raw profiles"
+ fi
+ exit "${status}"
+}
+trap preserve_coverage EXIT
+trap 'exit 130' INT
+trap 'exit 143' TERM HUP
+
if [ "${OH_COV_RUNNER:-cargo}" = "nextest" ]; then
- # cargo-nextest runs every test in its own process, in parallel. Process
- # globals (the event bus, registries, env vars, one-shot OnceLocks) are then
- # per test, so the serial runner and the isolated reaper run below are not
- # needed: every test is isolated. Settings: .config/nextest.toml [profile.ci].
- #
- # The core's unit tests compile the core as a test program; every other suite
- # below compiles it as a library. Neither build needs the other, so the unit
- # tests run in the background in a target dir of their own (one cargo per
- # target dir; a shared one would serialize them on its lock) and write their
- # own lcov file, beside this run's. Each invocation keeps exactly the package
- # selection, and so the feature resolution, it has when run alone.
- UNIT_TARGET_DIR="${CARGO_TARGET_DIR:-${PWD}/target}/cov-unit"
- UNIT_OUT="${OUT%.info}-unit.info"
- UNIT_LOG="${OUT%.info}-unit.log"
- UNIT_STATUS="${OUT%.info}-unit.status"
- rm -f "${UNIT_OUT}" "${UNIT_STATUS}"
- (
- export CARGO_TARGET_DIR="${UNIT_TARGET_DIR}"
- rc=0
- llvm_cov clean --workspace || rc=$?
- if [ "${rc}" = 0 ]; then
- llvm_cov nextest --profile ci --no-report --no-fail-fast -p openhuman --lib --bins || rc=$?
- fi
- case "${rc}" in 130 | 143) ;; *)
- report_rc=0
- llvm_cov report --lcov --output-path "${UNIT_OUT}" || report_rc=$?
- [ "${rc}" != 0 ] || rc="${report_rc}"
- ;;
- esac
- echo "${rc}" >"${UNIT_STATUS}"
- ) >"${UNIT_LOG}" 2>&1 &
- UNIT_PID=$!
- log "core unit tests started in the background (pid ${UNIT_PID}, target ${UNIT_TARGET_DIR}, log ${UNIT_LOG})"
+ # One process per test isolates process globals without separate target dirs.
+ suite "openhuman lib+bins (nextest)" llvm_cov --no-report --no-fail-fast -p openhuman --lib --bins
else
# Keep the aggregate unit-test process aligned with the canonical Rust runner.
# The isolated reaper test installs one-shot process globals, so it cannot run
@@ -235,6 +235,12 @@ fi
suite "openhuman-embed" llvm_cov_embed --no-report --no-fail-fast -p openhuman-embed --all-targets
suite "openhuman-rpc" llvm_cov_package --no-report --no-fail-fast -p openhuman-rpc --all-targets
suite "openhuman-tinyhumans" llvm_cov_product_facade --no-report --no-fail-fast -p openhuman-tinyhumans --all-targets
+if [ "${OH_COV_RUNNER:-cargo}" = "nextest" ]; then
+ # Contributor/default features are distinct from product features. Keep both
+ # configurations instrumented rather than dropping the default-only surface.
+ suite "openhuman-embed (default)" llvm_cov_package --no-report --no-fail-fast -p openhuman-embed --all-targets
+ suite "openhuman-tinyhumans (default)" llvm_cov_package --no-report --no-fail-fast -p openhuman-tinyhumans --all-targets
+fi
# The terminal frontend builds the core a third time (default features, not the
# product set). It is on by default and on in the PR lane; OH_COV_TUI=0 is an
# opt-out for local runs.
@@ -250,7 +256,7 @@ if [ "${OH_COV_RUNNER:-cargo}" = "nextest" ]; then
# other without the per-module and serial invocations below. Cargo skips a
# target whose required-features are not in the product set; `kind(test)`
# keeps the run to the integration targets, as the loop below runs them.
- suite "openhuman-cli integration tests (nextest)" llvm_cov nextest --profile ci \
+ suite "openhuman-cli integration tests (nextest)" llvm_cov \
--no-report --no-fail-fast -p openhuman-cli --tests -E 'kind(test)'
else
while IFS= read -r target; do
@@ -274,20 +280,7 @@ fi
log "merging coverage into ${OUT}"
suite "lcov report" llvm_cov report --lcov --output-path "${OUT}"
-presence_lcov="${OUT}"
-if [ -n "${UNIT_PID}" ]; then
- log "waiting for the core unit tests (pid ${UNIT_PID})"
- wait "${UNIT_PID}" || true
- echo "::group::[ci][rust-cov] core unit tests (nextest, background)"
- cat "${UNIT_LOG}"
- echo "::endgroup::"
- unit_rc="$(cat "${UNIT_STATUS}" 2>/dev/null || echo 1)"
- suite "openhuman lib+bins (nextest)" test "${unit_rc}" = 0 || true
- case "${unit_rc}" in 130 | 143) exit "${unit_rc}" ;; esac
- # One file for the presence gate; diff-cover reads both lcov files itself.
- presence_lcov="${OUT%.info}.presence"
- cat "${OUT}" "${UNIT_OUT}" >"${presence_lcov}" 2>/dev/null || true
-fi
+COVERAGE_REPORTED=1
# A full product build must produce records for every eligible source file,
# except in the crates whose suites this run skipped (OH_COV_TUI=0).
@@ -295,8 +288,7 @@ presence_skip=""
[ "${OH_COV_TUI:-1}" = "1" ] || presence_skip="crates/openhuman-tui/src/"
[ -z "${presence_skip}" ] || log "coverage presence: not checking ${presence_skip} (suite skipped)"
suite "coverage presence" env COVERAGE_PRESENCE_SKIP_PREFIXES="${presence_skip}" \
- bash scripts/ci/assert-coverage-presence.sh "${presence_lcov}" --all
-[ "${presence_lcov}" = "${OUT}" ] || rm -f "${presence_lcov}"
+ bash scripts/ci/assert-coverage-presence.sh "${OUT}" --all
if [ "${#FAILED_SUITES[@]}" -gt 0 ]; then
log "${#FAILED_SUITES[@]} suite(s) failed:"