refactor(gui_2): obliterate 2 legacy wrappers _detect_refresh_rate_win32 + _resolve_font_path (Phase 6)
Phase 6 (2 of 9 cruft sites obliterated): OBLITERATED wrappers: 1. _detect_refresh_rate_win32() -> float (1 caller in App.__init__) Migrated: caller now uses _detect_refresh_rate_win32_result(...).data with explicit .ok check; on failure uses 0.0 default (no fps cap). 2. _resolve_font_path(font_path, assets_dir) -> str (1 caller in App._load_fonts) Migrated: caller now uses _resolve_font_path_result(...).data with .ok check; on failure falls back to 'fonts/Inter-Regular.ttf' (the bundled Inter). Test result: 127/127 pass. Audit gate: src/gui_2.py --strict exits 0 (no new violations). Wrapper count: 2 -> 0. PITFALL encountered: edit_file ate a def line in _apply_runtime_caps_override. The function body got attached below the OBLITERATED stub. Fixed by restoring the def line. This completes Phases 3-6 (all file-level wrapper removals). Phase 7 (remaining files) is N/A — audit found 0 wrappers in any src/ file. Next: Phase 8 (audit gate + end-of-track report + campaign close-out).
This commit is contained in:
+4
-38
@@ -224,22 +224,6 @@ def _detect_refresh_rate_win32_result() -> Result[float]:
|
||||
original=e,
|
||||
)])
|
||||
|
||||
def _detect_refresh_rate_win32() -> float:
|
||||
"""Return the primary display's current refresh rate in Hz, or 0.0 on failure.
|
||||
|
||||
Uses user32.EnumDisplaySettingsW (ENUM_CURRENT_SETTINGS) which reads the value
|
||||
directly from the display driver in microseconds. The previous implementation
|
||||
shelled out to PowerShell + WMI (Get-CimInstance Win32_VideoController), which
|
||||
cost ~350ms on every startup and blocked the first frame.
|
||||
|
||||
Legacy wrapper: delegates to _detect_refresh_rate_win32_result. Preserves
|
||||
the original signature (returns float). The call site in App.__init__
|
||||
invokes the result helper directly and drains errors to
|
||||
self._startup_timeline_errors.
|
||||
"""
|
||||
result = _detect_refresh_rate_win32_result()
|
||||
return result.data
|
||||
|
||||
def _resolve_font_path_result(font_path: str, assets_dir: Path) -> Result[str]:
|
||||
"""Drain-aware variant of _resolve_font_path (L264 INTERNAL_SILENT_SWALLOW).
|
||||
|
||||
@@ -274,26 +258,6 @@ def _resolve_font_path_result(font_path: str, assets_dir: Path) -> Result[str]:
|
||||
return Result(data=rel)
|
||||
return Result(data="fonts/Inter-Regular.ttf")
|
||||
|
||||
def _resolve_font_path(font_path: str, assets_dir: Path) -> str:
|
||||
"""Normalize a configured font path to something hello_imgui can load.
|
||||
|
||||
hello_imgui resolves relative paths against the assets folder. A config may
|
||||
carry a stale ABSOLUTE path from a different project checkout (e.g.
|
||||
C:/projects/manual_slop/assets/fonts/MapleMono-Regular.ttf after the repo
|
||||
moved to C:/projects/sloppy). In that case the absolute file does not exist
|
||||
and the load fails. This recovers by:
|
||||
|
||||
1. If the absolute path lives under the current assets folder -> relativize.
|
||||
2. If the absolute path exists on disk as-is -> keep it.
|
||||
3. Otherwise recover the basename under assets/fonts or assets.
|
||||
4. Final fallback: the bundled default Inter font.
|
||||
|
||||
Legacy wrapper: delegates to _resolve_font_path_result. Preserves the
|
||||
original signature (returns str). The call site in App._load_fonts invokes
|
||||
the result helper directly and drains errors to self._startup_timeline_errors.
|
||||
"""
|
||||
return _resolve_font_path_result(font_path, assets_dir).data
|
||||
|
||||
def _apply_runtime_caps_override(app: "App", caps: "VendorCapabilities") -> "VendorCapabilities":
|
||||
from dataclasses import replace
|
||||
if app.current_provider == "llama":
|
||||
@@ -698,7 +662,8 @@ class App:
|
||||
# PowerShell/WMI subprocess (~350ms) so the first frame is not blocked.
|
||||
fps_cap = 60.0
|
||||
if sys.platform == "win32":
|
||||
rate = _detect_refresh_rate_win32()
|
||||
rate_result = _detect_refresh_rate_win32_result()
|
||||
rate = rate_result.data if rate_result.ok else 0.0
|
||||
if rate: fps_cap = rate
|
||||
|
||||
# Enable idling with monitor refresh rate to effectively cap FPS
|
||||
@@ -751,7 +716,8 @@ class App:
|
||||
font_path, font_size = theme.get_font_loading_params()
|
||||
|
||||
if font_path:
|
||||
font_path = _resolve_font_path(font_path, assets_dir)
|
||||
font_path_result = _resolve_font_path_result(font_path, assets_dir)
|
||||
font_path = font_path_result.data if font_path_result.ok else "fonts/Inter-Regular.ttf"
|
||||
result = _load_fonts_main_result(self, font_path, font_size, config)
|
||||
if not result.ok:
|
||||
if not hasattr(self, '_startup_timeline_errors'): self._startup_timeline_errors = []
|
||||
|
||||
@@ -146,4 +146,33 @@ def test_phase5_chunk_code_caller_uses_result():
|
||||
assert len(bare_calls) == 0, (
|
||||
f"caller should not call _chunk_code (legacy wrapper); "
|
||||
f"found {len(bare_calls)} bare calls"
|
||||
)
|
||||
|
||||
|
||||
# ============ Phase 6 (gui_2 wrappers) ============
|
||||
|
||||
def test_phase6_detect_refresh_rate_wrapper_obliterated():
|
||||
"""Phase 6 invariant: the legacy _detect_refresh_rate_win32 wrapper is DELETED."""
|
||||
from src import gui_2
|
||||
assert not hasattr(gui_2, "_detect_refresh_rate_win32"), (
|
||||
"_detect_refresh_rate_win32 wrapper must be OBLITERATED."
|
||||
)
|
||||
|
||||
|
||||
def test_phase6_resolve_font_path_wrapper_obliterated():
|
||||
"""Phase 6 invariant: the legacy _resolve_font_path wrapper is DELETED."""
|
||||
from src import gui_2
|
||||
assert not hasattr(gui_2, "_resolve_font_path"), (
|
||||
"_resolve_font_path wrapper must be OBLITERATED."
|
||||
)
|
||||
|
||||
|
||||
def test_phase6_audit_finds_zero_wrappers_in_src():
|
||||
"""Phase 6 invariant: 0 legacy wrappers remain anywhere in src/."""
|
||||
r = subprocess.run(
|
||||
["uv", "run", "python", "scripts/audit_legacy_wrappers.py"],
|
||||
capture_output=True, text=True,
|
||||
)
|
||||
assert "Found 0 legacy wrappers" in r.stdout, (
|
||||
f"expected 0 legacy wrappers in src/, but audit found:\n{r.stdout[:500]}"
|
||||
)
|
||||
Reference in New Issue
Block a user