"""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)