feat(channels): add inherited global compaction notice policy
This commit is contained in:
1 parent
7644d845b4
commit
ab6d5f1d3c
35 files changed
+287
-37
No files matched your search
@@ -1,6 +1,11 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
|
||||
from nanobot.channels.contracts import channel_default_config, channel_instance_specs
|
||||
from nanobot.channels.manager import ChannelManager
|
||||
from nanobot.channels.registry import load_channel_plugin
|
||||
from nanobot.config.loader import load_config, save_config
|
||||
from nanobot.config.schema import Config
|
||||
from nanobot.webui.settings_system import (
|
||||
coerce_channel_value,
|
||||
@@ -65,3 +70,48 @@ def test_channel_secret_is_cleared_only_by_explicit_null() -> None:
|
||||
|
||||
assert saved == ["channels.matrix.password"]
|
||||
assert config.channels.matrix["password"] == ""
|
||||
|
||||
|
||||
@pytest.mark.parametrize("existing_key", ["showCompactionNotices", "show_compaction_notices"])
|
||||
def test_compaction_notice_webui_contract_and_config_round_trip(existing_key, tmp_path):
|
||||
name = "qq"
|
||||
plugin = load_channel_plugin(name)
|
||||
spec = plugin.setup
|
||||
field = next(item for item in spec.to_public_dict(name)["fields"]
|
||||
if item["field"] == "showCompactionNotices")
|
||||
assert field["kind"] == "bool"
|
||||
assert field["inheritable"] is True
|
||||
assert "default_value" not in field
|
||||
assert channel_default_config(plugin).get("showCompactionNotices") is None
|
||||
config = Config.model_validate({
|
||||
"channels": {"showCompactionNotices": True, name: {existing_key: False}},
|
||||
})
|
||||
key = f"channels.{name}.showCompactionNotices"
|
||||
manager = ChannelManager.__new__(ChannelManager)
|
||||
# The generic settings route must preserve false, true and a return to inheritance.
|
||||
for submitted, expected in [("false", False), ("true", True), ("", None), (None, None)]:
|
||||
save_channel_config_values(
|
||||
config, name, {key: submitted}, load_channel_plugin=load_channel_plugin,
|
||||
)
|
||||
config_path = tmp_path / "config.json"
|
||||
save_config(config, config_path)
|
||||
config = load_config(config_path)
|
||||
assert config.channels.show_compaction_notices is True
|
||||
section = getattr(config.channels, name)
|
||||
[instance] = channel_instance_specs(plugin, section, enabled_only=False)
|
||||
assert instance.config.get("showCompactionNotices") is expected
|
||||
assert "show_compaction_notices" not in instance.config
|
||||
if expected is None:
|
||||
# Inheritance is persisted as absence, also readable by older QQ versions.
|
||||
assert "showCompactionNotices" not in instance.config
|
||||
assert manager._resolve_bool_override(
|
||||
instance.config, "show_compaction_notices", True,
|
||||
) is (True if expected is None else expected)
|
||||
|
||||
|
||||
def test_saving_other_qq_settings_does_not_pin_the_global_notice_policy():
|
||||
config = Config.model_validate({"channels": {"showCompactionNotices": True}})
|
||||
save_channel_config_values(
|
||||
config, "qq", {"appId": "a", "secret": "s"}, load_channel_plugin=load_channel_plugin,
|
||||
)
|
||||
assert config.channels.qq.get("showCompactionNotices") is None
|
||||
Reference in new issue
Block a user