Skip to content

fix: set avatar_url in TestRoomState test - #939

Merged
MadLittleMods merged 2 commits into
matrix-org:mainfrom
RasmusRendal:RasmusRendal/null_avatar_url
Nov 9, 2026
Merged

MadLittleMods merged 2 commits into
matrix-org:mainfrom
RasmusRendal:RasmusRendal/null_avatar_url

Conversation

@RasmusRendal

@RasmusRendal RasmusRendal commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Context is that when no avatar is set, Synapse still returns {"avatar_url": null} in response to /joined_members. But null isn't really a valid avatar_url value according to the Matrix spec and Arminius (another homeserver implementation) aligns with the Matrix spec here (omit avatar_url when not set).

As @MadLittleMods explained below, we should either:

a) add an actual avatar_url and assert JSONKeyPresent or b) no avatar and expect JSONKeyMissing.

To play nice with Synapse and Arminius, we go with option a.

Pull Request Checklist

@RasmusRendal
RasmusRendal requested review from a team as code owners October 22, 2026 11:47
@RasmusRendal
RasmusRendal requested review from MadLittleMods and removed request for a team October 22, 2026 11:47
Comment thread tests/csapi/apidoc_room_state_test.go Outdated
match.JSONKeyPresent("joined." + authedClient.UserID),
match.JSONKeyPresent("joined." + authedClient.UserID + ".display_name"),
match.JSONKeyPresent("joined." + authedClient.UserID + ".avatar_url"),
match.JSONKeyMissingOrNull("joined." + authedClient.UserID + ".avatar_url"),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What's spawning this change? Why did you create the PR?

Another homeserver implementation?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oh right, this change is motivated by work on the Arminius homeserver implementation :)

We use ruma types, which tend to prefer leaving keys out rather than setting them to null, which is causing us to fail this test in particular.
I haven't looked at it in depth, but I could imagine that Continuwuity fails this test for similar reasons.

Comment thread tests/csapi/apidoc_room_state_test.go Outdated
match.JSONKeyPresent("joined." + authedClient.UserID),
match.JSONKeyPresent("joined." + authedClient.UserID + ".display_name"),
match.JSONKeyPresent("joined." + authedClient.UserID + ".avatar_url"),
match.JSONKeyMissingOrNull("joined." + authedClient.UserID + ".avatar_url"),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The test doesn't have a description but if the point of this test is to assert the shape of the response, feels like we should either a) add an actual avatar_url and assert JSONKeyPresent or b) no avatar and expect JSONKeyMissing.

Option a) would allow Synapse to keep passing with this specific test and have the best coverage if we only have a single test to cover this 🤷

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I went for a), because it feels quite mean to make Synapse (and the other homeservers that already pass here) fail a test when they're not strictly speaking breaking the spec

Comment thread tests/csapi/apidoc_room_state_test.go Resolved
@RasmusRendal
RasmusRendal force-pushed the RasmusRendal/null_avatar_url branch 3 times, most recently from a6a8326 to 17a41b5 Compare October 27, 2026 08:34
@MadLittleMods
MadLittleMods self-requested a review October 27, 2026 14:38
@RasmusRendal RasmusRendal changed the title fix: allow non-present avatar_url in addition to explicit null fix: set avatar_url in TestRoomState test Oct 28, 2026
@RasmusRendal
RasmusRendal force-pushed the RasmusRendal/null_avatar_url branch from 17a41b5 to 92d2d3f Compare October 28, 2026 13:35
Comment thread tests/csapi/apidoc_room_state_test.go Outdated
t.Run("GET /rooms/:room_id/joined_members fetches my membership", func(t *testing.T) {
t.Parallel()

avatarURL := "mxc://example.com/SEsfnsuifSDFSSEF"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Matches the mxc:// URL we've already used elsewhere 👍

avatarURL := "mxc://example.com/SEsfnsuifSDFSSEF"

Comment thread tests/csapi/apidoc_room_state_test.go Resolved
Previously the test would expect `avatar_url` to be `null`, failing on
tests where the `avatar_url` would be non-present when unset.
Now we set an `avatar_url` to make sure that the key is set.

Signed-off-by: Rasmus Rendal <r.kjaer@famedly.com>
…hip test

We know the type and the entire key in these two cases, so we might as
well test it.

Signed-off-by: Rasmus Rendal <r.kjaer@famedly.com>
@RasmusRendal
RasmusRendal force-pushed the RasmusRendal/null_avatar_url branch from 92d2d3f to 601d1df Compare November 9, 2026 07:37
@MadLittleMods
MadLittleMods self-requested a review November 9, 2026 22:42
@MadLittleMods
MadLittleMods merged commit 612bdc1 into matrix-org:main Nov 9, 2026
6 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.

2 participants