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

MSC3030 Jump to date API endpoint #178

Merged
merged 23 commits into from
Mar 3, 2022

Conversation

MadLittleMods
Copy link
Contributor

@MadLittleMods MadLittleMods commented Jul 28, 2021

Add tests to ensure MSC3030 Jump to date functionality

MSC3030: matrix-org/matrix-spec-proposals#3030

Synapse implementation: matrix-org/synapse#9445


Includes nice debug statements when a test fails which give us the full history of messages in the room with color coding to show the expected and actual event alongside where the given timestamp fits into the list of events.

    msc3030_test.go:37: Expected to see $XQvueEX5r9wLDhH15tXm_weWOQ-JlTU4o2JWkkwnYC0 given 1638506547868 but received $XQvueEX5r9wLDhH15tXm_weWOQ-JlTU4o2JWkkwnYC0
                   -- oldest events --
             (got) $lapGquM-EboC-7FTGMYKw8LheBYqjobb6j0M2AusS3k (1638506547354) - m.room.create
                   $FkBUU9NGgvYJwQ_ofXsNm-omUTO6mkUnGBFj2kOiJJ8 (1638506547442) - m.room.member
                   $faI0p28WHp-8fnUskgDrngBpXVkxWgzTFOEuJ-a0JHk (1638506547536) - m.room.power_levels
                   $3AYYdSHWG-NvWoIoDmtEDXl073yGFpz9aJn7ftSwJlg (1638506547695) - m.room.join_rules
                   $_hHlabu_rAycc78meQX8Y-M-IBv_PQth0X5Ybt41Jp4 (1638506547792) - m.room.history_visibility
                   -- givenTimestamp=1638506547868 --
            (want) $XQvueEX5r9wLDhH15tXm_weWOQ-JlTU4o2JWkkwnYC0 (1638506547919) - m.room.message
                   $sU76QDNGmARqRCgGMoZ6vwtq9JvccO7nWyLD-qNp3hs (1638506548108) - m.room.message
                   -- newest events --

Dev notes

COMPLEMENT_ALWAYS_PRINT_SERVER_LOGS=1 COMPLEMENT_DIR=../complement ./scripts-dev/complement.sh TestJumpToDateEndpoint

// GetEvent fetches the given event from the specified room and returns a typed Event
func (c *CSAPI) GetEvent(t *testing.T, roomID, eventId string) b.Event {
	t.Helper()
	res := c.MustDoFunc(t, "GET", []string{"_matrix", "client", "r0", "rooms", roomID, "event", eventId})
	body := ParseJSON(t, res)

	statKeyRes := gjson.GetBytes(body, "state_key")
	var stateKey *string = nil
	if statKeyRes.Exists() {
		stateKey = b.Ptr(statKeyRes.Str)
	}

	return b.Event{
		Type:     GetJSONFieldStr(t, body, "type"),
		Sender:   GetJSONFieldStr(t, body, "sender"),
		StateKey: stateKey,
		Content:  GetJSONFieldStringMap(t, body, "content"),
		Unsigned: GetJSONFieldStringMap(t, body, "unsigned"),
	}
}


func GetJSONFieldStringMap(t *testing.T, body []byte, wantKey string) map[string]interface{} {
	t.Helper()

	res := gjson.GetBytes(body, wantKey)

	if !res.Exists() {
		t.Fatalf("GetJSONFieldStringMap: key '%s' missing from %s", wantKey, string(body))
	}

	jsonMap := map[string]interface{}{}
	res.ForEach(func(key, value gjson.Result) bool {
		jsonMap[key.Str] = value.Str

		// Keep iterating
		return true
	})

	return jsonMap
}
	logrus.WithFields(logrus.Fields{
		"stack": string(debug.Stack()),
	}).Error("destroy stack")
	
	logrus.WithFields(logrus.Fields{
		"mounts": fmt.Sprintf("%+v", mounts),
	}).Error("ContainerCreate")

Todo

  • Add sanity check test to make sure that you can't query for an event in a private room you're not invited to

@MadLittleMods MadLittleMods marked this pull request as draft July 28, 2021 05:42
@MadLittleMods MadLittleMods changed the title Draft: MSC3030 Jump to date API endpoint MSC3030 Jump to date API endpoint Nov 17, 2021
This test does not work because redacted versions of the events
are backfilled which include the event_id and origin_server_ts
necessary to find it. We just can't see the contents of the message.
So it's ok that this test fails.

See matrix-org/synapse#9445 (comment)
The history visiblity of the room does not matter.
We still return redacted versions of the events regardless
of if you can see the event according to the history visiblity.
MadLittleMods added a commit to matrix-org/synapse that referenced this pull request Dec 2, 2021
… time of merge

Complement tests are in matrix-org/complement#178
but haven't had any review and not sure when they will merge.
Conflicts:
	dockerfiles/synapse/homeserver.yaml
	dockerfiles/synapse/workers-shared.yaml
tests/msc3030_test.go Outdated Show resolved Hide resolved
tests/msc3030_test.go Outdated Show resolved Hide resolved
@MadLittleMods MadLittleMods merged commit 0399188 into main Mar 3, 2022
@MadLittleMods MadLittleMods deleted the madlittlemods/msc3030-jump-to-date branch March 3, 2022 04:59
@MadLittleMods
Copy link
Contributor Author

Thanks for the review @kegsay 🐅

MadLittleMods added a commit to matrix-org/synapse that referenced this pull request Mar 3, 2022
The Complement tests for MSC3030 are now merged, matrix-org/complement#178

Synapse implmentation: #9445
babolivier pushed a commit to matrix-org/synapse that referenced this pull request Mar 3, 2022
The Complement tests for MSC3030 are now merged, matrix-org/complement#178

Synapse implmentation: #9445
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