personal memory agent
0

Configure Feed

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

solstone / tests / test_speaker_attribution_schema.py
2.5 kB 100 lines
1# SPDX-License-Identifier: AGPL-3.0-only 2# Copyright (c) 2026 sol pbc 3 4import json 5from pathlib import Path 6 7import pytest 8from jsonschema import Draft202012Validator 9 10from solstone.think.talent import get_talent 11 12SCHEMA_PATH = ( 13 Path(__file__).parent.parent 14 / "solstone" 15 / "talent" 16 / "speaker_attribution.schema.json" 17) 18 19 20def _load_schema() -> dict: 21 return json.loads(SCHEMA_PATH.read_text(encoding="utf-8")) 22 23 24def test_speaker_attribution_schema_file_is_valid_draft_2020_12(): 25 Draft202012Validator.check_schema(_load_schema()) 26 27 28def test_speaker_attribution_talent_loads_schema(): 29 assert get_talent("speaker_attribution")["json_schema"] == _load_schema() 30 31 32@pytest.mark.parametrize( 33 "payload", 34 [ 35 { 36 "attributions": [ 37 { 38 "sentence_id": 1, 39 "speaker": "Alice", 40 "reasoning": "Introduced herself.", 41 } 42 ] 43 }, 44 { 45 "attributions": [ 46 { 47 "sentence_id": 1, 48 "speaker": "Alice", 49 "reasoning": "Introduced herself.", 50 }, 51 {"sentence_id": 2, "speaker": "Bob", "reasoning": "Replied to Alice."}, 52 ] 53 }, 54 ], 55) 56def test_positive_payload_validates(payload): 57 validator = Draft202012Validator(_load_schema()) 58 59 assert validator.is_valid(payload) 60 61 62def test_negative_bare_array_rejected(): 63 validator = Draft202012Validator(_load_schema()) 64 65 assert not validator.is_valid( 66 [{"sentence_id": 1, "speaker": "Alice", "reasoning": "Introduced herself."}] 67 ) 68 69 70def test_negative_missing_required_field_rejected(): 71 validator = Draft202012Validator(_load_schema()) 72 73 assert not validator.is_valid( 74 {"attributions": [{"sentence_id": 1, "speaker": "Alice"}]} 75 ) 76 77 78def test_negative_non_integer_sentence_id_rejected(): 79 validator = Draft202012Validator(_load_schema()) 80 81 assert not validator.is_valid( 82 {"attributions": [{"sentence_id": "1", "speaker": "Alice", "reasoning": "x"}]} 83 ) 84 85 86def test_negative_additional_properties_rejected(): 87 validator = Draft202012Validator(_load_schema()) 88 89 assert not validator.is_valid( 90 { 91 "attributions": [ 92 { 93 "sentence_id": 1, 94 "speaker": "Alice", 95 "reasoning": "x", 96 "confidence": "high", 97 } 98 ] 99 } 100 )