File size: 2,250 Bytes
4b7d391
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
"""Tests for Config."""

import os
import tempfile
from pathlib import Path
from unittest.mock import patch

import pytest

from lmaf.core.config import Config


class TestConfig:
    def test_defaults(self):
        config = Config()
        assert config.max_iterations == 15
        assert config.critic_every_n == 3
        assert config.max_consecutive_failures == 3
        assert "eu.anthropic" in config.default_model

    def test_model_for_default(self):
        config = Config()
        assert config.model_for("surveyor") == config.default_model

    def test_model_for_override(self):
        config = Config(model_overrides={"surveyor": "custom-model"})
        assert config.model_for("surveyor") == "custom-model"
        assert config.model_for("planner") == config.default_model

    def test_from_yaml(self):
        with tempfile.NamedTemporaryFile(suffix=".yaml", mode="w", delete=False) as f:
            f.write("max_iterations: 5\ncritic_every_n: 2\n")
            path = Path(f.name)

        config = Config.from_yaml(path)
        assert config.max_iterations == 5
        assert config.critic_every_n == 2
        path.unlink()

    def test_from_yaml_ignores_unknown_fields(self):
        with tempfile.NamedTemporaryFile(suffix=".yaml", mode="w", delete=False) as f:
            f.write("max_iterations: 10\nunknown_field: true\n")
            path = Path(f.name)

        config = Config.from_yaml(path)
        assert config.max_iterations == 10
        path.unlink()

    def test_from_env(self):
        env = {
            "AWS_REGION": "us-east-1",
            "AWS_ACCESS_KEY_ID": "test-key",
            "AWS_SECRET_ACCESS_KEY": "test-secret",
            "SECONDLAYER_API_KEY": "sl-key",
        }
        with patch.dict(os.environ, env, clear=False):
            config = Config.from_env()
            assert config.aws_region == "us-east-1"
            assert config.aws_access_key_id == "test-key"
            assert config.secondlayer_api_key == "sl-key"

    def test_from_env_defaults(self):
        with patch.dict(os.environ, {}, clear=True):
            config = Config.from_env()
            assert config.aws_region == ""
            assert config.secondlayer_api_url == "https://legal.org.ua/api"