-
Notifications
You must be signed in to change notification settings - Fork 3
feat: tim version config flag #241
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
base: master
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| # | ||
| # This file is licensed under the Affero General Public License (AGPL) version 3. | ||
| # | ||
| # Copyright (C) 2026 Famedly GmbH | ||
| # | ||
| # 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>. | ||
| # | ||
|
|
||
| from typing import Any | ||
|
|
||
| from synapse.config._base import Config, ConfigError | ||
| from synapse.types import JsonDict | ||
|
|
||
| VALID_TIM_VERSIONS = ("1.1", "1.2") | ||
|
|
||
|
|
||
| class TimConfig(Config): | ||
| """Config section for TIM-specific settings.""" | ||
|
|
||
| section = "tim" | ||
|
|
||
| def read_config(self, config: JsonDict, **kwargs: Any) -> None: | ||
| tim_version = config.get("tim_version", "1.1") | ||
|
|
||
| if tim_version not in VALID_TIM_VERSIONS: | ||
| raise ConfigError( | ||
| f"tim_version must be one of {', '.join(VALID_TIM_VERSIONS)}, " | ||
| f"got {tim_version!r}", | ||
| ("tim_version",), | ||
| ) | ||
|
|
||
| self.tim_version: str = tim_version | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,57 @@ | ||||||||||||||||||
| # | ||||||||||||||||||
| # This file is licensed under the Affero General Public License (AGPL) version 3. | ||||||||||||||||||
| # | ||||||||||||||||||
| # Copyright (C) 2026 Famedly GmbH | ||||||||||||||||||
| # | ||||||||||||||||||
| # 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>. | ||||||||||||||||||
| # | ||||||||||||||||||
|
|
||||||||||||||||||
| from synapse.config import ConfigError | ||||||||||||||||||
| from synapse.config.homeserver import HomeServerConfig | ||||||||||||||||||
|
|
||||||||||||||||||
| from tests.unittest import TestCase | ||||||||||||||||||
| from tests.utils import default_config | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
||||||||||||||||||
| class TimConfigTestCase(TestCase): | ||||||||||||||||||
| def _parse_config(self, extra: dict) -> HomeServerConfig: | ||||||||||||||||||
| config_dict = {**default_config("test"), **extra} | ||||||||||||||||||
| config = HomeServerConfig() | ||||||||||||||||||
| config.parse_config_dict(config_dict, "", "") | ||||||||||||||||||
| return config | ||||||||||||||||||
|
|
||||||||||||||||||
| def test_default_tim_version(self) -> None: | ||||||||||||||||||
| """tim_version defaults to '1.1' when not set.""" | ||||||||||||||||||
| config = self._parse_config({}) | ||||||||||||||||||
| self.assertEqual(config.tim.tim_version, "1.1") | ||||||||||||||||||
|
|
||||||||||||||||||
|
Comment on lines
+29
to
+33
|
||||||||||||||||||
| def test_tim_version_1_1(self) -> None: | ||||||||||||||||||
| """tim_version can be explicitly set to '1.1'.""" | ||||||||||||||||||
| config = self._parse_config({"tim_version": "1.1"}) | ||||||||||||||||||
| self.assertEqual(config.tim.tim_version, "1.1") | ||||||||||||||||||
|
|
||||||||||||||||||
| def test_tim_version_1_2(self) -> None: | ||||||||||||||||||
| """tim_version can be set to '1.2'.""" | ||||||||||||||||||
| config = self._parse_config({"tim_version": "1.2"}) | ||||||||||||||||||
| self.assertEqual(config.tim.tim_version, "1.2") | ||||||||||||||||||
|
|
||||||||||||||||||
| def test_invalid_tim_version_rejected(self) -> None: | ||||||||||||||||||
| """An invalid tim_version should raise ConfigError.""" | ||||||||||||||||||
| with self.assertRaises(ConfigError): | ||||||||||||||||||
| self._parse_config({"tim_version": "2.0"}) | ||||||||||||||||||
|
|
||||||||||||||||||
| def test_invalid_tim_version_string(self) -> None: | ||||||||||||||||||
| """A non-version string should raise ConfigError.""" | ||||||||||||||||||
| with self.assertRaises(ConfigError): | ||||||||||||||||||
| self._parse_config({"tim_version": "invalid"}) | ||||||||||||||||||
|
|
||||||||||||||||||
| def test_invalid_tim_version_numeric(self) -> None: | ||||||||||||||||||
| """A numeric (non-string) tim_version should raise ConfigError.""" | ||||||||||||||||||
| with self.assertRaises(ConfigError): | ||||||||||||||||||
| self._parse_config({"tim_version": 1.1}) | ||||||||||||||||||
|
Comment on lines
+54
to
+57
|
||||||||||||||||||
| def test_invalid_tim_version_numeric(self) -> None: | |
| """A numeric (non-string) tim_version should raise ConfigError.""" | |
| with self.assertRaises(ConfigError): | |
| self._parse_config({"tim_version": 1.1}) | |
| def test_tim_version_numeric_coerced(self) -> None: | |
| """A numeric tim_version is accepted by coercing it to a string.""" | |
| config = self._parse_config({"tim_version": 1.1}) | |
| self.assertEqual(config.tim.tim_version, "1.1") |
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.
tim_versionvalues in YAML may be parsed as numbers if unquoted (e.g.tim_version: 1.2). Currently those will always be rejected because you're comparing against string literals. Consider coercingtim_versiontostr(similar to howdefault_room_versionis handled) before validation, or at least raise a clearer error telling users to quote the value.