Files
OpenJarvis/tests/core/test_skills_learning_config.py
T
3e2f4bcdb4 feat(core): consolidate all state under a single env-aware home directory (#462) (#549)
Previously `core/config.py` defined `DEFAULT_CONFIG_DIR = Path.home() /
".openjarvis"` as a by-value module constant imported into ~45 modules, and 34
modules hardcoded `Path.home() / ".openjarvis"` directly. The installer honored
`OPENJARVIS_HOME` but the Python runtime ignored it, producing a split-brain
layout (some modules honored the override, the core config dir did not). Eval
dataset caches also scattered into `~/.cache/<benchmark>`.

This introduces a single env-aware resolver in `openjarvis/core/paths.py` and
routes every state/config/cache path through it. OpenJarvis now keeps ALL of
its state under ONE root, resolved in priority order:

  1. $OPENJARVIS_HOME
  2. $XDG_DATA_HOME/openjarvis   (single nested dir, when XDG_DATA_HOME is set)
  3. ~/.openjarvis               (default — unchanged, so existing installs are
                                  untouched and no data migration is required)

Implementation:
- New `core/paths.py`: get_config_dir / get_config_path / get_data_dir /
  get_cache_dir, with a source-tree rejection guard (fails loudly per
  REVIEW.md if the root resolves inside the repo).
- `core/config.py`: DEFAULT_CONFIG_DIR / DEFAULT_CONFIG_PATH are now resolved
  via the env-aware resolver at import (real attributes, so existing
  monkeypatch.setattr-based tests keep working). All dataclass field defaults
  that pointed at ~/.openjarvis converted to default_factory so they honor the
  override at instantiation.
- Routed all 34 hardcoders plus several string-literal escapees the original
  audit missed: prompt_loader / description_loader (were OPENJARVIS_HOME-only,
  no XDG), swebench_harness cache, tools/{memory,skill,user_profile}_manage
  defaults, server trace.db fallbacks, doctor_cmd hints.
- spec_search storage/paths now delegates to the unified resolver (gains XDG);
  its ConfigurationError is aliased to the core one.
- Eval dataset caches moved from ~/.cache/<name> to <root>/cache/<name>
  (~/.cache/huggingface left alone — it is HF's own cache).
- Docs + installer comment + `jarvis config path` to show resolved dirs.

Read-only macOS connectors and OS service files (LaunchAgents/systemd) are
intentionally left untouched.

Fixes #462

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-15 09:32:02 -07:00

44 lines
1.6 KiB
Python

"""Tests for SkillsLearningConfig and its wiring into LearningConfig."""
from __future__ import annotations
from openjarvis.core.config import LearningConfig, SkillsLearningConfig
from openjarvis.core.paths import get_config_dir
class TestSkillsLearningConfig:
def test_defaults(self):
cfg = SkillsLearningConfig()
assert cfg.auto_optimize is False
assert cfg.optimizer == "dspy"
assert cfg.min_traces_per_skill == 20
assert cfg.optimization_interval_seconds == 86400
# overlay_dir now resolves under the env-aware OpenJarvis root (#462),
# defaulting to <home>/learning/skills instead of the old literal.
assert cfg.overlay_dir == str(get_config_dir() / "learning" / "skills")
def test_can_be_constructed_with_all_fields(self):
cfg = SkillsLearningConfig(
auto_optimize=True,
optimizer="gepa",
min_traces_per_skill=10,
optimization_interval_seconds=3600,
overlay_dir="/tmp/overlays/",
)
assert cfg.auto_optimize is True
assert cfg.optimizer == "gepa"
assert cfg.min_traces_per_skill == 10
assert cfg.optimization_interval_seconds == 3600
assert cfg.overlay_dir == "/tmp/overlays/"
class TestLearningConfigSkillsField:
def test_skills_field_present(self):
cfg = LearningConfig()
assert hasattr(cfg, "skills")
assert isinstance(cfg.skills, SkillsLearningConfig)
def test_skills_field_default_disabled(self):
cfg = LearningConfig()
assert cfg.skills.auto_optimize is False