From 1e66c93d1a9c9c90b7dbe072e2abbe19f7abb56d Mon Sep 17 00:00:00 2001 From: Paul Otto <219596+potto007@users.noreply.github.com> Date: Tue, 24 Nov 2026 22:59:36 -0700 Subject: [PATCH 1/3] build: add cargo-mutants profile and config Signed-off-by: Paul Otto <219596+potto007@users.noreply.github.com> Github-Issue: #246 --- .cargo/mutants.toml | 12 ++++++++++++ .gitignore | 2 ++ Cargo.toml | 4 ++++ 3 files changed, 18 insertions(+) create mode 100644 .cargo/mutants.toml diff --git a/.cargo/mutants.toml b/.cargo/mutants.toml new file mode 100644 index 00000000..1b797b0c --- /dev/null +++ b/.cargo/mutants.toml @@ -0,0 +1,12 @@ +examine_globs = [ + "src/reconcile.rs", + "src/wf_pr.rs", + "src/merge.rs", + "src/board.rs", + "src/wf.rs", +] +profile = "mutants" +test_tool = "nextest" +additional_cargo_args = ["--test", "all"] +additional_cargo_test_args = ["-E", "test(/^pr_chaos::/)"] +minimum_test_timeout = 60 diff --git a/.gitignore b/.gitignore index 8569e8d8..e9e79521 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ target/ docs/book/ docs/src/api.md __pycache__/ +mutants.out/ +mutants.out.old/ diff --git a/Cargo.toml b/Cargo.toml index 4e863269..c8d60ae8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -81,3 +81,7 @@ inherits = "release" strip = true lto = "thin" codegen-units = 4 + +[profile.mutants] +inherits = "test" +debug = "none" From 7680bd1b86ba9e47b504d2085f6f104698abf42e Mon Sep 17 00:00:00 2001 From: Paul Otto <219596+potto007@users.noreply.github.com> Date: Tue, 24 Nov 2026 22:59:36 -0700 Subject: [PATCH 2/3] ci: add nightly chaos sweep and mutation grading Signed-off-by: Paul Otto <219596+potto007@users.noreply.github.com> Github-Issue: #246 --- .github/scripts/chaos-sweep.sh | 147 ++++++++++++++++++ .github/scripts/mutants-summary.sh | 32 ++++ .github/scripts/reach-table.sh | 24 +++ .github/workflows/chaos-nightly.yml | 222 ++++++++++++++++++++++++++++ 4 files changed, 425 insertions(+) create mode 100755 .github/scripts/chaos-sweep.sh create mode 100755 .github/scripts/mutants-summary.sh create mode 100755 .github/scripts/reach-table.sh create mode 100644 .github/workflows/chaos-nightly.yml diff --git a/.github/scripts/chaos-sweep.sh b/.github/scripts/chaos-sweep.sh new file mode 100755 index 00000000..cf7648cb --- /dev/null +++ b/.github/scripts/chaos-sweep.sh @@ -0,0 +1,147 @@ +#!/usr/bin/env bash +set -uo pipefail + +bin=$1 +start=$2 +count=$3 +out=$4 +shards=${SHARDS:-$(nproc)} +work_root=${WORK_ROOT:-/dev/shm} + +if [[ ! $count =~ ^[1-9][0-9]{0,8}$ ]]; then + echo "seed count must be a decimal integer from 1 to 999999999, got $count" >&2 + exit 2 +fi +if [[ -z $start ]]; then + start=$(( ${RUN_ID:?set RUN_ID or pass a seed start} % 100000000 * count )) +elif [[ ! $start =~ ^(0|[1-9][0-9]{0,17})$ ]]; then + echo "seed start must be a decimal integer below 10^18, got $start" >&2 + exit 2 +fi +test_name=pr_chaos::seeded_sequential_chaos_holds_all_invariants + +if (( count < shards )); then + shards=$count +fi +chunk=$(( (count + shards - 1) / shards )) + +work=$(mktemp -d "$work_root/chaos-sweep.XXXXXX") +mkdir -p "$out/logs" "$out/failures" + +run_shard() { + local i=$1 s_start=$2 s_count=$3 + mkdir -p "$work/shard-$i" + TMPDIR="$work/shard-$i" CHAOS_SEED_START=$s_start CHAOS_SEEDS=$s_count CHAOS_REACH=1 \ + "$bin" "$test_name" --exact --nocapture --test-threads=1 >"$out/logs/shard-$i.log" 2>&1 +} + +declare -a pids starts counts +for (( i = 0; i < shards; i++ )); do + s_start=$(( start + i * chunk )) + s_count=$(( count - i * chunk < chunk ? count - i * chunk : chunk )) + (( s_count > 0 )) || break + starts[i]=$s_start + counts[i]=$s_count + run_shard "$i" "$s_start" "$s_count" & + pids[i]=$! +done + +failed=() +declare -A shard_failed +for i in "${!pids[@]}"; do + if ! wait "${pids[i]}"; then + failed+=("$i") + shard_failed[$i]=1 + fi +done + +shrink_one() { + local i=$1 + local corpus="$work/corpus-$i" log="$out/logs/shrink-$i.log" seed_env + mkdir -p "$corpus" + local seed + seed=$(grep -m1 -E '^seed=[0-9]+$' "$out/logs/shard-$i.log" | cut -d= -f2) + if [[ -n $seed ]]; then + seed_env=(CHAOS_SEED="$seed") + else + seed_env=(CHAOS_SEED_START="${starts[i]}" CHAOS_SEEDS="${counts[i]}") + fi + env TMPDIR="$work/shard-$i" CHAOS_SHRINK=1 CHAOS_CORPUS_DIR="$corpus" "${seed_env[@]}" \ + "$bin" "$test_name" --exact --nocapture --test-threads=1 >"$log" 2>&1 + local ops + ops=$(find "$corpus" -name '*.ops' -print -quit) + if [[ -z $ops ]]; then + printf "| shard %s | %s | no shrunk .ops written; see \`logs/shrink-%s.log\` |\n" \ + "$i" "${seed:-unknown}" "$i" >>"$work/rows.md" + return + fi + local hash dir + hash=$(basename "$ops" .ops) + dir="$out/failures/$hash" + if [[ -d $dir ]]; then + echo "${seed:-shard $i}" >>"$dir/seeds.txt" + return + fi + mkdir -p "$dir" + cp "$ops" "$dir/$hash.ops" + cp "$log" "$dir/shrink.log" + echo "${seed:-shard $i}" >"$dir/seeds.txt" + env TMPDIR="$work/shard-$i" CHAOS_OPS="$dir/$hash.ops" \ + "$bin" "$test_name" --exact --nocapture --test-threads=1 >"$dir/trace.log" 2>&1 + local class + class=$(grep -m1 '^failure class:' "$log" | sed 's/^failure class: *//') + printf "| \`%s\` | %s | %s |\n" "$hash" "${seed:-unknown}" "${class:-unknown}" >>"$work/rows.md" +} + +for i in "${failed[@]}"; do + shrink_one "$i" +done + +{ + echo "## Swarm sweep" + echo + end=$(( start + count - 1 )) + echo "Seeds \`$start..=$end\` ($count seeds) across $shards shards${CHAOS_SENTINEL:+, sentinel \`$CHAOS_SENTINEL\`}." + echo + if (( ${#failed[@]} == 0 )); then + echo "All shards passed." + else + echo "${#failed[@]} shard(s) failed. Each shrunk failure is in the \`chaos-failures\` artifact under \`/\`." + echo + echo "| .ops hash | seed | failure class |" + echo "| --- | --- | --- |" + cat "$work/rows.md" 2>/dev/null + echo + echo "Unpack the artifact in the repository root and replay one:" + echo + first=$(find "$out/failures" -name '*.ops' -print -quit) + ops_file="${first:+$(basename "$(dirname "$first")")/$(basename "$first")}" + ops_file=${ops_file:-HASH.ops} + echo '```sh' + if [[ -n ${CHAOS_SENTINEL:-} ]]; then + echo "CHAOS_OPS=$ops_file CHAOS_SENTINEL=$CHAOS_SENTINEL cargo test --locked --features test-sentinels --test all pr_chaos::seeded_sequential_chaos_holds_all_invariants -- --exact --nocapture" + else + echo "CHAOS_OPS=$ops_file cargo test --locked --test all pr_chaos::seeded_sequential_chaos_holds_all_invariants -- --exact --nocapture" + fi + echo '```' + fi + echo + echo "### Reach hit rates" + echo + echo "Hits summed over the passing shards, per 1,000 seeds." + echo + passed_seeds=0 + passed_logs=() + for i in "${!pids[@]}"; do + if [[ -z ${shard_failed[$i]:-} ]]; then + passed_seeds=$(( passed_seeds + counts[i] )) + passed_logs+=("$out/logs/shard-$i.log") + fi + done + if (( ${#passed_logs[@]} > 0 )); then + "$(dirname "$0")/reach-table.sh" "$passed_seeds" "${passed_logs[@]}" + fi +} >"$out/summary.md" + +rm -rf "$work" +(( ${#failed[@]} == 0 )) diff --git a/.github/scripts/mutants-summary.sh b/.github/scripts/mutants-summary.sh new file mode 100755 index 00000000..1d8b4a75 --- /dev/null +++ b/.github/scripts/mutants-summary.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash +set -euo pipefail + +shards_dir=$1 +out=$2 +mkdir -p "$out" + +for kind in caught missed timeout unviable; do + find "$shards_dir" -name "$kind.txt" -exec cat {} + 2>/dev/null | sort -u >"$out/$kind.txt" +done + +count() { grep -c . "$1" || true; } + +{ + echo "## Mutation grading" + echo + echo "cargo-mutants over the files in \`.cargo/mutants.toml\`, graded by the \`pr_chaos\` tests." + echo + echo "| file | caught | missed | timeout | unviable |" + echo "| --- | ---: | ---: | ---: | ---: |" + cut -d: -f1 "$out"/{caught,missed,timeout,unviable}.txt | sort -u | while read -r file; do + [[ -n $file ]] || continue + row="| \`$file\`" + for kind in caught missed timeout unviable; do + row+=" | $(grep -c "^$file:" "$out/$kind.txt" || true)" + done + echo "$row |" + done + echo "| **total** | $(count "$out/caught.txt") | $(count "$out/missed.txt") | $(count "$out/timeout.txt") | $(count "$out/unviable.txt") |" + echo + echo "Survivors are listed in \`missed.txt\` and \`timeout.txt\` in the \`mutants-survivors\` artifact." +} >"$out/summary.md" diff --git a/.github/scripts/reach-table.sh b/.github/scripts/reach-table.sh new file mode 100755 index 00000000..f6e89d7b --- /dev/null +++ b/.github/scripts/reach-table.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash +set -euo pipefail + +seeds=$1 +shift + +echo "| tier | point | hits | per 1k seeds |" +echo "| --- | --- | ---: | ---: |" +awk -v seeds="$seeds" ' + /Reach summary:$/ { in_reach = 1; next } + in_reach && /^ \[T[12]\] / { + tier = substr($1, 2, 2); name = $2; hits[name] += $3; tiers[name] = tier + if (!(name in order)) { order[name] = ++n; names[n] = name } + next + } + in_reach { in_reach = 0 } + END { + for (k = 1; k <= n; k++) { + name = names[k] + rate = seeds > 0 ? hits[name] * 1000 / seeds : 0 + flag = hits[name] == 0 ? " **(never hit)**" : "" + printf "| %s | `%s`%s | %d | %.2f |\n", tiers[name], name, flag, hits[name], rate + } + }' "$@" diff --git a/.github/workflows/chaos-nightly.yml b/.github/workflows/chaos-nightly.yml new file mode 100644 index 00000000..544ab6eb --- /dev/null +++ b/.github/workflows/chaos-nightly.yml @@ -0,0 +1,222 @@ +name: chaos-nightly + +on: + schedule: + - cron: "23 9 * * *" + workflow_dispatch: + inputs: + seeds: + description: Sequential Swarm seeds to sweep + type: string + default: "200000" + seed_start: + description: First seed (empty derives it from the run ID) + type: string + default: "" + sentinel: + description: Planted sentinel to enable in the sweep (builds with test-sentinels, so the sweep fails on purpose) + type: choice + default: none + options: + - none + - board_card_wipes_ready + - close_keeps_gate + - gate_clear_wipes_other_ready + - reconcile_skips_independent_pr_seen + - outbox_no_purge + mutants: + description: Run the cargo-mutants grading + type: boolean + default: true + +permissions: + contents: read + +concurrency: + group: chaos-nightly-${{ github.ref }} + cancel-in-progress: false + +defaults: + run: + shell: bash + +env: + CARGO_TERM_COLOR: always + RUSTFLAGS: -C link-arg=-fuse-ld=mold + +jobs: + sweep: + name: swarm sweep + runs-on: ubuntu-latest + timeout-minutes: 120 + env: + SEEDS: ${{ inputs.seeds || '200000' }} + SEED_START: ${{ inputs.seed_start }} + CHAOS_SENTINEL: ${{ inputs.sentinel != 'none' && inputs.sentinel || '' }} + steps: + - uses: actions/checkout@v7 + with: + persist-credentials: false + - uses: dtolnay/rust-toolchain@683b588c487a69d01f6c6ddf40f036ff682cc2c8 # stable as of 2026-10-16 + with: + toolchain: stable + - name: Install mold + run: sudo apt-get update && sudo apt-get install -y mold + - uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2.9.3 + with: + key: chaos-sweep + - name: Build the release test binary + id: build + run: | + features=() + if [ -n "$CHAOS_SENTINEL" ]; then + features=(--features test-sentinels) + fi + bin=$(cargo test --release --locked "${features[@]}" --test all --no-run --message-format=json \ + | jq -r 'select(.executable != null and .target.name == "all") | .executable') + test -x "$bin" + echo "bin=$bin" >> "$GITHUB_OUTPUT" + - name: Sweep + env: + BIN: ${{ steps.build.outputs.bin }} + RUN_ID: ${{ github.run_id }} + run: .github/scripts/chaos-sweep.sh "$BIN" "$SEED_START" "$SEEDS" chaos-out + - name: Job summary + if: always() + run: | + if [ -f chaos-out/summary.md ]; then + cat chaos-out/summary.md >> "$GITHUB_STEP_SUMMARY" + fi + - uses: actions/upload-artifact@v7 + if: always() + with: + name: chaos-sweep-logs + path: chaos-out/logs/ + if-no-files-found: ignore + retention-days: 14 + - uses: actions/upload-artifact@v7 + if: failure() + with: + name: chaos-failures + path: chaos-out/failures/ + if-no-files-found: ignore + retention-days: 30 + + coverage: + name: coverage and reach + runs-on: ubuntu-latest + timeout-minutes: 60 + steps: + - uses: actions/checkout@v7 + with: + persist-credentials: false + - uses: dtolnay/rust-toolchain@683b588c487a69d01f6c6ddf40f036ff682cc2c8 # stable as of 2026-10-16 + with: + toolchain: stable + components: llvm-tools-preview + - name: Install mold + run: sudo apt-get update && sudo apt-get install -y mold + - uses: taiki-e/install-action@3a3daafd3b7f23b8f65d9f5ba2db203fb59b79e2 # v2.90.2 + with: + tool: cargo-llvm-cov@0.9.1 + - uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2.9.3 + with: + key: chaos-coverage + - name: Run pr_chaos under coverage + env: + CHAOS_REACH: "1" + run: | + mkdir -p coverage + cargo llvm-cov --locked --test all --no-report -- pr_chaos:: --nocapture 2>&1 | tee coverage/pr_chaos.log + - name: Report + run: | + cargo llvm-cov report --summary-only | tee coverage/summary.txt + cargo llvm-cov report --lcov --output-path coverage/lcov.info + { + echo "## Coverage of src/ by pr_chaos" + echo + echo "cargo-llvm-cov line and region coverage on stable Rust." + echo + echo '```text' + cat coverage/summary.txt + echo '```' + echo + echo "## Reach hit rates (default seeds)" + echo + .github/scripts/reach-table.sh 60 coverage/pr_chaos.log + } >> "$GITHUB_STEP_SUMMARY" + - uses: actions/upload-artifact@v7 + if: always() + with: + name: chaos-coverage + path: coverage/ + if-no-files-found: ignore + retention-days: 14 + + mutants: + name: mutants (${{ matrix.shard }}/8) + if: github.event_name == 'schedule' || inputs.mutants + runs-on: ubuntu-latest + timeout-minutes: 300 + strategy: + fail-fast: false + matrix: + shard: [0, 1, 2, 3, 4, 5, 6, 7] + steps: + - uses: actions/checkout@v7 + with: + persist-credentials: false + - uses: dtolnay/rust-toolchain@683b588c487a69d01f6c6ddf40f036ff682cc2c8 # stable as of 2026-10-16 + with: + toolchain: stable + - name: Install mold + run: sudo apt-get update && sudo apt-get install -y mold + - uses: taiki-e/install-action@3a3daafd3b7f23b8f65d9f5ba2db203fb59b79e2 # v2.90.2 + with: + tool: cargo-mutants@27.1.0,cargo-nextest@0.9.151 + - uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2.9.3 + with: + key: chaos-mutants + save-if: ${{ matrix.shard == 0 }} + - name: Grade + env: + SHARD: ${{ matrix.shard }} + run: | + set +e + cargo mutants --in-place --shard "$SHARD/8" --output "mutants-$SHARD" + code=$? + set -e + case $code in + 0|2|3) ;; + *) echo "cargo-mutants exited $code"; exit "$code" ;; + esac + - uses: actions/upload-artifact@v7 + if: always() + with: + name: mutants-shard-${{ matrix.shard }} + path: mutants-${{ matrix.shard }}/mutants.out/ + if-no-files-found: ignore + retention-days: 14 + + mutants-report: + name: mutants report + needs: mutants + if: needs.mutants.result == 'success' + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v7 + with: + persist-credentials: false + - uses: actions/download-artifact@v8 + with: + pattern: mutants-shard-* + path: shards + - name: Summarize + run: | + .github/scripts/mutants-summary.sh shards mutants-survivors + cat mutants-survivors/summary.md >> "$GITHUB_STEP_SUMMARY" + - uses: actions/upload-artifact@v7 + with: + name: mutants-survivors + path: mutants-survivors/ + retention-days: 30 From a25179f45faa3543d93216f9a6b921f6b2441b53 Mon Sep 17 00:00:00 2001 From: Paul Otto <219596+potto007@users.noreply.github.com> Date: Tue, 24 Nov 2026 22:59:36 -0700 Subject: [PATCH 3/3] docs: describe the nightly chaos workflow Signed-off-by: Paul Otto <219596+potto007@users.noreply.github.com> Github-Issue: #246 --- docs/src/contributing.md | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/docs/src/contributing.md b/docs/src/contributing.md index 15c5fcc0..f9e389ac 100644 --- a/docs/src/contributing.md +++ b/docs/src/contributing.md @@ -77,6 +77,43 @@ under `tests/chaos_corpus/` during plain `cargo test --locked`. The NDJSON loader ignores blank lines and `#` comment lines, so a file can carry `# source:` and `# failure:` headers above its ops. +### Nightly chaos + +`.github/workflows/chaos-nightly.yml` runs every night on Linux, and on demand +from the Actions tab. It has three parts: + +- **Swarm sweep.** 200,000 sequential seeds in a release build, split across + the runner's cores with each shard's temporary files on `/dev/shm`. The first + seed is the last eight digits of the run ID times the seed count, so runs + sweep different ranges until those digits repeat. A + failing shard's seed is shrunk with `CHAOS_SHRINK=1`, and the + `chaos-failures` artifact holds one `/` folder per distinct + shrunk `.ops` file. Each folder has the `.ops` file, the shrink log, a replay + trace and the seeds that shrank to it. The job summary lists each hash and + the `Reach` hit rates per 1,000 seeds. +- **Coverage and reach.** `cargo-llvm-cov` line and region coverage of `src/` + by the `pr_chaos` tests, with the text summary and the `Reach` table in the + job summary and an `lcov.info` in the `chaos-coverage` artifact. +- **Mutation grading.** `cargo-mutants`, configured in `.cargo/mutants.toml`, + mutates `src/reconcile.rs`, `src/wf_pr.rs`, `src/merge.rs`, `src/board.rs` + and `src/wf.rs` and grades each mutant with the `pr_chaos` tests only, so a + survivor is a change the chaos oracle does not notice. Eight shards run in + parallel, and the `mutants-survivors` artifact collects `missed.txt` and + `timeout.txt`. + +A dispatch can set the seed count, the first seed, and a planted sentinel. A +sentinel builds with `test-sentinels`, so the sweep fails on purpose and shows +the shrink path working. To promote a failure, download its `.ops` file, check +that it replays, and commit it under `tests/chaos_corpus/` with the fix: + +```bash +CHAOS_OPS=.ops cargo test --locked --test all pr_chaos::seeded_sequential_chaos_holds_all_invariants -- --exact --nocapture +``` + +The workflow does not file issues. A later job could read the hashes from the +`chaos-failures` artifact and open or comment on one tracking issue per hash, +with `issues: write` granted to that job alone. + ## This site `docs/build.sh` generates the [API reference](api.md) page from `t3cm types`,