Skip to content

Personal AI, On Personal Devices

Python
2.3 KB
Raw Blame
"""Tests for skills.sources config section."""

from __future__ import annotations

from pathlib import Path

from openjarvis.core.config import SkillsConfig, SkillSourceConfig, load_config


class TestSkillSourceConfig:
    def test_default_filter_empty(self):
        cfg = SkillSourceConfig(source="hermes")
        assert cfg.source == "hermes"
        assert cfg.filter == {}
        assert cfg.auto_update is False
        assert cfg.url == ""

    def test_with_filter(self):
        cfg = SkillSourceConfig(
            source="hermes",
            filter={"category": ["research", "coding"]},
        )
        assert cfg.filter["category"] == ["research", "coding"]


class TestSkillsConfigWithSources:
    def test_default_no_sources(self):
        cfg = SkillsConfig()
        assert cfg.enabled is True
        assert cfg.auto_sync is False
        assert cfg.sources == []

    def test_auto_sync_can_be_enabled(self):
        cfg = SkillsConfig(auto_sync=True)
        assert cfg.auto_sync is True

    def test_can_add_sources(self):
        cfg = SkillsConfig(
            sources=[
                SkillSourceConfig(source="hermes"),
                SkillSourceConfig(source="openclaw"),
            ]
        )
        assert len(cfg.sources) == 2
        assert cfg.sources[0].source == "hermes"

    def test_loads_source_tables_as_config_objects(
        self, tmp_path: Path, monkeypatch
    ) -> None:
        monkeypatch.setenv("OPENJARVIS_HOME", str(tmp_path / "home"))
        toml_file = tmp_path / "config.toml"
        toml_file.write_text(
            "[[skills.sources]]\n"
            'source = "hermes"\n'
            'filter = { category = ["productivity"] }\n\n'
            "[[skills.sources]]\n"
            'source = "github"\n'
            'url = "https://github.com/example/skill-library"\n'
            "auto_update = true\n"
        )

        load_config.cache_clear()
        try:
            cfg = load_config(toml_file)
        finally:
            load_config.cache_clear()

        assert cfg.skills.sources == [
            SkillSourceConfig(
                source="hermes",
                filter={"category": ["productivity"]},
            ),
            SkillSourceConfig(
                source="github",
                url="https://github.com/example/skill-library",
                auto_update=True,
            ),
        ]