-
Notifications
You must be signed in to change notification settings - Fork 330
Run mutation tests in CI for changed files #1364
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
souradeep-das
wants to merge
4
commits into
ethereum:forks/osaka
Choose a base branch
from
souradeep-das:souradeep/ci_mutmut_integ
base: forks/osaka
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -95,3 +95,105 @@ jobs: | |||||
- uses: ./.github/actions/setup-env | ||||||
- name: Run optimized tests | ||||||
run: tox -e optimized | ||||||
|
||||||
changed-forks: | ||||||
runs-on: ubuntu-latest | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
This is the magic sauce that runs the job on a beefier machine. |
||||||
needs: static | ||||||
outputs: | ||||||
changed-forks: ${{ steps.filter-tests.outputs.forks }} | ||||||
fork-mapping: ${{ steps.filter-tests.outputs.fork_mapping }} | ||||||
steps: | ||||||
- uses: actions/checkout@v4 | ||||||
- name: Setup Python | ||||||
uses: actions/setup-python@v5 | ||||||
with: | ||||||
python-version: "3.11" | ||||||
- name: Install project for fork detection | ||||||
run: pip install . | ||||||
- name: Find changed valid forks | ||||||
id: set-forks | ||||||
run: | | ||||||
git fetch origin ${{ github.event.pull_request.base.ref }} | ||||||
VALID_FORKS=$(python -c "import json; from ethereum_spec_tools.forks import Hardfork; print(json.dumps([f.short_name for f in Hardfork.discover()]))") | ||||||
CHANGED_FORKS=$(git diff --name-only origin/${{ github.event.pull_request.base.ref }} ${{ github.sha }} -- src/ethereum/ | awk -F'/' '{print $3}' | sort -u) | ||||||
readarray -t VALID_FORKS_ARR < <(echo "$VALID_FORKS" | jq -r '.[]') | ||||||
FILTERED=$(for f in $CHANGED_FORKS; do for v in "${VALID_FORKS_ARR[@]}"; do [ "$f" = "$v" ] && echo $f; done; done | jq -R . | jq -s -c .) | ||||||
echo "FILTERED (final forks for matrix): $FILTERED" | ||||||
echo "forks=$FILTERED" >> $GITHUB_OUTPUT | ||||||
- name: Filter out forks without tests | ||||||
id: filter-tests | ||||||
run: | | ||||||
FORK_DATA=$(python -c " | ||||||
import sys | ||||||
sys.path.insert(0, 'tests') | ||||||
from json_infra import FORKS | ||||||
import json | ||||||
eels_to_json = {} | ||||||
for json_fork, config in FORKS.items(): | ||||||
eels_to_json[config['eels_fork']] = json_fork | ||||||
print(json.dumps(eels_to_json)) | ||||||
") | ||||||
|
||||||
AVAILABLE_EELS_FORKS=$(echo "$FORK_DATA" | jq -r 'keys[]') | ||||||
FILTERED_WITH_TESTS=$(for f in $(echo '${{ steps.set-forks.outputs.forks }}' | jq -r '.[]'); do | ||||||
if echo "$AVAILABLE_EELS_FORKS" | grep -q "^$f$"; then | ||||||
echo $f | ||||||
fi | ||||||
done | jq -R . | jq -s -c .) | ||||||
echo "FILTERED_WITH_TESTS: $FILTERED_WITH_TESTS" | ||||||
echo "forks=$FILTERED_WITH_TESTS" >> $GITHUB_OUTPUT | ||||||
echo "fork_mapping=$FORK_DATA" >> $GITHUB_OUTPUT | ||||||
|
||||||
mutation-test: | ||||||
runs-on: [self-hosted-ghr, size-xl-x64] | ||||||
needs: [static, changed-forks] | ||||||
if: github.event_name == 'pull_request' | ||||||
strategy: | ||||||
matrix: | ||||||
fork: ${{ fromJson(needs.changed-forks.outputs.changed-forks) }} | ||||||
steps: | ||||||
- uses: actions/checkout@v4 | ||||||
with: | ||||||
submodules: recursive | ||||||
- name: Setup Python | ||||||
uses: actions/setup-python@v5 | ||||||
with: | ||||||
python-version: "3.11" | ||||||
- name: Install project with test dependencies | ||||||
run: pip install '.[test]' | ||||||
- name: Install mutmut | ||||||
run: pip install git+https://github.com/souradeep-das/mutmut.git@cc99e509092ed232600712d9d77fb38be31f74ec | ||||||
- name: Find changed files for fork | ||||||
id: changed | ||||||
run: | | ||||||
git fetch origin ${{ github.event.pull_request.base.ref }} | ||||||
echo "changed_files<<EOF" >> $GITHUB_OUTPUT | ||||||
(git diff --name-only origin/${{ github.event.pull_request.base.ref }} ${{ github.sha }} -- src/ethereum/${{ matrix.fork }}/ || true) >> $GITHUB_OUTPUT | ||||||
echo "EOF" >> $GITHUB_OUTPUT | ||||||
- name: Display changed files | ||||||
run: | | ||||||
echo "Changed files:" | ||||||
echo "${{ steps.changed.outputs.changed_files }}" | ||||||
- name: Skip if no changes for this fork | ||||||
if: steps.changed.outputs.changed_files == '' | ||||||
run: echo "No changes for ${{ matrix.fork }}, skipping mutmut." | ||||||
- name: Copy dependencies for mutation testing | ||||||
if: steps.changed.outputs.changed_files != '' | ||||||
run: | | ||||||
mkdir -p mutants/src | ||||||
cp -r src/* mutants/src/ | ||||||
- name: Determine JSON fork name | ||||||
if: steps.changed.outputs.changed_files != '' | ||||||
id: json-fork | ||||||
run: | | ||||||
JSON_FORK=$(echo '${{ needs.changed-forks.outputs.fork-mapping }}' | jq -r '."${{ matrix.fork }}"') | ||||||
echo "json_fork=$JSON_FORK" >> $GITHUB_OUTPUT | ||||||
echo "Found JSON fork name: $JSON_FORK for eels fork: ${{ matrix.fork }}" | ||||||
- name: Run mutmut | ||||||
if: steps.changed.outputs.changed_files != '' | ||||||
run: | | ||||||
FILES=$(echo "${{ steps.changed.outputs.changed_files }}" | paste -sd, -) | ||||||
mutmut --paths-to-mutate $FILES --tests-dir tests/json_infra/ --pytest-extra-args '-m "not slow and not angry_mutant" --ignore-glob=tests/json_infra/fixtures/* --fork ${{ steps.json-fork.outputs.json_fork }}' --debug run | ||||||
- name: Show mutmut results | ||||||
if: steps.changed.outputs.changed_files != '' | ||||||
run: mutmut results |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The mutation tests might take a while to run - so I'm wondering how we should run them - per PR or commit on main
If several files have changes the time to run on CI also might be unrealistic. In which case I was thinking if we should add more limitations on when to run these tests (or patch mutmut to be able to run mutation tests for specific functions (as opposed to files).
Attached a test run on the main comment ^