Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
4468a3f
Convert Sytest `Name/topic keys are correct` to Complement
anoadragon453 Oct 20, 2025
835ba9a
Regenerate the list of converted sytests in the README
anoadragon453 Oct 20, 2025
320b79b
Merge branch 'main' of github.com:matrix-org/complement into anoa/syt…
anoadragon453 Oct 29, 2025
0ef2cf7
Update sytest coverage list
anoadragon453 Oct 29, 2025
f31eeff
Wait for `SyncUnitTimeout` instead of 15s arbitrarily
anoadragon453 Oct 29, 2025
2d2a8ab
Batch up all errors of a room before logging
anoadragon453 Oct 29, 2025
843789b
Use `GetFullyQualifiedHomeserverName`
anoadragon453 Oct 29, 2025
1f20acf
Print out unexpected rooms if we found any
anoadragon453 Oct 29, 2025
2d9a22c
foundRooms -> validatedRooms
anoadragon453 Oct 30, 2025
6958458
Convert to a separate test per room data config
anoadragon453 Oct 30, 2025
9e08bc7
Remove the room from the public rooms list at test's end
anoadragon453 Oct 30, 2025
e79b346
Mark `parsePublicRoomsResponse` as a test helper function
anoadragon453 Nov 5, 2025
c7ee1d8
Replace arbitrary timeout with `authedClient.SyncUntilTimeout`
anoadragon453 Nov 5, 2025
59f9f0e
hostname -> server_name
anoadragon453 Nov 5, 2025
a395212
Only log unexpected rooms if there are any
anoadragon453 Nov 5, 2025
d24405d
Remove duplicate `chunk` checks
anoadragon453 Nov 5, 2025
83723e7
Remove room at the end of "Can search public room list"
anoadragon453 Nov 5, 2025
9ab045c
unparallel public rooms tests
anoadragon453 Nov 5, 2025
ce9288f
`defer` right after creating the room
anoadragon453 Nov 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ update-ca-certificates

## Sytest parity

As of 10 February 2023:
As of 29 October 2025:
```
$ go build ./cmd/sytest-coverage
$ ./sytest-coverage -v
Expand Down Expand Up @@ -507,7 +507,13 @@ $ ./sytest-coverage -v
✓ Can get rooms/{roomId}/members

30rooms/60version_upgrade 0/19 tests
30rooms/70publicroomslist 0/5 tests
30rooms/70publicroomslist 2/5 tests
× Asking for a remote rooms list, but supplying the local server's name, returns the local rooms list
× Can get remote public room list
× Can paginate public room list
✓ Can search public room list
✓ Name/topic keys are correct

31sync/01filter 2/2 tests
✓ Can create filter
✓ Can download filter
Expand Down Expand Up @@ -707,5 +713,5 @@ $ ./sytest-coverage -v
90jira/SYN-516 0/1 tests
90jira/SYN-627 0/1 tests

TOTAL: 220/610 tests converted
TOTAL: 222/610 tests converted
```
194 changes: 194 additions & 0 deletions tests/csapi/public_rooms_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package csapi_tests

import (
"fmt"
"net/http"
"testing"
"time"
Expand All @@ -12,11 +13,13 @@ import (
"github.com/matrix-org/complement/helpers"
"github.com/matrix-org/complement/match"
"github.com/matrix-org/complement/must"
"github.com/matrix-org/complement/should"
)

func TestPublicRooms(t *testing.T) {
deployment := complement.Deploy(t, 1)
defer deployment.Destroy(t)
hostname := deployment.GetFullyQualifiedHomeserverName(t, "hs1")

t.Run("parallel", func(t *testing.T) {
// sytest: Can search public room list
Expand Down Expand Up @@ -71,5 +74,196 @@ func TestPublicRooms(t *testing.T) {
}),
)
})

// sytest: Name/topic keys are correct
t.Run("Name/topic keys are correct", func(t *testing.T) {
t.Parallel()
authedClient := deployment.Register(t, "hs1", helpers.RegistrationOpts{})

// Define room configurations matching the Sytest
roomConfigs := []struct {
alias string
name string
topic string
}{
{"publicroomalias_no_name", "", ""},
{"publicroomalias_with_name", "name_1", ""},
{"publicroomalias_with_topic", "", "topic_1"},
{"publicroomalias_with_name_topic", "name_2", "topic_2"},
{"publicroom_with_unicode_chars_name", "un nom français", ""},
{"publicroom_with_unicode_chars_topic", "", "un topic à la française"},
{"publicroom_with_unicode_chars_name_topic", "un nom français", "un topic à la française"},
}

// Create all rooms with their configurations
createdRooms := make(map[string]struct {
roomID string
name string
topic string
})

for _, config := range roomConfigs {
roomOptions := map[string]interface{}{
"visibility": "public",
"room_alias_name": config.alias,
}

if config.name != "" {
roomOptions["name"] = config.name
}
if config.topic != "" {
roomOptions["topic"] = config.topic
}

roomID := authedClient.MustCreateRoom(t, roomOptions)
createdRooms[config.alias] = struct {
roomID string
name string
topic string
}{
roomID: roomID,
name: config.name,
topic: config.topic,
}
t.Logf("Created room %s with alias %s", roomID, config.alias)
}

// Poll /publicRooms until all our rooms appear with correct data
authedClient.MustDo(t, "GET", []string{"_matrix", "client", "v3", "publicRooms"},
client.WithRetryUntil(authedClient.SyncUntilTimeout, func(res *http.Response) bool {
body := must.ParseJSON(t, res.Body)

must.MatchGJSON(
t,
body,
match.JSONKeyPresent("chunk"),
match.JSONKeyTypeEqual("chunk", gjson.JSON),
)

chunk := body.Get("chunk")
if !chunk.IsArray() {
t.Logf("chunk is not an array")
return false
}

// Track which rooms we've correctly found
foundRooms := make(map[string]bool)

// Keep track of any rooms that we didn't expect to see.
unexpectedRooms := make([]string, 0)

// Check each room in the public rooms list
for _, roomData := range chunk.Array() {
roomId := roomData.Get("room_id").Str

// Verify required keys are present. This applies to any room we see.
err := should.MatchGJSON(
roomData,
match.JSONKeyPresent("world_readable"),
match.JSONKeyPresent("guest_can_join"),
match.JSONKeyPresent("num_joined_members"),
)
if err != nil {
// This room is missing required keys, log and try again.
t.Logf("Room %s data missing required keys: %s", roomId, err.Error())
return false
}

validationErrors := make([]error, 0)

canonicalAlias := roomData.Get("canonical_alias").Str
name := roomData.Get("name").Str
topic := roomData.Get("topic").Str
numMembers := roomData.Get("num_joined_members").Int()

// Skip rooms that aren't ours
if canonicalAlias == "" {
unexpectedRooms = append(unexpectedRooms, roomId)
continue
}

// Find which of our rooms this matches
var matchedAlias string
for alias := range createdRooms {
expectedAlias := "#" + alias + ":" + string(hostname)
if canonicalAlias == expectedAlias {
matchedAlias = alias
break
}
}

if matchedAlias == "" {
continue // Not one of our rooms
}

roomConfig := createdRooms[matchedAlias]

// Verify member count
if numMembers != 1 {
err = fmt.Errorf("Room %s has %d members, expected 1", matchedAlias, numMembers)
validationErrors = append(validationErrors, err)
}

// Verify name field
if roomConfig.name != "" {
if name != roomConfig.name {
err = fmt.Errorf("Room %s has name '%s', expected '%s'", matchedAlias, name, roomConfig.name)
validationErrors = append(validationErrors, err)
}
} else {
if name != "" {
err = fmt.Errorf("Room %s has unexpected name '%s', expected no name", matchedAlias, name)
validationErrors = append(validationErrors, err)
}
}

// Verify topic field
if roomConfig.topic != "" {
if topic != roomConfig.topic {
err = fmt.Errorf("Room %s has topic '%s', expected '%s'", matchedAlias, topic, roomConfig.topic)
validationErrors = append(validationErrors, err)
}
} else {
if topic != "" {
err = fmt.Errorf("Room %s has unexpected topic '%s', expected no topic", matchedAlias, topic)
validationErrors = append(validationErrors, err)
}
}

if len(validationErrors) > 0 {
for _, e := range validationErrors {
t.Logf("Validation error for room %s: %s", matchedAlias, e.Error())
}

return false
}

// Mark this room as correctly found
foundRooms[matchedAlias] = true

t.Logf("Successfully validated room %s", matchedAlias)
}

// Check if we found all our rooms
if len(foundRooms) != len(createdRooms) {
missing := []string{}
for alias := range createdRooms {
if !foundRooms[alias] {
missing = append(missing, alias)
}
}
t.Logf("Missing rooms in public list: %v (found %d/%d)", missing, len(foundRooms), len(createdRooms))

if len(unexpectedRooms) > 0 {
t.Logf("Also found unexpected rooms: %v", unexpectedRooms)
}
return false
}

t.Logf("All %d rooms found with correct name/topic data", len(foundRooms))
return true
}),
)
})
})
}
Loading