mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-06 19:01:54 +00:00
Modules imported by tests run inside the same pytest process as the tests themselves. Raw ``path.read_text(...)`` calls in those modules bypass the cache the tests just populated. ``roles/`` stays excluded (deployed scripts have no ``utils/`` on PYTHONPATH); ``utils/cache/`` stays excluded (cache implementation itself). Five conversions to ``utils.cache.files.read_text``: - ``utils/handler/yaml.py`` (YAML loader, read-only) - ``utils/annotations/summarize.py`` (CI log scanner, with ``UnicodeDecodeError`` fallback replacing ``errors="replace"``) - ``cli/meta/roles/applications/resolution/combined/__main__.py`` (single-shot CLI JSON input) - ``cli/core/help.py`` (read_folder_title + read_folder_description; same README is read many times across CLI help iteration) Eight ``# nocheck: cache-read`` markers, each annotated inline: - ``utils/claude/settings_sort.py`` (read then rewrite sorted) - ``utils/docker/version_updater.py`` (read then rewrite config) - ``cli/administration/deploy/development/network.py`` (tests mock ``Path.read_text`` directly; caching would bypass the mock) - ``cli/administration/deploy/development/log_utils.py`` (append flow) - ``cli/contributing/changelog/archive/changelog_md.py``, ``__main__.py``, ``package_mirror.py`` (file mutated in same flow) Two callers refactored to variable extraction so ruff's 88-char wrap keeps the ``# nocheck`` marker on the ``read_text(...)`` AST span line (``cli/.../network.py`` and ``package_mirror.py:105``). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
41 lines
1.1 KiB
Python
41 lines
1.1 KiB
Python
from __future__ import annotations
|
|
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
from typing import TYPE_CHECKING
|
|
|
|
if TYPE_CHECKING:
|
|
from collections.abc import Mapping
|
|
|
|
DOCKER_DAEMON_CONFIG_PATH = Path("/etc/docker/daemon.json")
|
|
MIN_VALID_MTU = 576
|
|
MAX_VALID_MTU = 9000
|
|
|
|
|
|
def detect_outer_network_mtu(
|
|
env: Mapping[str, str] | None = None,
|
|
*,
|
|
daemon_config_path: Path = DOCKER_DAEMON_CONFIG_PATH,
|
|
) -> str | None:
|
|
current_env = os.environ if env is None else env
|
|
explicit_mtu = current_env.get("INFINITO_OUTER_NETWORK_MTU", "").strip()
|
|
if explicit_mtu:
|
|
return explicit_mtu
|
|
|
|
if not daemon_config_path.exists():
|
|
return None
|
|
|
|
try:
|
|
# nocheck below: single-shot CLI read; tests mock Path.read_text directly
|
|
raw = daemon_config_path.read_text() # nocheck: cache-read
|
|
daemon_config = json.loads(raw)
|
|
except (json.JSONDecodeError, OSError):
|
|
return None
|
|
|
|
mtu = daemon_config.get("mtu")
|
|
if isinstance(mtu, int) and MIN_VALID_MTU <= mtu <= MAX_VALID_MTU:
|
|
return str(mtu)
|
|
|
|
return None
|