personal memory agent
at main 94 lines 3.6 kB view raw
1# SPDX-License-Identifier: AGPL-3.0-only 2# Copyright (c) 2026 sol pbc 3 4"""Tests for entity type validation.""" 5 6from think.entities import ENTITY_TYPES, is_valid_entity_type 7 8 9def test_entity_types_constant(): 10 """Test that ENTITY_TYPES constant has expected structure.""" 11 assert len(ENTITY_TYPES) == 4 12 assert all("name" in t for t in ENTITY_TYPES) 13 # Verify standard types in expected order 14 names = [t["name"] for t in ENTITY_TYPES] 15 assert names == ["Person", "Company", "Project", "Tool"] 16 17 18def test_valid_standard_types(): 19 """Test that standard 4 entity types are valid.""" 20 assert is_valid_entity_type("Person") is True 21 assert is_valid_entity_type("Company") is True 22 assert is_valid_entity_type("Project") is True 23 assert is_valid_entity_type("Tool") is True 24 25 26def test_valid_custom_types(): 27 """Test that custom entity types are accepted.""" 28 assert is_valid_entity_type("Location") is True 29 assert is_valid_entity_type("Event") is True 30 assert is_valid_entity_type("Organization") is True 31 assert is_valid_entity_type("Product") is True 32 assert is_valid_entity_type("Service") is True 33 34 35def test_valid_types_with_spaces(): 36 """Test that entity types with spaces are accepted.""" 37 assert is_valid_entity_type("Custom Type") is True 38 assert is_valid_entity_type("Event Location") is True 39 assert is_valid_entity_type("Tech Product") is True 40 41 42def test_valid_types_with_numbers(): 43 """Test that entity types with numbers are accepted.""" 44 assert is_valid_entity_type("Type123") is True 45 assert is_valid_entity_type("Event 2024") is True 46 assert is_valid_entity_type("Version 2") is True 47 48 49def test_invalid_too_short(): 50 """Test that types shorter than 3 characters are rejected.""" 51 assert is_valid_entity_type("") is False 52 assert is_valid_entity_type("A") is False 53 assert is_valid_entity_type("AB") is False 54 55 56def test_invalid_special_characters(): 57 """Test that types with special characters are rejected.""" 58 assert is_valid_entity_type("Person!") is False 59 assert is_valid_entity_type("Type-Name") is False 60 assert is_valid_entity_type("Type_Name") is False 61 assert is_valid_entity_type("Type@Name") is False 62 assert is_valid_entity_type("Type#Name") is False 63 assert is_valid_entity_type("Type$Name") is False 64 assert is_valid_entity_type("Type%Name") is False 65 assert is_valid_entity_type("Type&Name") is False 66 assert is_valid_entity_type("Type*Name") is False 67 assert is_valid_entity_type("Type(Name)") is False 68 assert is_valid_entity_type("Type/Name") is False 69 assert is_valid_entity_type("Type\\Name") is False 70 assert is_valid_entity_type("Type.Name") is False 71 assert is_valid_entity_type("Type,Name") is False 72 73 74def test_invalid_unicode(): 75 """Test that unicode/emoji characters are rejected.""" 76 assert is_valid_entity_type("Type🚀") is False 77 assert is_valid_entity_type("Typé") is False 78 assert is_valid_entity_type("类型") is False 79 80 81def test_none_and_whitespace(): 82 """Test that None and whitespace-only strings are rejected.""" 83 assert is_valid_entity_type(" ") is False 84 assert is_valid_entity_type("\t") is False 85 assert is_valid_entity_type("\n") is False 86 87 88def test_case_sensitivity(): 89 """Test that validation is case-insensitive (accepts both).""" 90 assert is_valid_entity_type("person") is True 91 assert is_valid_entity_type("PERSON") is True 92 assert is_valid_entity_type("PeRsOn") is True 93 assert is_valid_entity_type("custom type") is True 94 assert is_valid_entity_type("CUSTOM TYPE") is True