Files
gitlab-instance-0a899031_sh/d2ypp2/tests/test_neko_config.py
root fa422fb7b8 s
2026-05-18 13:49:53 +00:00

117 lines
6.8 KiB
Python

from __future__ import annotations
import json
import unittest
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
class NekoConfigTests(unittest.TestCase):
def test_browser_launch_cleanup_script_still_prunes_profile_bloat(self) -> None:
script = (ROOT / "services" / "neko" / "browser-launch.sh").read_text(encoding="utf-8")
self.assertIn("arch=\"$(uname -m", script)
self.assertIn("--disable-software-rasterizer", script)
self.assertIn("--use-gl=swiftshader", script)
self.assertIn("NEKO_BROWSER_RENDER_MODE", script)
self.assertIn("--start-minimized", script)
self.assertIn("--disable-background-networking", script)
self.assertIn('prune_path "$profile_dir/BrowserMetrics"', script)
self.assertIn('prune_path "$profile_dir/Crash Reports"', script)
self.assertIn('prune_path "$profile_dir/SingletonLock"', script)
self.assertIn('prune_path "$profile_dir/Default/Code Cache"', script)
def test_browser_policies_default_to_allowed_permissions(self) -> None:
policies = json.loads((ROOT / "services" / "neko" / "policies" / "policies.json").read_text(encoding="utf-8"))
self.assertEqual(policies["DefaultNotificationsSetting"], 1)
self.assertEqual(policies["DefaultGeolocationSetting"], 1)
self.assertTrue(policies["VideoCaptureAllowed"])
self.assertTrue(policies["AudioCaptureAllowed"])
self.assertEqual(policies["DeveloperToolsAvailability"], 1)
def test_google_chrome_supervisor_uses_direct_stable_command(self) -> None:
conf = (ROOT / "services" / "neko" / "google-chrome.conf").read_text(encoding="utf-8")
self.assertIn("command=/etc/neko/browser-launch.sh google-chrome", conf)
self.assertNotIn("--bwsi", conf)
self.assertIn("autorestart=true", conf)
self.assertIn("[program:openbox]", conf)
self.assertIn("/usr/bin/openbox --config-file /etc/neko/openbox.xml", conf)
script = (ROOT / "services" / "neko" / "browser-launch.sh").read_text(encoding="utf-8")
self.assertIn('profile_dir="/home/neko/.config/google-chrome"', script)
self.assertIn('--user-data-dir="$profile_dir"', script)
def test_chromium_supervisor_uses_direct_stable_command(self) -> None:
conf = (ROOT / "services" / "neko" / "chromium.conf").read_text(encoding="utf-8")
self.assertIn("command=/etc/neko/browser-launch.sh chromium", conf)
self.assertNotIn("--bwsi", conf)
self.assertIn("autorestart=true", conf)
self.assertIn("[program:openbox]", conf)
script = (ROOT / "services" / "neko" / "browser-launch.sh").read_text(encoding="utf-8")
self.assertIn('profile_dir="/home/neko/.config/chromium"', script)
self.assertIn('--user-data-dir="$profile_dir"', script)
def test_neko_compose_mounts_only_selected_supervisor_conf(self) -> None:
compose = (ROOT / "services" / "neko" / "docker-compose.yml").read_text(encoding="utf-8")
self.assertIn("./${NEKO_BROWSER_SUPERVISOR_CONF}:/etc/neko/supervisord/browser.conf:ro", compose)
self.assertIn("./browser-launch.sh:/etc/neko/browser-launch.sh:ro", compose)
self.assertIn("container_name: live-neko-1", compose)
self.assertIn("container_name: live-neko-2", compose)
self.assertIn("container_name: live-neko-3", compose)
self.assertIn("${NEKO_HTTP_PORT_1}:8080", compose)
self.assertIn("${NEKO_HTTP_PORT_2}:8080", compose)
self.assertIn("${NEKO_HTTP_PORT_3}:8080", compose)
self.assertNotIn("./chromium.conf:/etc/neko/supervisord/chromium.conf:ro", compose)
self.assertNotIn("./google-chrome.conf:/etc/neko/supervisord/google-chrome.conf:ro", compose)
def test_supervisor_uses_browser_launch_script(self) -> None:
chrome = (ROOT / "services" / "neko" / "google-chrome.conf").read_text(encoding="utf-8")
chromium = (ROOT / "services" / "neko" / "chromium.conf").read_text(encoding="utf-8")
self.assertIn("command=/etc/neko/browser-launch.sh google-chrome", chrome)
self.assertIn("command=/etc/neko/browser-launch.sh chromium", chromium)
self.assertNotIn("--start-maximized", chrome)
self.assertNotIn("--start-maximized", chromium)
def test_neko_scripts_use_family_specific_profile_dirs(self) -> None:
service_ctl = (ROOT / "scripts" / "linux" / "service_ctl.sh").read_text(encoding="utf-8")
common = (ROOT / "scripts" / "linux" / "lib" / "common.sh").read_text(encoding="utf-8")
self.assertIn("resolve_neko_profile_dir()", service_ctl)
self.assertIn('${family}-profile-v2', service_ctl)
self.assertIn("resolve_neko_profile_dir()", common)
self.assertIn('${family}-profile-v2', common)
self.assertIn("resolve_neko_profile_dir_for_instance()", service_ctl)
self.assertIn("NEKO_HTTP_PORT_2", service_ctl)
self.assertIn("NEKO_WEBRTC_UDP_RANGE_3", service_ctl)
self.assertIn("resolve_neko_profile_dir_for_instance()", common)
self.assertIn("NEKO_HTTP_PORT_2", common)
self.assertIn("NEKO_WEBRTC_UDP_RANGE_3", common)
def test_neko_ip_watcher_is_installed_and_restarts_on_drift(self) -> None:
common = (ROOT / "scripts" / "linux" / "lib" / "common.sh").read_text(encoding="utf-8")
watcher = (ROOT / "scripts" / "linux" / "neko_ip_watch.sh").read_text(encoding="utf-8")
upgrade = (ROOT / "scripts" / "linux" / "upgrade_live_console.sh").read_text(encoding="utf-8")
uninstall = (ROOT / "scripts" / "linux" / "uninstall_stack.sh").read_text(encoding="utf-8")
stack_env = (ROOT / "config" / "system-stack.env.example").read_text(encoding="utf-8")
self.assertIn("install_neko_ip_watch_service()", common)
self.assertIn("live-neko-ip-watch.service", common)
self.assertIn("ExecStart=/bin/bash", common)
self.assertIn("scripts/linux/neko_ip_watch.sh", common)
self.assertIn("detect_preferred_lan_ip", watcher)
self.assertIn('bash "$SERVICE_CTL" neko restart', watcher)
self.assertIn("NEKO_IP_WATCH_INTERVAL", watcher)
self.assertIn("install_neko_ip_watch_service", upgrade)
self.assertIn("live-neko-ip-watch.service", uninstall)
self.assertIn("NEKO_IP_WATCH_INTERVAL=15", stack_env)
def test_local_browser_prefers_chrome_on_x86_and_chromium_elsewhere(self) -> None:
script = (ROOT / "scripts" / "linux" / "launch_browser.sh").read_text(encoding="utf-8")
self.assertIn("x86_64|amd64", script)
x86_branch = script.split("x86_64|amd64)", 1)[1].split(";;", 1)[0]
other_branch = script.split("*)", 1)[1].split(";;", 1)[0]
self.assertLess(x86_branch.find("google-chrome"), x86_branch.find("chromium"))
self.assertLess(other_branch.find("chromium"), other_branch.find("google-chrome"))
if __name__ == "__main__":
unittest.main()