Skip to content

Introduce cargo mutants cron job#573

Merged
spacebear21 merged 1 commit intopayjoin:masterfrom
benalleng:mutation-ci
Mar 24, 2025
Merged

Introduce cargo mutants cron job#573
spacebear21 merged 1 commit intopayjoin:masterfrom
benalleng:mutation-ci

Conversation

@benalleng
Copy link
Collaborator

@benalleng benalleng commented Mar 12, 2025

Relates to #539

This is our first step at cargo mutants in our ci!

At the moment all cargo mutant exploration I have been doing locally but with over 250 missed mutants remaining and possibly growing as new code is introduced I think it is time to implement a weekly cron job to track these mutants.

This heavily copies the rust-bitcoin implementation of their mutants workflow with tweaks for our codebase and mutants coverage progress.

currently set to happen weekly Sun 00:00

@coveralls
Copy link
Collaborator

coveralls commented Mar 12, 2025

Pull Request Test Coverage Report for Build 14042949679

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.03%) to 81.124%

Totals Coverage Status
Change from base Build 14042339636: 0.03%
Covered Lines: 5007
Relevant Lines: 6172

💛 - Coveralls

@benalleng benalleng force-pushed the mutation-ci branch 3 times, most recently from b3e5da6 to ff1eeb8 Compare March 12, 2025 22:28
Copy link
Collaborator

@spacebear21 spacebear21 left a comment

Choose a reason for hiding this comment

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

Based on my current understanding, this cron job would look for mutants over all of payjoin and payjoin-cli each time it runs. Since there are over 250 mutants remaining as you mentioned, it would create a new issue every week flagging the same mutants over and over until we've addressed all of them.

To avoid this noise, we should find (or achieve) a narrow scope of code that has zero mutants and change mutants.toml to exclude everything else, such that running the job returns zero missed mutants. That way this cron job functions as a regression test and we can get true signal if it runs one week and creates an issue.

Over time - as better tests are added to other areas of the code - we can expand the mutation testing scope. For example rust-bitcoin started off by running mutation tests only over the units crate, then expanded to also cover primitives. They also exclude a bunch of crate-specific stuff using regex for reasons, I guess for mutants that are known to be unkillable or not worth the effort.

additional_cargo_args = ["--all-features"]
examine_globs = ["units/src/**/*.rs", "primitives/src/**/*.rs"]
exclude_globs = [
    "units/src/amount/verification.rs" # kani tests
]
exclude_re = [
# ...
    "deserialize", # Skip serde mutation tests
    "Iterator", # Mutating operations in an iterator can result in an infinite loop
    # ----------------------------------Crate-specific exclusions----------------------------------
    # Units
    # src/amount/mod.rs
    "parse_signed_to_satoshi", # Can't kill all mutants since there is no denomination smaller than Satoshi
# ...

@benalleng
Copy link
Collaborator Author

benalleng commented Mar 13, 2025

Ok! Good call, I'm realizing now that even on their first run the rust-bitcoin mutation cron had 0 missed mutants, they had full coverage before they added theirs. I'll look into a good place to start our scope and then expand it out as we add coverage. alternatively I can close this for now before we feel like its worth adding a cron job for keeping track of regressions

@benalleng benalleng force-pushed the mutation-ci branch 4 times, most recently from d0166b8 to 9cdbfbc Compare March 13, 2025 20:41
@benalleng
Copy link
Collaborator Author

benalleng commented Mar 13, 2025

I just added additional coverage that completes mutation coverage for payjoin/src/uri/*.rs in #578 I figure that could be a fine place to start

@benalleng
Copy link
Collaborator Author

benalleng commented Mar 13, 2025

They also exclude a bunch of crate-specific stuff using regex for reasons, I guess for mutants that are known to be unkillable or not worth the effort.

I guess this will just grow as we go, as these definitely seem like unknown-unknowns at the moment. The first one that comes to mind is the process_response function which i avoided adding as it requires a receiver response for (even that feels like it could be handled though)

At the moment all cargo mutant exploration I have been doing locally
but with over 250 missed mutants remaining and possibly growing as new
code is introduced I think it is time to implement a weekly cron job
to track these mutants.

This heavily copies the rust-bitcoin implementation of their mutants
workflow with tweaks for our codebase and mutants coverage progress.
@benalleng
Copy link
Collaborator Author

I added the first crate specific exclude rules relating to interleave_shuffle

Copy link
Collaborator

@spacebear21 spacebear21 left a comment

Choose a reason for hiding this comment

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

tACK f8cb70d

I ran cargo mutants locally on this branch and found 3 missed mutants. After rebasing on the latest master with changes from #578 and running it again there are now zero missed. Nice!

@spacebear21 spacebear21 merged commit 3311a09 into payjoin:master Mar 24, 2025
7 checks passed
@spacebear21 spacebear21 mentioned this pull request Apr 1, 2025
17 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants