File size: 1,262 Bytes
53b2ac9 | 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 | # SPDX-License-Identifier: MIT
"""The shipped .trashclaw.toml.example must only use keys a project config honours.
Project configs are untrusted, so url, auto_shell, max_rounds, max_context
(and anything else outside PROJECT_CONFIG_ALLOWED_KEYS) are ignored with a
warning. An example that sets them tells users something that does not work.
"""
import os
import shutil
import sys
sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
import pytest
import trashclaw
EXAMPLE = os.path.join(os.path.dirname(os.path.dirname(__file__)), ".trashclaw.toml.example")
@pytest.mark.parametrize("use_fallback_parser", [False, True])
def test_example_only_uses_honoured_keys(tmp_path, monkeypatch, capsys, use_fallback_parser):
if use_fallback_parser:
monkeypatch.setitem(sys.modules, "tomllib", None) # Python < 3.11 path
monkeypatch.setattr(trashclaw, "CONFIG_FILE", str(tmp_path / "no-home-config.json"))
shutil.copy(EXAMPLE, str(tmp_path / ".trashclaw.toml"))
cfg = trashclaw._load_config(str(tmp_path))
err = capsys.readouterr().err
assert "Ignoring" not in err, err
assert cfg.get("model")
assert isinstance(cfg.get("context_files"), list) and cfg["context_files"]
assert cfg.get("project_system_prompt")
|