From 891142570b7220dc5c7d3463e439a36e39bdb4b3 Mon Sep 17 00:00:00 2001 From: pyr0ball Date: Thu, 9 Apr 2026 12:28:38 -0700 Subject: [PATCH] feat(#14): default bench_results_dir + testability seam - sft.py: _DEFAULT_BENCH_RESULTS_DIR set to circuitforge-orch bench results path; set_default_bench_results_dir() seam for test isolation - test fixture resets default to tmp_path to avoid real-fs interference - 136 tests passing Closes #14 --- app/sft.py | 27 ++++++++++++++++++--------- tests/test_sft.py | 7 +++++-- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/app/sft.py b/app/sft.py index ab439f1..b9b9fe0 100644 --- a/app/sft.py +++ b/app/sft.py @@ -51,17 +51,26 @@ def _config_file() -> Path: return _ROOT / "config" / "label_tool.yaml" +_DEFAULT_BENCH_RESULTS_DIR = "/Library/Development/CircuitForge/circuitforge-orch/scripts/bench_results" + + +def set_default_bench_results_dir(path: str) -> None: + """Override the default bench_results_dir — used by tests to avoid real filesystem.""" + global _DEFAULT_BENCH_RESULTS_DIR + _DEFAULT_BENCH_RESULTS_DIR = path + + def _get_bench_results_dir() -> Path: f = _config_file() - if not f.exists(): - return Path("/nonexistent-bench-results") - try: - raw = yaml.safe_load(f.read_text(encoding="utf-8")) or {} - except yaml.YAMLError as exc: - logger.warning("Failed to parse SFT config %s: %s", f, exc) - return Path("/nonexistent-bench-results") - d = raw.get("sft", {}).get("bench_results_dir", "") - return Path(d) if d else Path("/nonexistent-bench-results") + if f.exists(): + try: + raw = yaml.safe_load(f.read_text(encoding="utf-8")) or {} + d = raw.get("sft", {}).get("bench_results_dir", "") + if d: + return Path(d) + except yaml.YAMLError as exc: + logger.warning("Failed to parse SFT config %s: %s", f, exc) + return Path(_DEFAULT_BENCH_RESULTS_DIR) def _candidates_file() -> Path: diff --git a/tests/test_sft.py b/tests/test_sft.py index e3c98f9..ac6410c 100644 --- a/tests/test_sft.py +++ b/tests/test_sft.py @@ -8,13 +8,16 @@ from pathlib import Path @pytest.fixture(autouse=True) def reset_sft_globals(tmp_path): from app import sft as sft_module - _prev_data = sft_module._SFT_DATA_DIR - _prev_cfg = sft_module._SFT_CONFIG_DIR + _prev_data = sft_module._SFT_DATA_DIR + _prev_cfg = sft_module._SFT_CONFIG_DIR + _prev_default = sft_module._DEFAULT_BENCH_RESULTS_DIR sft_module.set_sft_data_dir(tmp_path) sft_module.set_sft_config_dir(tmp_path) + sft_module.set_default_bench_results_dir(str(tmp_path / "bench_results")) yield sft_module.set_sft_data_dir(_prev_data) sft_module.set_sft_config_dir(_prev_cfg) + sft_module.set_default_bench_results_dir(_prev_default) @pytest.fixture