personal memory agent
0

Configure Feed

Select the types of activity you want to include in your feed.

solstone / tests / test_prompt_metadata.py
2.8 kB 90 lines
1# SPDX-License-Identifier: AGPL-3.0-only 2# Copyright (c) 2026 sol pbc 3 4"""Tests for prompt metadata parsing failures.""" 5 6import json 7 8import pytest 9 10import solstone.think.prompts as prompts 11import solstone.think.talent as talent 12from solstone.think.prompts import PromptMetadataError, _load_prompt_metadata 13 14 15def test_load_prompt_metadata_returns_expected_fields(tmp_path): 16 md_path = tmp_path / "valid.md" 17 md_path.write_text( 18 '{\n "title": "Valid Prompt",\n "schedule": "daily"\n}\n\nBody text\n', 19 encoding="utf-8", 20 ) 21 22 info = _load_prompt_metadata(md_path) 23 24 assert info["path"] == str(md_path) 25 assert info["mtime"] == int(md_path.stat().st_mtime) 26 assert info["title"] == "Valid Prompt" 27 assert info["schedule"] == "daily" 28 assert info["color"] == "#6c757d" 29 30 31def test_load_prompt_metadata_raises_prompt_metadata_error_for_bad_json(tmp_path): 32 md_path = tmp_path / "invalid.md" 33 md_path.write_text( 34 '{\n "title": "Invalid Prompt",\n "disabled": True\n}\n\nBody text\n', 35 encoding="utf-8", 36 ) 37 38 with pytest.raises(PromptMetadataError) as excinfo: 39 _load_prompt_metadata(md_path) 40 41 exc = excinfo.value 42 assert exc.path == md_path 43 assert str(md_path) in str(exc) 44 assert isinstance(exc.__cause__, json.JSONDecodeError) 45 46 47def test_load_raw_templates_raises_prompt_metadata_error_for_bad_template( 48 tmp_path, monkeypatch 49): 50 templates_dir = tmp_path / "templates" 51 templates_dir.mkdir() 52 bad_template = templates_dir / "broken.md" 53 bad_template.write_text( 54 '{\n "title": "Broken Template",\n "disabled": True\n}\n\nBody text\n', 55 encoding="utf-8", 56 ) 57 58 monkeypatch.setattr(prompts, "TEMPLATES_DIR", templates_dir) 59 monkeypatch.setattr(prompts, "_templates_cache", None) 60 61 with pytest.raises(PromptMetadataError) as excinfo: 62 prompts._load_raw_templates() 63 64 exc = excinfo.value 65 assert exc.path == bad_template 66 assert str(bad_template) in str(exc) 67 assert isinstance(exc.__cause__, json.JSONDecodeError) 68 69 70def test_get_talent_configs_propagates_prompt_metadata_error(tmp_path, monkeypatch): 71 talent_dir = tmp_path / "talent" 72 talent_dir.mkdir() 73 apps_dir = tmp_path / "apps" 74 apps_dir.mkdir() 75 broken_prompt = talent_dir / "broken.md" 76 broken_prompt.write_text( 77 '{\n "title": "Broken Prompt",\n "disabled": True\n}\n\nBody text\n', 78 encoding="utf-8", 79 ) 80 81 monkeypatch.setattr(talent, "TALENT_DIR", talent_dir) 82 monkeypatch.setattr(talent, "APPS_DIR", apps_dir) 83 84 with pytest.raises(PromptMetadataError) as excinfo: 85 talent.get_talent_configs(include_disabled=True) 86 87 exc = excinfo.value 88 assert exc.path == broken_prompt 89 assert str(broken_prompt) in str(exc) 90 assert isinstance(exc.__cause__, json.JSONDecodeError)