Skip to content

Session persister mutants#791

Merged
arminsabouri merged 2 commits intopayjoin:masterfrom
benalleng:mutants-06-23-25
Jul 7, 2025
Merged

Session persister mutants#791
arminsabouri merged 2 commits intopayjoin:masterfrom
benalleng:mutants-06-23-25

Conversation

@benalleng
Copy link
Collaborator

Closes #786

@0xBEEFCAF3 curious if you have any initial thoughts on catching all of the MaybeFatalTransition::transient(e) mutants. Currently all of those match arms are untested at each stage of the receiver.

@coveralls
Copy link
Collaborator

coveralls commented Jun 23, 2025

Pull Request Test Coverage Report for Build 16004747729

Details

  • 146 of 163 (89.57%) changed or added relevant lines in 3 files are covered.
  • 2 unchanged lines in 1 file lost coverage.
  • Overall coverage increased (+0.4%) to 85.897%

Changes Missing Coverage Covered Lines Changed/Added Lines %
payjoin/src/core/receive/v2/session.rs 47 48 97.92%
payjoin/src/core/persist.rs 0 4 0.0%
payjoin/src/core/receive/v2/mod.rs 99 111 89.19%
Files with Coverage Reduction New Missed Lines %
payjoin/src/core/persist.rs 2 96.08%
Totals Coverage Status
Change from base Build 15983582431: 0.4%
Covered Lines: 7388
Relevant Lines: 8601

💛 - Coveralls

@arminsabouri
Copy link
Collaborator

@0xBEEFCAF3 curious if you have any initial thoughts on catching all of the MaybeFatalTransition::transient(e) mutants. Currently all of those match arms are untested at each stage of the receiver.

Are any of the fatal ones being caught?

@benalleng
Copy link
Collaborator Author

benalleng commented Jun 23, 2025

Yes, all of the mutants are the transient match arms, the fatal arms are all caught.

payjoin/src/receive/v2/mod.rs:289:21: delete match arm
payjoin/src/receive/v2/mod.rs:468:21: delete match arm
payjoin/src/receive/v2/mod.rs:527:17: delete match arm
payjoin/src/receive/v2/mod.rs:573:17: delete match arm
payjoin/src/receive/v2/mod.rs:618:17: delete match arm

Not sure if these are worthy of skipping as to the purpose of these transient errors.
As an aside i think its more likely that the fatal match arms are marked as unviable as opposed to all of them being explicitly caught as the fatal arms are all the catch-all arm. Removing _ => would just cause a linter to catch it.

@arminsabouri
Copy link
Collaborator

Not sure if these are worthy of skipping as to the purpose of these transient errors.

I agree. The transient errors should be caught and preferably in unit tests. Ideally we unit test each path a state transition method could take. As a first step we may want to develop some test tooling first for this first. i.e get_statex_from_test_vector(). Currently the way get into a particular state is by progressing through the entire state machine

@benalleng benalleng force-pushed the mutants-06-23-25 branch 4 times, most recently from 8cc726e to 9539e4b Compare June 25, 2025 17:15
@benalleng
Copy link
Collaborator Author

benalleng commented Jun 25, 2025

Ok, I have created a test for all levels of the state machine that have these transient errors, except for WithContext.
Since that is just taking in a response body and an ohttp::ClientResponse in process_response() what do you think the best approach is for getting that test in?

@benalleng benalleng force-pushed the mutants-06-23-25 branch 2 times, most recently from e7031ec to 391e057 Compare June 26, 2025 14:35
@arminsabouri
Copy link
Collaborator

Ok, I have created a test for all levels of the state machine that have these transient errors, except for WithContext. Since that is just taking in a response body and an ohttp::ClientResponse in process_response() what do you think the best approach is for getting that test in?

We talked about this in discord. The We realized that the withContext state transition should never throw a implementation error and that transient error branch can be removed. This is addressed here

@benalleng benalleng changed the title [WIP] session persister mutants Session persister mutants Jun 26, 2025
@benalleng
Copy link
Collaborator Author

Added this note to the commit message so it will be in the history.

@benalleng benalleng marked this pull request as ready for review June 26, 2025 15:29
@benalleng benalleng requested a review from arminsabouri June 26, 2025 15:29
Copy link
Collaborator

@arminsabouri arminsabouri left a comment

Choose a reason for hiding this comment

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

Approach ACK. Just had a couple nits and I think we should move the unit tests added in persist.rs to the v2::receiver. Thanks for picking this up!


let v2_get_context = V2GetContext {
endpoint,
endpoint: endpoint.clone(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

I dont see other changes that would warrant this clone? Do you remenber why we needed this?

Copy link
Collaborator Author

@benalleng benalleng Jun 27, 2025

Choose a reason for hiding this comment

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

This was a holdout from something I reverted, I had some tests before you added some tests in #805 it can be removed

let session_context = SHARED_CONTEXT.clone();
let events = vec![SessionEvent::Created(session_context.clone())];

let uri = SessionHistory { events }.pj_uri().expect("Could not get session history uri");
Copy link
Collaborator

Choose a reason for hiding this comment

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

personal nit: with expects I think its idomatic to explain why we expect a certain condition to be true rather than an error message. i.e expect("session creation event is present")

@benalleng benalleng force-pushed the mutants-06-23-25 branch 4 times, most recently from 2b6a662 to 24faaa3 Compare July 1, 2025 13:04
@benalleng
Copy link
Collaborator Author

I added a commit to make all of the relevant fields public, do you think that is ok or should they still be limited to the crate level?

@arminsabouri
Copy link
Collaborator

I added a commit to make all of the relevant fields public, do you think that is ok or should they still be limited to the crate level?

If they can be, they should be pub(crate)'d

benalleng added 2 commits July 1, 2025 12:18
A few new mutants were introduced with the push updating our session
persistence. These catch the mutants by adding some new test coverage
along that new code path.
The WithContext state transition should never throw an implementation
error so that transient error branch should not exist and can be safely
removed. This also obviously addresses the final missing mutant here as
this code is not required.
@benalleng benalleng requested a review from arminsabouri July 3, 2025 18:11
Copy link
Collaborator

@arminsabouri arminsabouri left a comment

Choose a reason for hiding this comment

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

utACK 9bd4193
Just had a small nit. This is good to go as is

Comment on lines +1107 to +1112
let receiver = Receiver {
state: UncheckedProposal {
v1: crate::receive::v1::test::unchecked_proposal_from_test_vector(),
context: context.clone(),
},
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: can we use the helper method defined above? (unchecked_proposal_v2_from_test_vector)

Copy link
Collaborator Author

@benalleng benalleng Jul 7, 2025

Choose a reason for hiding this comment

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

No, the expiry time now was changed in the context above. so we need to build the receiver here.

),
};
}
Err(e) =>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just noting this so I don't forget. Removing transient errors from this state transition does make sense right now given that we are implicitly treating all the errors as fatal. However, there are certainly transient errors here that could be resolved based on some external events. e.g changing the ohttp relays, waiting for the dir to be operational again, etc...

@arminsabouri arminsabouri merged commit 22e59cc into payjoin:master Jul 7, 2025
7 checks passed
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.

New Mutants Found

3 participants