Spaces:
Running
Running
File size: 3,663 Bytes
210ef30 | 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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | """Memory scope, triviality and visibility — blueprint 1.3, 6.9, 11 and master prompt 4.5."""
import pytest
from brain.memory.scope import forced_scope, parse_extraction
from brain.memory.trivial import is_trivial
from brain.persona.types import Mode, Scope
from brain.visibility import can_see, visible_for
# --- Extraction parsing ----------------------------------------------------
def test_a_shared_fact_is_parsed():
fact = parse_extraction("shared|His sister's name is Ria.", Mode.GF)
assert fact.scope is Scope.SHARED
assert fact.content == "His sister's name is Ria."
def test_a_private_fact_is_parsed():
fact = parse_extraction("private|He calls her shona when tired.", Mode.GF)
assert fact.scope is Scope.PRIVATE
@pytest.mark.parametrize("raw", ["NONE", "none", "NONE.", '"NONE"', "", " "])
def test_none_means_nothing_to_remember(raw):
assert parse_extraction(raw, Mode.GF) is None
def test_a_missing_scope_defaults_to_private():
# Blueprint 6.9: parse defensively, default to private when unsure.
fact = parse_extraction("He likes rain.", Mode.GF)
assert fact.scope is Scope.PRIVATE
assert fact.content == "He likes rain."
@pytest.mark.parametrize("scope", ["gf", "SHARD", "public", "Shared?", "romantic"])
def test_any_unrecognised_scope_is_private(scope):
assert parse_extraction(f"{scope}|He likes rain.", Mode.GF).scope is Scope.PRIVATE
def test_normal_mode_facts_are_always_shared_whatever_the_extractor_said():
fact = parse_extraction("private|He has a client call on Thursday.", Mode.NORMAL)
assert fact.scope is Scope.SHARED
def test_only_the_first_line_counts():
fact = parse_extraction("shared|He hates coriander.\nHope that helps!", Mode.GF)
assert fact.content == "He hates coriander."
def test_an_overlong_fact_is_rejected():
assert parse_extraction("shared|" + "word " * 100, Mode.GF) is None
def test_an_empty_fact_after_the_scope_is_rejected():
assert parse_extraction("shared|", Mode.GF) is None
def test_remember_tool_in_normal_mode_is_forced_shared():
assert forced_scope("private", Mode.NORMAL) is Scope.SHARED
def test_remember_tool_in_gf_mode_respects_the_request():
assert forced_scope("shared", Mode.GF) is Scope.SHARED
assert forced_scope("private", Mode.GF) is Scope.PRIVATE
def test_remember_tool_with_no_scope_defaults_to_shared():
# He said "remember my dentist is on Friday": an explicit request with nothing private in it.
assert forced_scope(None, Mode.GF) is Scope.SHARED
# --- Triviality ------------------------------------------------------------
@pytest.mark.parametrize("message", ["ok", "hmm", "haha", "thik ache", "OK!", "hm ok", " k "])
def test_filler_is_trivial(message):
assert is_trivial(message) is True
@pytest.mark.parametrize(
"message", ["amar sister er naam Ria", "client call ta kobe?", "aaj khub tired lagche"]
)
def test_real_messages_are_not_trivial(message):
assert is_trivial(message) is False
# --- Visibility ------------------------------------------------------------
MESSAGES = [
{"id": 1, "mode": "normal", "content": "report ready?"},
{"id": 2, "mode": "gf", "content": "miss korchi"},
{"id": 3, "mode": "normal", "content": "call at 3"},
]
def test_normal_mode_sees_normal_messages_only():
assert [m["id"] for m in visible_for(Mode.NORMAL, MESSAGES)] == [1, 3]
def test_gf_mode_sees_everything():
assert [m["id"] for m in visible_for(Mode.GF, MESSAGES)] == [1, 2, 3]
def test_can_see_accepts_the_enum_or_its_value():
assert can_see(Mode.NORMAL, Mode.GF) is False
assert can_see(Mode.NORMAL, "normal") is True
|