Skip to content

Conversation

@Fizzadar
Copy link
Contributor

@Fizzadar Fizzadar commented Dec 19, 2025

While working on babbleserv I threw this test together for some basic state res validation.

Pull Request Checklist

Signed-off-by: Nick @ Beeper (@Fizzadar) <nick@beeper.com)

@Fizzadar Fizzadar requested review from a team as code owners December 19, 2025 12:21
cancel := srv.Listen()
defer cancel()

hsName := "hs1"
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd be tempted just to inline this.

The placement here makes it bit weird to figure out whether it pertains to the real homeserver from the deployment vs the engineered homeserver from Complement.

// v v
//
// what is the current state here
func TestFederationStateResolution(t *testing.T) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
func TestFederationStateResolution(t *testing.T) {
func TestFederationStateConflictResolution(t *testing.T) {

ver := alice.GetDefaultRoomVersion(t)
serverRoom := srv.MustMakeRoom(t, ver, federation.InitialRoomEvents(ver, bob))

getName := func() string {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Probably better as a func getRoomName(...) helper below without it being nested here

// Join Charlie - this will be a federated join as the server is not yet in the room
charlie.MustJoinRoom(t, serverRoom.RoomID, []spec.ServerName{srv.ServerName()})
charlie.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(charlie.UserID, serverRoom.RoomID))
serverRoom.WaiterForMembershipEvent(charlie.UserID).Waitf(t, 5*time.Second, "failed to see alice join complement server")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
serverRoom.WaiterForMembershipEvent(charlie.UserID).Waitf(t, 5*time.Second, "failed to see alice join complement server")
serverRoom.WaiterForMembershipEvent(charlie.UserID).Waitf(t, 5*time.Second, "failed to see charlie join complement server")

serverRoom.MustHaveMembershipForUser(t, alice.UserID, "join")

// Send updated power levels so alice can set the room name.
pwlvlEvt := srv.MustCreateEvent(t, serverRoom, federation.Event{
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
pwlvlEvt := srv.MustCreateEvent(t, serverRoom, federation.Event{
powerlevelEvent := srv.MustCreateEvent(t, serverRoom, federation.Event{


// Alice now sets the room name, which is allowed. Notably it is this event that will be lost
// due to the state reset.
e2 := alice.SendEventSynced(t, serverRoom.RoomID, b.Event{
Copy link
Collaborator

Choose a reason for hiding this comment

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

Better name especially since we refer to this name in the error messages

Suggested change
e2 := alice.SendEventSynced(t, serverRoom.RoomID, b.Event{
roomNameChangeFromAlice := alice.SendEventSynced(t, serverRoom.RoomID, b.Event{

(applies to all of the e2, s2, type stuff)

Type: "m.room.name",
StateKey: b.Ptr(""),
Content: map[string]any{
"name": "Bad name",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
"name": "Bad name",
"name": "another name",

It's not a bad name so let's not mark it as such. It's "some state that will be rolled back because we will later do xxx"

// dropped is an unfortunate consequence of the state res v2 algorithm, as described here:
// https://github.com/matrix-org/matrix-spec-proposals/blob/erikj/state_res_msc/proposals/1442-state-resolution.md#state-resets
if name := getName(); name == "Bad name" {
ct.Fatalf(t, "initial name not restored after state resolution, got: %s", name)
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should also show the expected name

Comment on lines +174 to +178
if name := getName(); name == "Bad name" {
ct.Fatalf(t, "initial name not restored after state resolution, got: %s", name)
} else if name == "" {
t.Log("original name not restored")
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would expect this check to look more like, if not equal to the name we expect to be rolled back to then error

return w
}

func (r *ServerRoom) WaiterForMembershipEvent(userID string) *helpers.Waiter {
Copy link
Collaborator

Choose a reason for hiding this comment

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

We could make this a general WaiterForStateEvent thing 🤷

Might make it more appetizing to write engineered tests

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.

2 participants