A tiny, local-first CLI that finds the files your AI coding agent actually needs — and packs them into a focused context.
| 1 | """Config loading tests.""" |
| 2 | |
| 3 | from __future__ import annotations |
| 4 | |
| 5 | from pathlib import Path |
| 6 | |
| 7 | import pytest |
| 8 | |
| 9 | from agent_context.config import ConfigError, load_config |
| 10 | |
| 11 | |
| 12 | def test_defaults_when_missing(tmp_path: Path): |
| 13 | cfg = load_config(tmp_path) |
| 14 | assert cfg.max_tokens == 12_000 |
| 15 | assert cfg.redact_secrets is True |
| 16 | assert cfg.include == [] |
| 17 | |
| 18 | |
| 19 | def test_valid_config(tmp_path: Path): |
| 20 | (tmp_path / ".agent-context.toml").write_text( |
| 21 | """ |
| 22 | [context] |
| 23 | max_tokens = 8000 |
| 24 | |
| 25 | [security] |
| 26 | redact_secrets = false |
| 27 | |
| 28 | [files] |
| 29 | include = ["src/**", "tests/**"] |
| 30 | exclude = ["generated/**"] |
| 31 | """, |
| 32 | encoding="utf-8", |
| 33 | ) |
| 34 | cfg = load_config(tmp_path) |
| 35 | assert cfg.max_tokens == 8000 |
| 36 | assert cfg.redact_secrets is False |
| 37 | assert cfg.include == ["src/**", "tests/**"] |
| 38 | assert cfg.exclude == ["generated/**"] |
| 39 | |
| 40 | |
| 41 | def test_invalid_toml(tmp_path: Path): |
| 42 | (tmp_path / ".agent-context.toml").write_text("[context\n", encoding="utf-8") |
| 43 | with pytest.raises(ConfigError): |
| 44 | load_config(tmp_path) |
| 45 | |
| 46 | |
| 47 | def test_invalid_max_tokens(tmp_path: Path): |
| 48 | (tmp_path / ".agent-context.toml").write_text( |
| 49 | "[context]\nmax_tokens = -1\n", encoding="utf-8" |
| 50 | ) |
| 51 | with pytest.raises(ConfigError): |
| 52 | load_config(tmp_path) |