#!/bin/bash set -euo pipefail ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" ROOT="$ROOT" PYTHONPATH="$ROOT/lib" python3 - <<'PY' import os, pathlib, runpy, subprocess, sys, tempfile from classroom_config import ui_scale root = pathlib.Path(os.environ['ROOT']) helper = runpy.run_path(str(root/'scripts/classroom-set-scale')) original = '# keep this\nCHANNEL=classroom-v2\nMQTT_PASSWORD=literal $ and = characters\nUI_SCALE=1.25\nCUSTOM=x\nUI_SCALE=1.5\n' result = helper['updated'](original, 2.0) assert 'MQTT_PASSWORD=literal $ and = characters\n' in result assert result.count('UI_SCALE=') == 1 assert helper['updated'](result, 2.0) == result assert 'CUSTOM=x\n' in result assert ui_scale({'UI_SCALE': '2'}) == 2 assert ui_scale({'UI_SCALE': '3'}) == 3 for bad in ('nan', 'inf', '-inf', 'oops'): assert ui_scale({'UI_SCALE': bad}) == 1 assert ui_scale({'UI_SCALE': '999'}) == 3 assert ui_scale({'UI_SCALE': '-1'}) == 0.8 # Run the actual migration's config code in a temporary directory: no services. script = (root/'scripts/classroom-migrate').read_text() code = script.split("<<'PY'\n", 1)[1].split('\nPY\n', 1)[0] with tempfile.TemporaryDirectory() as tmp: path = pathlib.Path(tmp)/'device.conf' for channel in ('stable', 'canary', 'hyprland', 'classroom-v2', 'custom'): path.write_text(original.replace('CHANNEL=classroom-v2', 'CHANNEL='+channel)) subprocess.run([sys.executable, '-c', code, str(path)], check=True, capture_output=True) # The experiment's channel and hyprland come home to stable; # everything anybody chose deliberately is left alone. expected = 'stable' if channel in ('classroom-v2', 'hyprland') else channel assert 'CHANNEL='+expected+'\n' in path.read_text() assert 'MQTT_PASSWORD=literal $ and = characters\n' in path.read_text() print('Display settings: scale bounds, config preservation, idempotence and channel migration passed.') PY