-
Notifications
You must be signed in to change notification settings - Fork 567
Add in-repo Complement test to sanity check Synapse version matches git checkout #19476
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
Changes from 21 commits
e1587cc
59df0d6
49d2d27
ce1ae57
5189af9
77ed60f
991ab59
639402b
29029e5
5293622
bc2c676
aef8a88
b58aab6
6ce2ca2
5d1a25f
4b33f3f
e8c5bad
944611c
ddfbbf8
b7bd4be
c7cb45d
107066c
0b5cb91
3f7f4f5
b1a651e
f2c92ec
7bdc821
296ba32
957d5c3
c28cd6c
7b199ab
5dd4805
4109f09
c5c5465
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -707,28 +707,28 @@ jobs: | |
| cache-dependency-path: complement/go.sum | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This PR is purposely not up to date with the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lol, trying to get this new test to fail in CI but it looks like GitHub Versus the previous GitHub Looks like this was reverted in actions/runner-images#13708 |
||
| go-version-file: complement/go.mod | ||
|
|
||
| - name: Run Complement Tests | ||
| id: run_complement_tests | ||
| # -p=1: We're using `-p 1` to force the test packages to run serially as GHA boxes | ||
| # are underpowered and don't like running tons of Synapse instances at once. | ||
| # -json: Output JSON format so that gotestfmt can parse it. | ||
| # | ||
| # tee /tmp/gotest-complement.log: We tee the output to a file so that we can re-process it | ||
| # later on for better formatting with gotestfmt. But we still want the command | ||
| # to output to the terminal as it runs so we can see what's happening in | ||
| # real-time. | ||
| run: | | ||
| set -o pipefail | ||
| COMPLEMENT_DIR=`pwd`/complement synapse/scripts-dev/complement.sh -p 1 -json 2>&1 | tee /tmp/gotest-complement.log | ||
| shell: bash | ||
| env: | ||
| POSTGRES: ${{ (matrix.database == 'Postgres') && 1 || '' }} | ||
| WORKERS: ${{ (matrix.arrangement == 'workers') && 1 || '' }} | ||
|
|
||
| - name: Formatted Complement test logs | ||
| # Always run this step if we attempted to run the Complement tests. | ||
| if: always() && steps.run_complement_tests.outcome != 'skipped' | ||
| run: cat /tmp/gotest-complement.log | gotestfmt -hide "successful-downloads,empty-packages" | ||
| # - name: Run Complement Tests | ||
| # id: run_complement_tests | ||
| # # -p=1: We're using `-p 1` to force the test packages to run serially as GHA boxes | ||
| # # are underpowered and don't like running tons of Synapse instances at once. | ||
| # # -json: Output JSON format so that gotestfmt can parse it. | ||
| # # | ||
| # # tee /tmp/gotest-complement.log: We tee the output to a file so that we can re-process it | ||
| # # later on for better formatting with gotestfmt. But we still want the command | ||
| # # to output to the terminal as it runs so we can see what's happening in | ||
| # # real-time. | ||
| # run: | | ||
| # set -o pipefail | ||
| # COMPLEMENT_DIR=`pwd`/complement synapse/scripts-dev/complement.sh -p 1 -json 2>&1 | tee /tmp/gotest-complement.log | ||
| # shell: bash | ||
| # env: | ||
| # POSTGRES: ${{ (matrix.database == 'Postgres') && 1 || '' }} | ||
| # WORKERS: ${{ (matrix.arrangement == 'workers') && 1 || '' }} | ||
|
|
||
| # - name: Formatted Complement test logs | ||
| # # Always run this step if we attempted to run the Complement tests. | ||
| # if: always() && steps.run_complement_tests.outcome != 'skipped' | ||
| # run: cat /tmp/gotest-complement.log | gotestfmt -hide "successful-downloads,empty-packages" | ||
|
MadLittleMods marked this conversation as resolved.
Outdated
|
||
|
|
||
| - name: Run in-repo Complement Tests | ||
| id: run_in_repo_complement_tests | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Add in-repo Complement test to sanity check Synapse version matches git checkout (testing what we think we are). |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| // This file is licensed under the Affero General Public License (AGPL) version 3. | ||
| // | ||
| // Copyright (C) 2026 Element Creations Ltd | ||
| // | ||
| // This program is free software: you can redistribute it and/or modify | ||
| // it under the terms of the GNU Affero General Public License as | ||
| // published by the Free Software Foundation, either version 3 of the | ||
| // License, or (at your option) any later version. | ||
| // | ||
| // See the GNU Affero General Public License for more details: | ||
| // <https://www.gnu.org/licenses/agpl-3.0.html>. | ||
|
|
||
| package synapse_tests | ||
|
|
||
| import ( | ||
| "net/http" | ||
| "os/exec" | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/matrix-org/complement" | ||
| "github.com/matrix-org/complement/match" | ||
| "github.com/matrix-org/complement/must" | ||
| "github.com/tidwall/gjson" | ||
| ) | ||
|
|
||
| func TestSynapseVersion(t *testing.T) { | ||
| deployment := complement.Deploy(t, 1) | ||
| defer deployment.Destroy(t) | ||
|
|
||
| unauthedClient := deployment.UnauthenticatedClient(t, "hs1") | ||
|
|
||
| // Sanity check that the version of Synapse used in the `COMPLEMENT_BASE_IMAGE` | ||
| // matches the same git commit we have checked out. This ensures that the image being | ||
| // used in Complement is the one that we just built locally with `complement.sh` | ||
| // instead of accidentally pulling in some remote one. | ||
| // | ||
| // This test is expected to pass if you use `complement.sh`. | ||
| // | ||
| // If this test fails, it probably means that Complement is using an image that | ||
| // doesn't encompass the changes you have checked out (unexpected). We want to yell | ||
| // loudly and point out what's wrong instead of silently letting your PR's pass | ||
| // without actually being tested. | ||
| t.Run("Synapse version matches current git checkout", func(t *testing.T) { | ||
| // Get the Synapse version details of the current git checkout | ||
| checkoutSynapseVersion := runCommand( | ||
| t, | ||
| []string{ | ||
| "poetry", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess it's not necessarily a given that people will have poetry if our
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would expect this to be updated to whatever our developer flow is ⏩ |
||
| "run", | ||
| "python", | ||
| "-c", | ||
| "from synapse.util import SYNAPSE_VERSION; print(SYNAPSE_VERSION)", | ||
| }, | ||
| ) | ||
|
|
||
| // Find the version details of the Synapse instance deployed from the Docker image | ||
| res := unauthedClient.MustDo(t, "GET", []string{"_matrix", "federation", "v1", "version"}) | ||
|
MadLittleMods marked this conversation as resolved.
|
||
| body := must.MatchResponse(t, res, match.HTTPResponse{ | ||
| StatusCode: http.StatusOK, | ||
| JSON: []match.JSON{ | ||
| match.JSONKeyPresent("server"), | ||
| }, | ||
| }) | ||
| rawSynapseVersionString := gjson.GetBytes(body, "server.version").Str | ||
| t.Logf( | ||
| "Synapse version string from federation version endpoint: %s", | ||
| rawSynapseVersionString, | ||
| ) | ||
|
|
||
| must.Equal( | ||
| t, | ||
| rawSynapseVersionString, | ||
| checkoutSynapseVersion, | ||
| "Synapse version in the checkout doesn't match the Synapse version that Complement is running. "+ | ||
| "If this test fails, it probably means that Complement is using an image that "+ | ||
| "doesn't encompass the changes you have checked out (unexpected). We want to yell "+ | ||
| "loudly and point out what's wrong instead of silently letting your PR's pass "+ | ||
|
MadLittleMods marked this conversation as resolved.
Outdated
|
||
| "without actually being tested.", | ||
| ) | ||
| }) | ||
| } | ||
|
|
||
| // runCommand will run the given command and return the stdout (whitespace | ||
| // trimmed). | ||
| func runCommand(t *testing.T, commandPieces []string) string { | ||
| t.Helper() | ||
|
|
||
| // Then run our actual command | ||
| cmd := exec.Command(commandPieces[0], commandPieces[1:]...) | ||
| output, err := cmd.Output() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that's expected as we just want the machine-readable/pipeable values from Although I don't think it matters in this case with the command we're using. Ideally, we'd print everything when the command fails 👍 |
||
| if err != nil { | ||
| t.Fatalf( | ||
| "runCommand: failed to run command (%s): %v", | ||
| strings.Join(commandPieces, " "), | ||
| err, | ||
| ) | ||
| } | ||
|
|
||
| return strings.TrimSpace(string(output)) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -171,6 +171,14 @@ FROM docker.io/library/python:${PYTHON_VERSION}-slim-${DEBIAN_VERSION} | |
|
|
||
| ARG TARGETARCH | ||
|
|
||
| # If specified, Synapse will use this as the version string in the app. | ||
| # | ||
| # This can be useful to capture the git info of the build as `.git/` won't be be | ||
|
MadLittleMods marked this conversation as resolved.
Outdated
|
||
| # available in the Docker image for Synapse to generate from. | ||
| ARG SYNAPSE_VERSION_STRING | ||
| # Pass it through to Synapse as an environment variable. | ||
| ENV SYNAPSE_VERSION_STRING=${SYNAPSE_VERSION_STRING} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (had to look up that this is actually optional, seems like it is) |
||
|
|
||
| LABEL org.opencontainers.image.url='https://github.com/element-hq/synapse' | ||
| LABEL org.opencontainers.image.documentation='https://element-hq.github.io/synapse/latest/' | ||
| LABEL org.opencontainers.image.source='https://github.com/element-hq/synapse.git' | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Putting this PR up for review to get help with the problem summarized in
#synapse-dev:matrix.org- also tracked in discussions on this PR: