#!/usr/bin/env python3 """Checks preferences_get and preferences_set against the Preferences dialog. Its design is the test_preferences entry of tools/mcp/test-entries/commands.md. tools/mcp/orca_mcp.py launch --datadir tools/mcp/test_preferences.py On each of the dialog's tabs (window_open, then widget_list of the dialog), the controls named after a key are the keys preferences_get lists for that tab. The MCP server's switch and port read as the dialog shows them: on, and the port this session's launch gave. preferences_set writes a checkbox, a choice and a number in one call, and each reads back from preferences_get and from its control in the dialog opened again. A preference read at the next start says so in preferences_get and in the reply. A call with a good key and a refused one (the language) changes nothing, and so does a value no choice has. The backup period runs the backup timer only while Auto backup is on, read from the timer's log line. The downloads folder takes a folder this test makes in its own temporary folder, which preferences_get and the dialog's row then show, and refuses one that does not exist; while the dialog is open a call cannot write it, and its Browse button, answered with another such folder, shows that folder in the open dialog's row. Hide login side panel, whose control has an effect in the app (Ops::apply_preference()): the Home page hides its login side panel as soon as preferences_set writes it, without the dialog, and shows it again when it is written back. Last, preset sync and stealth mode are written on and off again: with no account signed in, turning sync on starts no sync, and stealth mode signs out of no account. It starts from the Generic Klipper Printer and the baseline's preferences, and first sets the two that its write puts back to the app's defaults away from them. It writes only preferences whose effect stays inside the app it drives; it signs in to nothing and needs no network. Exits 0 when every check passes. """ import os import re import sys import tempfile sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) import checks as shared # noqa: E402 import orca_mcp # noqa: E402 from orca_mcp import McpError # noqa: E402 TABS = ["general", "files", "behaviour", "control", "graphics", "online", "developer"] # A widget_list line of a control named after a key: its kind, its label and value, its name and its state. CONTROL = re.compile(r'^\s*\[w\d+\] (\w+)(?: "(?P