From a916bf9d660cd704ea9f0d58ca2af4ec7b98be6b Mon Sep 17 00:00:00 2001 From: Gracy769 <169199616+Gracy769@users.noreply.github.com> Date: Tue, 1 Sep 2026 13:54:53 +0530 Subject: [PATCH] perf(test): cache bash probe resolution per session with functools.lru_cache --- tests/test_pre_push_hook_contract.py | 3 +++ tests/test_roadmap_helpers.py | 10 +++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/tests/test_pre_push_hook_contract.py b/tests/test_pre_push_hook_contract.py index 0cc1f287..a9ef026a 100644 --- a/tests/test_pre_push_hook_contract.py +++ b/tests/test_pre_push_hook_contract.py @@ -1,3 +1,4 @@ +import functools import os import shutil import subprocess @@ -5,6 +6,7 @@ import unittest from pathlib import Path +@functools.lru_cache(maxsize=1) def get_bash_executable() -> str | None: if os.name == 'nt': for candidate in ( @@ -21,6 +23,7 @@ def get_bash_executable() -> str | None: return None +@functools.lru_cache(maxsize=1) def require_bash() -> bool: bash = get_bash_executable() if not bash: diff --git a/tests/test_roadmap_helpers.py b/tests/test_roadmap_helpers.py index 3b376357..f7307c71 100644 --- a/tests/test_roadmap_helpers.py +++ b/tests/test_roadmap_helpers.py @@ -1,7 +1,10 @@ from __future__ import annotations +import functools +import os import shutil import subprocess +import sys import tempfile import unittest from pathlib import Path @@ -12,12 +15,8 @@ NEXT_ID = REPO_ROOT / 'scripts' / 'roadmap-next-id.sh' DOGFOOD_PROBE = REPO_ROOT / 'scripts' / 'dogfood-probe.py' - - -import sys - +@functools.lru_cache(maxsize=1) def get_bash_executable() -> str | None: - import os if os.name == 'nt': for candidate in ( r'C:\Program Files\Git\bin\bash.exe', @@ -33,6 +32,7 @@ def get_bash_executable() -> str | None: return None +@functools.lru_cache(maxsize=1) def require_bash() -> bool: bash = get_bash_executable() if not bash: