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
This commit is contained in:
pyr0ball 2026-04-09 12:28:38 -07:00
parent a271278dc9
commit 891142570b
2 changed files with 23 additions and 11 deletions

View file

@ -51,17 +51,26 @@ def _config_file() -> Path:
return _ROOT / "config" / "label_tool.yaml" 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: def _get_bench_results_dir() -> Path:
f = _config_file() f = _config_file()
if not f.exists(): if f.exists():
return Path("/nonexistent-bench-results") try:
try: raw = yaml.safe_load(f.read_text(encoding="utf-8")) or {}
raw = yaml.safe_load(f.read_text(encoding="utf-8")) or {} d = raw.get("sft", {}).get("bench_results_dir", "")
except yaml.YAMLError as exc: if d:
logger.warning("Failed to parse SFT config %s: %s", f, exc) return Path(d)
return Path("/nonexistent-bench-results") except yaml.YAMLError as exc:
d = raw.get("sft", {}).get("bench_results_dir", "") logger.warning("Failed to parse SFT config %s: %s", f, exc)
return Path(d) if d else Path("/nonexistent-bench-results") return Path(_DEFAULT_BENCH_RESULTS_DIR)
def _candidates_file() -> Path: def _candidates_file() -> Path:

View file

@ -8,13 +8,16 @@ from pathlib import Path
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def reset_sft_globals(tmp_path): def reset_sft_globals(tmp_path):
from app import sft as sft_module from app import sft as sft_module
_prev_data = sft_module._SFT_DATA_DIR _prev_data = sft_module._SFT_DATA_DIR
_prev_cfg = sft_module._SFT_CONFIG_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_data_dir(tmp_path)
sft_module.set_sft_config_dir(tmp_path) sft_module.set_sft_config_dir(tmp_path)
sft_module.set_default_bench_results_dir(str(tmp_path / "bench_results"))
yield yield
sft_module.set_sft_data_dir(_prev_data) sft_module.set_sft_data_dir(_prev_data)
sft_module.set_sft_config_dir(_prev_cfg) sft_module.set_sft_config_dir(_prev_cfg)
sft_module.set_default_bench_results_dir(_prev_default)
@pytest.fixture @pytest.fixture