Spaces:
Running
Running
Download brain/tests/test_memory_rules.py from chintakapp/prova-core: direct link, hf CLI and curl.
- Browser
- Download file 3.66 kB
-
https://huggingface.co/spaces/chintakapp/prova-core/resolve/main/brain/tests/test_memory_rules.py
- Command line
-
hf download hf://spaces/chintakapp/prova-core/brain/tests/test_memory_rules.py
-
curl -L -o test_memory_rules.py https://huggingface.co/spaces/chintakapp/prova-core/resolve/main/brain/tests/test_memory_rules.py
3.66 kB
| """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 | |
| 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." | |
| 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 ------------------------------------------------------------ | |
| def test_filler_is_trivial(message): | |
| assert is_trivial(message) is True | |
| 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 | |