""" The Node page offers `connection_processes`, bounded by the machine's cores. The node refuses a number above its core count, so a field that let one be typed would be a field whose Save fails. The ceiling comes with the settings (`cpu_count`, which the node adds and ignores when it is sent back). """ import re from pathlib import Path STATIC = Path(__file__).resolve().parents[1] / "src" / "meshbay_hub" / "static" def _field() -> str: src = (STATIC / "node-page.js").read_text(encoding="utf-8") at = src.index("t('node.setting_connection_processes')") return src[at:src.index("", at)] def test_the_field_cannot_hold_more_than_the_cores(): field = _field() assert "max=${editSettings.cpu_count || 1}" in field assert re.search(r"Math\.min\(Math\.max\(parseInt\(e\.target\.value\) \|\| 1, 1\), " r"s\.cpu_count \|\| 1\)", field), ( "a typed value is not held to the ceiling, only the spinner is") def test_it_says_how_many_cores_there_are(): assert "t('node.setting_unit_of', { n: editSettings.cpu_count || 1 })" in _field() def test_every_language_names_it(): for locale in sorted((STATIC / "locales").glob("*.js")): text = locale.read_text(encoding="utf-8") assert "'node.setting_connection_processes':" in text, locale.name m = re.search(r"'node\.setting_unit_of': '([^']*)'", text) assert m and "{n}" in m.group(1), locale.name