matrix-org / vodozemac

An implementation of Olm and Megolm in pure Rust.
Apache License 2.0
175 stars 30 forks source link

test(megolm): Add mutation tests #142

Closed Johennes closed 6 months ago

Johennes commented 7 months ago

This fixes the following issues:

MISSED   src/megolm/group_session.rs:80:9: replace GroupSession::session_config -> SessionConfig with Default::default() in 0.8s build + 3.1s test
MISSED   src/megolm/inbound_group_session.rs:289:47: replace < with == in InboundGroupSession::find_ratchet in 0.8s build + 3.1s test
MISSED   src/megolm/inbound_group_session.rs:302:9: replace InboundGroupSession::verify_mac -> Result<(), DecryptionError> with Ok(()) in 1.0s build + 3.1s test
MISSED   src/megolm/message.rs:133:9: replace MegolmMessage::add_signature -> Result<(), SignatureError> with Ok(()) in 0.8s build + 3.7s test
MISSED   src/megolm/message.rs:282:42: replace + with - in <impl TryFrom for MegolmMessage>::try_from in 0.8s build + 3.0s test
MISSED   src/megolm/message.rs:50:54: replace + with * in 0.8s build + 3.2s test
MISSED   src/megolm/message.rs:54:9: replace MegolmMessage::ciphertext -> &[u8] with Vec::leak(Vec::new()) in 0.8s build + 3.0s test
MISSED   src/megolm/message.rs:54:9: replace MegolmMessage::ciphertext -> &[u8] with Vec::leak(vec![0]) in 0.8s build + 3.4s test
MISSED   src/megolm/message.rs:54:9: replace MegolmMessage::ciphertext -> &[u8] with Vec::leak(vec![1]) in 0.8s build + 3.0s test
MISSED   src/megolm/message.rs:59:9: replace MegolmMessage::message_index -> u32 with 0 in 0.8s build + 2.9s test
MISSED   src/megolm/message.rs:59:9: replace MegolmMessage::message_index -> u32 with 1 in 0.8s build + 3.0s test
MISSED   src/megolm/message.rs:64:9: replace MegolmMessage::mac -> &[u8] with Vec::leak(Vec::new()) in 0.8s build + 3.1s test
MISSED   src/megolm/message.rs:64:9: replace MegolmMessage::mac -> &[u8] with Vec::leak(vec![0]) in 0.8s build + 3.2s test
MISSED   src/megolm/message.rs:64:9: replace MegolmMessage::mac -> &[u8] with Vec::leak(vec![1]) in 0.9s build + 3.3s test
MISSED   src/megolm/mod.rs:34:5: replace default_config -> SessionConfig with Default::default() in 0.8s build + 3.2s test
MISSED   src/megolm/ratchet.rs:218:31: replace < with == in Ratchet::advance_to in 0.7s build + 3.0s test
MISSED   src/megolm/session_config.rs:33:9: replace SessionConfig::version -> u8 with 0 in 0.8s build + 3.0s test
MISSED   src/megolm/session_config.rs:33:9: replace SessionConfig::version -> u8 with 1 in 0.8s build + 3.5s test
MISSED   src/megolm/session_keys.rs:141:9: replace <impl Zeroize for ExportedSessionKey>::zeroize with () in 1.0s build + 3.2s test
MISSED   src/megolm/session_keys.rs:291:9: replace <impl Zeroize for SessionKey>::zeroize with () in 0.9s build + 3.2s test
TIMEOUT  src/megolm/ratchet.rs:230:23: replace -= with += in Ratchet::advance_to in 0.8s build + 23.0s test
TIMEOUT  src/megolm/ratchet.rs:230:23: replace -= with /= in Ratchet::advance_to in 0.8s build + 23.0s test

This also gets us to +90% coverage. πŸ™‚

Relates to: #78

codecov-commenter commented 7 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 90.47%. Comparing base (7d51bd6) to head (b71c7c7). Report is 4 commits behind head on main.

:exclamation: Current head b71c7c7 differs from pull request most recent head 1f1d3f1. Consider uploading reports for the commit 1f1d3f1 to get more accurate results

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #142 +/- ## ========================================== + Coverage 89.41% 90.47% +1.05% ========================================== Files 32 32 Lines 1786 1785 -1 ========================================== + Hits 1597 1615 +18 + Misses 189 170 -19 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

Johennes commented 7 months ago

Looks like the clippy errors are due to a new rule on nightly.

Edit: Attempting to fix them in https://github.com/matrix-org/vodozemac/pull/145.

Johennes commented 6 months ago

Hm, looks like the CI ran on an ARM Mac

Image: macos-14-arm64

but then installed the x86 rust toolchain

Run rustup toolchain install stable-x86_64-apple-darwin --profile minimal --no-self-update

which results in

/Users/runner/work/_temp/39f7e4d6-3a3c-42b0-9e65-200e32c1e151.sh: line 1: cargo: command not found

πŸ€”

Johennes commented 6 months ago

So according to https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners/about-github-hosted-runners#standard-github-hosted-runners-for-private-repositories macos-latest currently aliases macos-14 and always runs on M1. I'm not sure what suddenly changed here because last week it still resolved to macos-12 as evidenced by https://github.com/matrix-org/vodozemac/actions/runs/8779442225/job/24087554656#step:1:8.

@poljar do you want CI for macOS to run on both x86 and ARM Mac or would just ARM be enough?

poljar commented 6 months ago

So according to https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners/about-github-hosted-runners#standard-github-hosted-runners-for-private-repositories macos-latest currently aliases macos-14 and always runs on M1. I'm not sure what suddenly changed here because last week it still resolved to macos-12 as evidenced by https://github.com/matrix-org/vodozemac/actions/runs/8779442225/job/24087554656#step:1:8.

@poljar do you want CI for macOS to run on both x86 and ARM Mac or would just ARM be enough?

Hmm, obviously both are better, but I'm happy to have any CI for Mac. So ARM only would be enough.

Johennes commented 6 months ago

Hmm, obviously both are better, but I'm happy to have any CI for Mac. So ARM only would be enough.

Since the CI job was already set up via a matrix strategy, it was actually pretty easy to just build on both. I hope it's ok that I added the small change in this PR directly.

poljar commented 6 months ago

Hmm, obviously both are better, but I'm happy to have any CI for Mac. So ARM only would be enough.

Since the CI job was already set up via a matrix strategy, it was actually pretty easy to just build on both. I hope it's ok that I added the small change in this PR directly.

Yeah that's fine.

Johennes commented 6 months ago

I don't know why codecov is hanging now. I already tried it three or four times by now. πŸ€·β€β™‚οΈ

poljar commented 6 months ago

I don't know why codecov is hanging now. I already tried it three or four times by now. πŸ€·β€β™‚οΈ

Hmm, no idea either. Maybe it'll untangle itself once merged.