Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
117 changes: 117 additions & 0 deletions .github/scripts/check-crash-gate-coverage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
#!/usr/bin/env bash
# Guard the crash-gate PR partition against silent coverage loss (#1635).
#
# PR #1310 split the aggregate `crash-gate` recipe into four PR checks
# partitioned by test-name filter (pkgs/id/justfile): crash-gate-sampled
# runs WITHOUT --include-ignored, and crash-gate-sweep / -control /
# -ingest each run exactly ONE `--include-ignored <substring>` filter.
# An #[ignore]d test in pkgs/id/tests/crash/ therefore gets PR coverage
# only if its name contains one of those substrings; the partition is
# complete today but nothing checked it, so a future ignored crash test
# matching no split would silently run in no PR check at all — only the
# nightly aggregate would ever execute it.
#
# This script makes the partition a checked invariant, at source level
# (no cargo build, so it can run in the id-check.yml guard job):
#
# 1. enumerate the #[ignore]d test names in pkgs/id/tests/crash/*.rs
# 2. subtract the named corpus-writer exclusions below — they rewrite
# the checked-in corpus files and are run by hand, never in CI
# 3. extract the split filters from the justfile's crash-gate-sweep /
# -control / -ingest recipes
# 4. fail, naming each test, when an ignored gate test contains none
# of the filter substrings
#
# Parse drift is a failure too: finding no filters or no ignored tests
# means the inputs changed shape, and a guard that silently passes on
# empty input is the failure this script exists to prevent.
set -euo pipefail

repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
crash_dir="$repo_root/pkgs/id/tests/crash"
justfile="$repo_root/pkgs/id/justfile"

excluded=(write_corpus write_corpus_identity)

# --- split filters from the justfile recipes -------------------------------
filters=()
for recipe in crash-gate-sweep crash-gate-control crash-gate-ingest; do
filter="$(
awk -v header="^${recipe}:" '
$0 ~ header { in_recipe = 1; next }
in_recipe && /--include-ignored/ {
for (i = 1; i <= NF; i++) {
if ($i == "--include-ignored") { print $(i + 1); exit }
}
}
' "$justfile"
)"
if [[ -z $filter ]]; then
echo "::error::check-crash-gate-coverage: no --include-ignored filter found in the '$recipe' recipe in pkgs/id/justfile — the guard cannot verify the partition; update the recipe or this script."
exit 1
fi
filters+=("$filter")
done

# --- #[ignore]d test names from the crash suite ----------------------------
# An ignored test is declared as a #[ignore ...] attribute line followed
# (after any further attribute/doc lines) by `fn <name>(`. Names repeat
# across files (main.rs and identity.rs carry copies); coverage is by
# name, so deduplicate.
ignored_tests="$(
awk '
/#\[ignore/ { ignored = 1; next }
ignored && /^#\[/ { next }
ignored && /^\/\/\// { next }
ignored && /^fn [A-Za-z0-9_]+/ {
Comment on lines +64 to +66

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Recognize indented ignored tests in nested modules

When an ignored crash test is inside a nested module, its normally indented fn declaration does not match this column-zero regex, so the parser silently discards it. This layout already exists in pkgs/id/tests/crash/faultfs.rs: adding #[ignore] to its unsynced_writes_are_dropped_at_a_power_cut test in a temporary fixture leaves the guard passing with the same three covered names, although that test matches none of the split filters and would lose PR coverage. The nonempty-input check cannot detect this because the other ignored tests still parse. Accept leading whitespace on function and intervening attribute/doc lines so nested tests participate in the coverage check.

Useful? React with 👍 / 👎.

name = $2
sub(/\(.*/, "", name)
print name
ignored = 0
next
}
ignored { ignored = 0 }
' "$crash_dir"/*.rs | sort -u
)"

if [[ -z $ignored_tests ]]; then
echo "::error::check-crash-gate-coverage: no #[ignore]d tests found in pkgs/id/tests/crash/*.rs — the suite changed shape; update this guard."
exit 1
fi

# --- coverage ----------------------------------------------------------------
uncovered=()
covered=0
while IFS= read -r name; do
skip=0
for ex in "${excluded[@]}"; do
if [[ $name == "$ex" ]]; then
skip=1
break
fi
done
if [[ $skip -eq 1 ]]; then
continue
fi
hit=0
for filter in "${filters[@]}"; do
if [[ $name == *"$filter"* ]]; then
hit=1
break
fi
done
if [[ $hit -eq 1 ]]; then
covered=$((covered + 1))
else
uncovered+=("$name")
fi
done <<<"$ignored_tests"

if [[ ${#uncovered[@]} -ne 0 ]]; then
for name in "${uncovered[@]}"; do
echo "::error::#[ignore]d crash test '$name' matches none of the crash-gate PR split filters (${filters[*]}) — it would run in no PR check. Rename it to contain a split filter, extend a split in pkgs/id/justfile, or add it to the exclusion list in check-crash-gate-coverage.sh if it is a corpus writer."
done
exit 1
fi

echo "crash-gate partition covers all $covered #[ignore]d gate tests (${#excluded[@]} corpus writers excluded: ${excluded[*]})."
4 changes: 4 additions & 0 deletions .github/scripts/check-id-pr-checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
# The aggregate `crash-gate` is likewise covered by composition on
# PRs: crash-gate-sampled/-sweep/-control/-ingest partition its tests
# by name filter (#551). They still run in the nightly full flake check.
# That partition is a checked invariant, not just prose:
# check-crash-gate-coverage.sh runs in the same guard job and fails,
# naming the test, when an #[ignore]d crash test matches none of the
# split filters (#1635).
#
# Usage: check-id-pr-checks.sh [list-file]
# For tests, ID_FLAKE_CHECKS_FILE names a file with one flake check
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/id-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,14 @@ on:
- ".github/workflows/id-check.yml"
- ".github/scripts/id-pr-checks.txt"
- ".github/scripts/check-id-pr-checks.sh"
- ".github/scripts/check-crash-gate-coverage.sh"
pull_request:
paths:
- "pkgs/id/**"
- ".github/workflows/id-check.yml"
- ".github/scripts/id-pr-checks.txt"
- ".github/scripts/check-id-pr-checks.sh"
- ".github/scripts/check-crash-gate-coverage.sh"

permissions:
contents: read
Expand Down Expand Up @@ -93,6 +95,12 @@ jobs:
- name: Guard PR check list against flake drift
run: .github/scripts/check-id-pr-checks.sh

# The crash-gate composition asserted in check-id-pr-checks.sh is
# itself checked (#1635): an #[ignore]d crash test matching none
# of the PR split filters fails here by name.
- name: Guard crash-gate PR partition coverage
run: .github/scripts/check-crash-gate-coverage.sh

- name: Emit PR check list for the matrix
id: list
run: |
Expand Down
4 changes: 4 additions & 0 deletions pkgs/id/justfile
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,10 @@ crash-gate:
# in parallel; together with the nightly full `crash-gate` they cover
# every test crash-gate runs. write_corpus / write_corpus_identity stay
# excluded everywhere (they rewrite the checked-in corpus files).
# The partition is guarded by .github/scripts/check-crash-gate-coverage.sh
# (#1635): a future #[ignore]d crash test matching none of the three split
# filters below fails the id PR guard job by name instead of silently
# losing all PR coverage.
[group('test')]
crash-gate-sampled:
cargo test --release --features web --test crash -- --skip write_corpus
Expand Down
Loading