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
56 changes: 56 additions & 0 deletions .github/workflows/mutation-audit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Mutation pool audit

on:
schedule:
- cron: '0 6 * * 1'
workflow_dispatch:

permissions:
contents: read

jobs:
full_pool:
name: Full pool
uses: $/.github/workflows/mutation.yml
with:
test-group: full
test-selection: full
test-order: collection
full-source: true
fast_pool:
name: Fast pool
uses: $/.github/workflows/mutation.yml
with:
test-group: fast
test-selection: coverage
full-source: true
compare:
name: Compare full and fast pools
needs: [full_pool, fast_pool]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
with:
version: '0.13.9'
- uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
with:
python-version: '3.13'
- run: npm ci
- run: uv sync --locked --all-groups --extra binary
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
pattern: mutation-report-*-full-shard-*
path: coverage/parity/full
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
pattern: mutation-report-*-fast-shard-*
path: coverage/parity/fast
- run: uv run --locked python -m tests.compare_mutations coverage/parity/full coverage/parity/fast > coverage/parity/comparison.json
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
if: always()
with:
name: mutation-pool-comparison
path: coverage/parity/comparison.json
40 changes: 34 additions & 6 deletions .github/workflows/mutation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,41 @@ on:
pull_request:
branches: [main]
workflow_dispatch:
inputs:
test-group:
type: choice
options: [fast, full]
default: fast
test-selection:
type: choice
options: [coverage, full]
default: coverage
workflow_call:
inputs:
test-group:
type: string
default: fast
test-selection:
type: string
default: coverage
test-order:
type: string
default: component
full-source:
type: boolean
default: false

concurrency:
group: mutation-${{ github.event_name == 'pull_request' && github.ref || github.run_id }}
group: mutation-${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.ref || github.run_id }}-${{ inputs.test-group || 'fast' }}-${{ inputs.test-selection || 'coverage' }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

permissions:
contents: read

env:
MUTATION_TEST_GROUP: ${{ inputs.test-group || 'fast' }}
MUTATION_TEST_SELECTION: ${{ inputs.test-selection || 'coverage' }}
MUTATION_TEST_ORDER: ${{ inputs.test-order || 'component' }}
PYTHONHASHSEED: "0"
TRAILMARK_REQUIRE_BINARY_TOOLS: "1"
TRAILMARK_LLVM_OBJDUMP: /usr/bin/llvm-objdump
Expand All @@ -38,6 +64,7 @@ jobs:
id: scope
env:
PR_BASE_SHA: ${{ github.event.pull_request.base.sha }}
FULL_SOURCE: ${{ inputs.full-source }}
run: |
reviewed=false
if [[ "$GITHUB_EVENT_NAME" == pull_request ]]; then
Expand All @@ -47,6 +74,7 @@ jobs:
reviewed=false
fi
fi
if [[ "$FULL_SOURCE" == true ]]; then reviewed=false; fi
echo "reviewed=$reviewed" >> "$GITHUB_OUTPUT"

baselines:
Expand All @@ -73,11 +101,11 @@ jobs:
run: |
scope=()
if [[ "$MUTATION_REVIEWED" == true ]]; then scope+=(--reviewed); fi
uv run --locked --extra binary python -m tests.run_mutations "${scope[@]}" --baseline-shard="$BASELINE_SHARD"
uv run --locked --extra binary python -m tests.run_mutations "${scope[@]}" --test-group="$MUTATION_TEST_GROUP" --test-selection="$MUTATION_TEST_SELECTION" --test-order="$MUTATION_TEST_ORDER" --baseline-shard="$BASELINE_SHARD"
- name: Upload validated baselines
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: mutation-baseline
name: mutation-baseline-${{ env.MUTATION_TEST_GROUP }}
overwrite: true
path: |
coverage/gremlins/baseline-*.json
Expand Down Expand Up @@ -114,13 +142,13 @@ jobs:
- run: uv sync --locked --all-groups --extra binary
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: mutation-baseline
name: mutation-baseline-${{ env.MUTATION_TEST_GROUP }}
path: coverage/gremlins/baselines
- name: Run mutation campaign with shared baselines
run: |
scope=()
if [[ "$MUTATION_REVIEWED" == true ]]; then scope+=(--reviewed); fi
uv run --locked --extra binary python -m tests.run_mutations "${scope[@]}" --workers=4 --shard="$MUTATION_SHARD" --baselines=coverage/gremlins/baselines
uv run --locked --extra binary python -m tests.run_mutations "${scope[@]}" --test-group="$MUTATION_TEST_GROUP" --test-selection="$MUTATION_TEST_SELECTION" --test-order="$MUTATION_TEST_ORDER" --workers=4 --shard="$MUTATION_SHARD" --baselines=coverage/gremlins/baselines

- name: Enforce reviewed mutation baseline
run: uv run --locked --extra binary python -m tests.mutation_gate --shard="$MUTATION_SHARD"
Expand All @@ -135,7 +163,7 @@ jobs:
if: always()
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: mutation-report-${{ github.sha }}-shard-${{ matrix.shard }}
name: mutation-report-${{ github.sha }}-${{ env.MUTATION_TEST_GROUP }}-shard-${{ matrix.shard }}
overwrite: true
path: coverage/gremlins/
if-no-files-found: error
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
mutants/
src/trailmark/tree_sitter_custom/**/*.so
src/trailmark/tree_sitter_custom/**/*.pyd
# Native cache outputs remain generated artifacts when mutations corrupt their suffix.
/src/trailmark/tree_sitter_custom/*/_binding_*
.gremlins_cache/
coverage/gremlins/
coverage/
# Keep raw audit reports, probes, and validation logs local.
/docs/audits/
/pr-audits/
Expand Down
19 changes: 12 additions & 7 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,20 +108,20 @@ uv run python -m tests.mutation_gate
The runner uses real pytest subprocesses and coverage-driven test selection.
It validates clean and instrumented baselines, expands shared-fixture coverage
to every consumer, and retains tests whose subprocesses or tracing obscure
coverage. Import-time and unmapped mutations run the full suite. Ordinary kills
require a passing neutral failure-prefix check or a matching validated full-suite
order. The control retains the full selected collection and fixture teardown. Use it
rather than invoking the pinned plugin directly. Omit
coverage. Import-time and unmapped mutations run the entire selected pool.
Ordinary kills require a passing neutral failure-prefix check or a matching
validated complete-pool order. The control retains the full selected collection
and fixture teardown. Use it rather than invoking the pinned plugin directly. Omit
`--reviewed` for a full repository campaign; CI runs that after merges
and on manual dispatch. `--workers` already enables parallel execution.
CI produces one baseline receipt and coverage plan from a single instrumented
coverage pass. Its 32 mutation jobs reuse that evidence and execute mutants
without replaying full baselines or prevalidating selected subsets.
Local runs validate their own baselines by default. To reproduce a partition,
pass the same `--shard=1/32` (one-based index/total) to both commands.
Use `--test-selection=full` for a full-suite reference campaign. Shared coverage
preparation uses `--baseline-shard=1/1`; copy both `baseline-1-of-1.json` and
`coverage-plan.json` together when using `--baselines=PATH`.
Use `--test-group=full --test-selection=full` for an unfiltered full-suite reference.
Shared coverage preparation uses `--baseline-shard=1/1`; copy both
`baseline-1-of-1.json` and `coverage-plan.json` together when using `--baselines=PATH`.
See `CONTRIBUTING.md` for baseline sharing and failure-prefix confirmation.
Do not enable `TRAILMARK_UPDATE_SNAPSHOTS` during CI or mutation testing.

Expand All @@ -137,3 +137,8 @@ Do not enable `TRAILMARK_UPDATE_SNAPSHOTS` during CI or mutation testing.
`test_query.py`, plus focused parser/analysis/doc regression tests.
- Update `README.md` and the matching regression tests if adding or
changing user-facing API.

The `mutation_fast` pool is the default; use `--test-group=full` for the full pool.
Pull requests run one mutation campaign, using the fast pool. Weekly and manual
audits compare it with the unfiltered full pool. See CONTRIBUTING.md for comparisons
and release audits.
63 changes: 58 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,11 @@ child processes or replace Python tracing are retained for every mutant. Known
native GNU/LLVM tools, C compilers, and the fixed `git -C ROOT rev-parse HEAD`
provenance query are recognized through fingerprints of their executable contents.
Other Git commands and Python or script wrappers remain opaque. Import-time and
unmapped locations use the full suite.
unmapped locations use the entire selected test pool.

After mutant execution, ordinary test failures receive a neutral failure-prefix
check. The control collects the same selected tests, executes only through the
test that failed, and includes fixture teardown. Matching full-suite orders reuse
test that failed, and includes fixture teardown. Matching complete-pool orders reuse
the passing baseline. For each remaining selected collection, one successful
longest prefix also validates its shorter failure prefixes. These controls use
the same worker budget after the mutant pool closes. A failing neutral prefix
Expand All @@ -171,14 +171,14 @@ Collection-time `SystemExit` counts as a kill only when its traceback includes
an instrumented application source and the unmutated test selection loads
successfully. Harness failures and unrelated internal errors remain errors.

Each mutant subprocess may run for 240 seconds so the full fallback suite can
Each mutant subprocess may run for 240 seconds so the complete fallback pool can
finish with four workers competing for CI resources. A timeout is not counted
as a kill unless the unmutated confirmation run establishes sufficient headroom;
inconclusive outcomes still fail the gate.

**Test ordering.** Within a coverage-selected subset, component unit tests run first,
stopping at the first failure. Shared-helper mutants retain tests from every
language that covers the mutation. Full-suite fallbacks keep collection order so
language that covers the mutation. Complete-pool fallbacks keep collection order so
they can reuse the shared neutral baseline. Tests stay in
their existing files; `tests/mutation_order.py` defines the ordering, and
unknown components keep collection order. Use `--test-order=collection` to
Expand All @@ -196,11 +196,64 @@ mutants prioritize binding-boundary and PHP callable tests; shared parser mutant
prioritize directory-linking regressions after their utility tests.

**Focusing a campaign.** Pass `--targets` with comma-separated source paths,
followed by the relevant test files.
followed by the relevant test files. Use `--test-group=full` when those tests have
no `mutation_fast` marker.

Snapshot updates (`TRAILMARK_UPDATE_SNAPSHOTS=1`) are disabled during CI and
mutation runs; do not enable them there.

### Mutation test pools

Mutation campaigns use the fast pool by default. It marks existing tests with
`pytest.mark.mutation_fast`; tests stay in their original modules and ordinary CI
continues to run every test. Select it explicitly with `--test-group=fast`, or use
`--test-group=full` to run mutations against the full pool.

```bash
uv run pytest -q -m mutation_fast tests/
uv run python -m tests.run_mutations --workers=4 --report-dir=coverage/fast
uv run python -m tests.mutation_gate --report-dir=coverage/fast

# Full-pool comparison using the same coverage selection as routine mutation runs.
uv run python -m tests.run_mutations --test-group=full --workers=4 --report-dir=coverage/full
uv run python -m tests.compare_mutations coverage/full coverage/fast --allow-coverage-reference

# Unfiltered reference: test pool and coverage selection are independent controls.
uv run python -m tests.run_mutations --test-group=full --test-selection=full --test-order=collection --report-dir=coverage/reference
uv run python -m tests.compare_mutations coverage/reference coverage/fast

# Optional controlled benchmark: three serialized repetitions per configuration.
# Configure the native tool paths listed above before starting this long benchmark.
uv run python -m tests.benchmark_mutations --workers=4 --repeat=3 --output-dir=coverage/pool-benchmark
```

Report directories must be distinct for independent campaigns; put them under
ignored `coverage/` or outside the checkout. Comparisons require the exact source
checkout that produced the reports. They reconstruct the complete mutation inventory,
validate disjoint shard coverage and matching inputs, reject inconclusive outcomes,
and report each outcome difference rather than comparing percentages alone.
The benchmark includes clean baselines, instrumented coverage preparation,
collection, mutation execution, confirmations, and report validation. It includes
plain unsharded pytest-gremlins only as a measurement reference; normal mutation
work must use the repository runner. Result caching is disabled in these comparisons.

The seed pool comes from the v0.9.1 campaign's recorded failing-test witnesses.
These witnesses are candidates, not evidence that each test kills independently.
Keep integration tests and collection import witnesses that provide unique kills.
When an audit loses a kill, restore the relevant existing test to the marked pool
or add a small behavioral regression, then rerun the comparison. Do not expand
equivalent-mutant exceptions or narrow the mutated application to repair parity.
Timing measurements belong in the benchmark, never in correctness assertions.

Pull requests run one mutation campaign, using the fast pool.
`mutation-audit.yml` runs weekly on Monday at 06:00 UTC and on its manual trigger.
Each audit compares the fast pool with an unfiltered full-pool reference. Run that
manual audit against each release candidate as well. Each pool uses 32 mutation
shards and its own matching baseline. Restore every lost kill before accepting a
failed audit. Coverage-selected references require the explicit
`--allow-coverage-reference` comparison flag; the default comparison requires an
unfiltered full-pool reference.

## Audit artifacts

Keep implementations, minimized behavioral regressions, and concise decisions in
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ known-third-party = ["coverage"]
[tool.pytest.ini_options]
testpaths = ["tests"]
markers = [
"mutation_fast: default mutation test pool; retain full-pool parity audits",
"mutation_infrastructure: validate the runner once in its clean baseline",
"binary_tools: integration checks requiring the binary extra and native host tools",
]
Expand Down
Loading
Loading