Files
synapse/tests/config/test_experimental.py
Erik JohnstonandClaude Opus 5.5 e6d308b578 Accept YAML booleans for rust_state_res
YAML reads an unquoted on or off as a boolean, so rust_state_res: on
failed config validation. Map true and false to "on" and "off", and
quote the value the Complement start script writes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ULdieJyQoHNzeHq42H2M1p
2026-10-13 13:22:07 +00:00

92 lines
2.9 KiB
Python

#
# 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>.
import yaml
from parameterized import parameterized
from synapse.config._base import ConfigError, RootConfig
from synapse.config.experimental import ExperimentalConfig
from synapse.config.homeserver import HomeServerConfig
from synapse.types import JsonDict
from tests import unittest
class ExperimentalConfigTestCase(unittest.TestCase):
@parameterized.expand(
[
[
"single",
{
"experimental_features": {
"msc3575_enabled": True,
}
},
],
[
"multi",
{
"experimental_features": {
"msc3575_enabled": True,
"msc3030_enabled": True,
}
},
],
# This has historically worked and this is being added as a regression test
["none", {"experimental_features": None}],
]
)
def test_experimental_features_parsing(
self, test_description: str, config_values: JsonDict
) -> None:
"""
Test the that `experimental_features` parses with these values
"""
_read_config(config_values)
@parameterized.expand(
[
("rust_state_res: shadow", "shadow"),
# YAML reads these as booleans.
("rust_state_res: on", "on"),
("rust_state_res: off", "off"),
("rust_state_res: 'on'", "on"),
("{}", "off"),
]
)
def test_rust_state_res(self, features_yaml: str, expected: str) -> None:
config = _read_config({"experimental_features": yaml.safe_load(features_yaml)})
self.assertEqual(config.rust_state_res, expected)
def test_rust_state_res_rejects_unknown_modes(self) -> None:
with self.assertRaises(ConfigError):
_read_config({"experimental_features": {"rust_state_res": "maybe"}})
def _read_config(config_values: JsonDict) -> ExperimentalConfig:
config = ExperimentalConfig(RootConfig())
config.read_config(
yaml.safe_load(
HomeServerConfig().generate_config(
config_dir_path="CONFDIR",
data_dir_path="/data_dir_path",
server_name="che.org",
)
)
| config_values,
allow_secrets_in_config=False,
)
return config