Files
OpenJarvis/tests/learning/intelligence/test_sft_trainer.py
T
05f2c02131 feat: Algolia DocSearch + learning subsystem reorganization (#43)
* chore: create learning subdirectory structure (routing, agents, intelligence)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* feat: extract classify_query to routing/_utils.py

Move the classify_query() function and its regex patterns into a shared
utility module so multiple routing policies can import it without
depending on the full trace_policy module.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* refactor: move routing files to learning/routing/ subdirectory

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* feat: create LearnedRouterPolicy merging trace-driven + SFT routing

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* feat: add conditional Algolia DocSearch integration

Add Algolia DocSearch as an optional search upgrade — native lunr.js
search remains the default until credentials are configured. Includes
CDN assets, Jinja2 conditional config injection, init script with
graceful fallback, light/dark theme CSS, improved search tokenization
for snake_case/dotted identifiers, and search boosts for key pages.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* refactor: move agent_evolver and skill_discovery to learning/agents/

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* refactor: move learning/orchestrator to learning/intelligence/orchestrator

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* refactor: delete removed learning policies, rewrite __init__.py, clean up api_routes

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* feat: add SFT/GRPO/DSPy/GEPA config dataclasses, update LearningConfig

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* feat: add general-purpose SFT trainer (intelligence/sft_trainer.py)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: update stale imports in multi_model_router example

Update imports to use new learning/routing/ paths after the
subdirectory reorganization. Replace BanditRouterPolicy with
LearnedRouterPolicy.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* feat: add general-purpose GRPO trainer (intelligence/grpo_trainer.py)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* feat: add DSPy agent optimizer (agents/dspy_optimizer.py)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* feat: add GEPA agent optimizer (agents/gepa_optimizer.py)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* feat: add learning-dspy and learning-gepa optional dependency extras

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: update integration test to check for learned policy instead of grpo

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: clean up stale APIs and unused params in examples

- deep_research: remove system_prompt and max_turns params not accepted
  by Jarvis.ask(), inline system prompt into the query instead
- doc_qa: remove unused --top-k CLI arg that was never passed to the API
- multi_model_router: fix select_model() call to match single-arg signature

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: import SFT/GRPO trainers in intelligence/__init__.py for registry

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* chore: remove .md file changes from PR

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* chore: restore search boost frontmatter for key docs pages

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-12 21:34:31 -07:00

67 lines
2.3 KiB
Python

"""Tests for the general-purpose SFT trainer."""
from __future__ import annotations
from unittest.mock import MagicMock, patch
class TestSFTTrainerConfig:
def test_default_config(self) -> None:
from openjarvis.core.config import SFTConfig
cfg = SFTConfig()
assert cfg.model_name == "Qwen/Qwen3-1.7B"
assert cfg.use_lora is True
assert cfg.lora_rank == 16
assert cfg.min_pairs == 10
def test_trainer_init(self) -> None:
from openjarvis.core.config import SFTConfig
from openjarvis.learning.intelligence.sft_trainer import SFTTrainer
cfg = SFTConfig()
trainer = SFTTrainer(cfg)
assert trainer.config is cfg
def test_target_modules_parsing(self) -> None:
from openjarvis.core.config import SFTConfig
from openjarvis.learning.intelligence.sft_trainer import SFTTrainer
cfg = SFTConfig(target_modules="q_proj,v_proj,k_proj")
trainer = SFTTrainer(cfg)
assert trainer.target_module_list == ["q_proj", "v_proj", "k_proj"]
class TestSFTTrainerTrainOnPairs:
def test_empty_pairs_skipped(self) -> None:
from openjarvis.core.config import SFTConfig
from openjarvis.learning.intelligence.sft_trainer import SFTTrainer
trainer = SFTTrainer(SFTConfig())
result = trainer.train_on_pairs([])
assert result["status"] == "skipped"
def test_too_few_pairs_skipped(self) -> None:
from openjarvis.core.config import SFTConfig
from openjarvis.learning.intelligence.sft_trainer import SFTTrainer
trainer = SFTTrainer(SFTConfig(min_pairs=5))
pairs = [{"input": "hi", "output": "hello"}]
result = trainer.train_on_pairs(pairs)
assert result["status"] == "skipped"
assert "min_pairs" in result.get("reason", "")
class TestSFTTrainerTraceMining:
def test_train_delegates_to_miner(self) -> None:
from openjarvis.core.config import SFTConfig
from openjarvis.learning.intelligence.sft_trainer import SFTTrainer
trainer = SFTTrainer(SFTConfig(min_pairs=1))
mock_store = MagicMock()
with patch.object(trainer, "_mine_pairs", return_value=[]) as mock_mine:
result = trainer.train(mock_store)
mock_mine.assert_called_once_with(mock_store)
assert result["status"] == "skipped"