Skip to content
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

Appservice virt member test #747

Merged
merged 2 commits into from
Jun 14, 2022

Conversation

agraven
Copy link
Contributor

@agraven agraven commented Jun 9, 2022

commit 1: Don't assume virtual client membership is join if none is stored, since that leads to a client being told it's joined in rooms it has no membership of. The main appservice client still assumes it's joined every room it receives transaction events about.

commit 2: Test that virtual clients get assigned the correct membership to rooms when processing received transactions.

Don't assume virtual client membership is join if none is stored, since
that leads to a client being told it's joined in rooms it has no
membership of. The main appservice client still assumes it's joined
every room it receives transaction events about.
@agraven agraven force-pushed the appservice-virt-member-test branch from 3cf280a to d5f14c0 Compare June 9, 2022 12:06
"age": 2970366
}
}))?
.cast::<AnyRoomEvent>(),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wasn't sure where to put the test json, as the needed Vec<Raw> form was slightly different than usual.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

In most cases I prefer to put the JSON close to the test, even at the cost of some duplication. Otherwise it makes it harder to keep in mind which JSON we're using and what assumptions it carries with it.

@@ -709,25 +713,28 @@ impl AppService {
let key = &[USER_MEMBER, room_id.as_bytes(), b".", user_id.as_bytes()].concat();
let membership = match client.store().get_custom_value(key).await? {
Some(value) => String::from_utf8(value).ok().map(MembershipState::from),
// Assume the appservice is in every known room
None if user_id == appserv_uid => Some(MembershipState::Join),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seemed like a safe assumption that if the appservice receives events for a given room, the main client is already a member of it and we just missed it or haven't processed the relevant membership event yet.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yep, seems like a save assumption. A proper fix would be to force a full state sync if we see events for a room the first time, but that's out of scope for this PR.

@codecov
Copy link

codecov bot commented Jun 9, 2022

Codecov Report

Merging #747 (9bd9b46) into main (8b05f92) will increase coverage by 0.10%.
The diff coverage is 81.25%.

@@            Coverage Diff             @@
##             main     #747      +/-   ##
==========================================
+ Coverage   71.59%   71.70%   +0.10%     
==========================================
  Files         117      117              
  Lines       16475    16505      +30     
==========================================
+ Hits        11796    11835      +39     
+ Misses       4679     4670       -9     
Impacted Files Coverage Δ
crates/matrix-sdk-appservice/src/lib.rs 71.22% <70.00%> (+5.54%) ⬆️
crates/matrix-sdk-appservice/tests/tests.rs 96.44% <86.36%> (-1.51%) ⬇️
crates/matrix-sdk/src/client/builder.rs 66.98% <0.00%> (+2.83%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8b05f92...9bd9b46. Read the comment docs.

@agraven agraven force-pushed the appservice-virt-member-test branch from d5f14c0 to de0251c Compare June 9, 2022 12:54
Test that virtual clients get assigned the correct membership to rooms
when processing received transactions.
@agraven agraven force-pushed the appservice-virt-member-test branch from de0251c to 9bd9b46 Compare June 9, 2022 13:00
@johannescpk
Copy link
Contributor

I think the sender_localpart check is missing in the receive_transaction method?

@agraven
Copy link
Contributor Author

agraven commented Jun 10, 2022

That gets covered by assuming the appservice acount is join in every room.

                        // Assume the appservice is in every known room
                        None if user_id == appserv_uid => Some(MembershipState::Join),

Edit: though it might still make sense to do, since that means we're not using the fallback behavior in every case.

Copy link
Contributor

@poljar poljar left a comment

Choose a reason for hiding this comment

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

This looks good from my point of view, thanks for spending time writing tests for the app-service crate. @johannescpk are your concerns resolved as well?

"age": 2970366
}
}))?
.cast::<AnyRoomEvent>(),
Copy link
Contributor

Choose a reason for hiding this comment

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

In most cases I prefer to put the JSON close to the test, even at the cost of some duplication. Otherwise it makes it harder to keep in mind which JSON we're using and what assumptions it carries with it.

@johannescpk
Copy link
Contributor

@agraven Makes sense.

@poljar Yep, looks good to me.

@poljar poljar merged commit 5243091 into matrix-org:main Jun 14, 2022
@poljar
Copy link
Contributor

poljar commented Jun 14, 2022

Seems like this merged fine without any conflicts but clashes with #750. @agraven mind taking a look?

@agraven
Copy link
Contributor Author

agraven commented Jun 14, 2022

Fix filed in #764

@poljar
Copy link
Contributor

poljar commented Jun 14, 2022

Thanks.

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