read the config the module writes: containers can be turned off
The module rendered containers_enabled, workspace_base, container_mode, max_containers and the pointer lease keys into the TOML, and policy.py read only [defaults] and [apps] -- so the settings were inert. The defaults coincided, which made it look honoured, until a deployment tried to turn containers off and found it could not. Settings now come from the same file: parsed beside Policy (read by __main__, so the manager keeps taking a plain ManagerConfig its tests build directly) and carried into ContainerHost, which reports itself unavailable when switched off. That is the whole mechanism -- the manager already treats an unavailable host as 'sessions without containers', which is what turning them off means -- and the reason names the key, so a disabled machine cannot be mistaken for one whose compositor is down. This is what made the rollback on the host possible; the machine had containers built, tested, and impossible to disable.
This commit is contained in:
1 parent
c1dc60af00
commit
8f3f000783
6 files changed
+221
-1
No files matched your search
@@ -0,0 +1,78 @@
|
||||
"""The config file's non-allowlist half.
|
||||
|
||||
These keys are rendered by the NixOS module and, until this existed, read by
|
||||
nothing: a deployment could turn containers off or move a lease deadline and be
|
||||
silently ignored, while the defaults happened to make it look honoured. The
|
||||
values here are therefore the ones the module actually writes -- if the module's
|
||||
shape changes, these tests are where that shows up.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
import tomllib
|
||||
|
||||
import pytest
|
||||
|
||||
from hhstreamd.policy import PolicyError, load_settings, settings_from_dict
|
||||
|
||||
#: Exactly what `nix/module.nix` renders today, through
|
||||
#: `services.hyprland-headless-stream`, with containers turned off.
|
||||
MODULE_SHAPE = """
|
||||
[defaults]
|
||||
max_sessions = 4
|
||||
idle_timeout_s = 10800
|
||||
max_containers = 2
|
||||
|
||||
[compositor]
|
||||
runtime_dir = "/run/hypr-stream"
|
||||
containers_enabled = false
|
||||
workspace_base = 1000
|
||||
container_mode = "1280x720"
|
||||
|
||||
[pointer]
|
||||
enabled = true
|
||||
lease_ttl_s = 30
|
||||
lease_max_s = 300
|
||||
|
||||
[apps.chromium]
|
||||
exec = "/nix/store/x/bin/chromium"
|
||||
args_allow = ["--ozone-platform=wayland"]
|
||||
"""
|
||||
|
||||
|
||||
def test_the_module_shape_is_read() -> None:
|
||||
settings = settings_from_dict(tomllib.loads(MODULE_SHAPE))
|
||||
|
||||
assert settings.containers_enabled is False
|
||||
# max_containers lives in [defaults] while the rest live in [compositor];
|
||||
# that split is the module's, and reading only one of them is how a budget
|
||||
# silently stops applying.
|
||||
assert settings.container_slots == 2
|
||||
assert settings.container_base == 1000
|
||||
assert settings.container_mode == (1280, 720)
|
||||
assert (settings.pointer_ttl_s, settings.pointer_max_s) == (30.0, 300.0)
|
||||
|
||||
|
||||
def test_containers_default_to_on_when_the_key_is_absent() -> None:
|
||||
"""A config written before this setting existed keeps working."""
|
||||
|
||||
assert settings_from_dict({"apps": {}}).containers_enabled is True
|
||||
|
||||
|
||||
def test_a_bad_mode_is_refused_by_name() -> None:
|
||||
"""A typo must be loud: a container at the wrong size looks like an app bug."""
|
||||
|
||||
with pytest.raises(PolicyError) as exc:
|
||||
settings_from_dict({"compositor": {"container_mode": "wide"}})
|
||||
|
||||
assert "container_mode" in str(exc.value)
|
||||
|
||||
|
||||
def test_an_absent_file_is_the_defaults(tmp_path: Path) -> None:
|
||||
"""Missing config behaves conservatively rather than refusing to start."""
|
||||
|
||||
settings = load_settings(tmp_path / "absent.toml")
|
||||
|
||||
assert settings.containers_enabled is True
|
||||
assert settings.container_mode == (1280, 720)
|
||||
Reference in new issue
Block a user