| 1 | from __future__ import annotations |
| 2 | |
| 3 | import sys |
| 4 | from pathlib import Path |
| 5 | |
| 6 | PROJECT_ROOT = Path(__file__).resolve().parents[1] |
| 7 | if str(PROJECT_ROOT) not in sys.path: |
| 8 | sys.path.insert(0, str(PROJECT_ROOT)) |
| 9 | |
| 10 | from plugins._memory.helpers.memory_quality import ( |
| 11 | filter_auto_memory_fragments, |
| 12 | is_auto_fragment_worth_saving, |
| 13 | ) |
| 14 | |
| 15 | |
| 16 | def test_auto_fragment_quality_keeps_durable_preferences_and_project_facts(): |
| 17 | assert is_auto_fragment_worth_saving( |
| 18 | "User currently prefers concise technical answers with verification." |
| 19 | ) |
| 20 | assert is_auto_fragment_worth_saving( |
| 21 | "Project currently uses a configured live runtime for smoke checks." |
| 22 | ) |
| 23 | assert is_auto_fragment_worth_saving( |
| 24 | "Runtime-impacting plugin changes must be synced into the configured live environment before testing." |
| 25 | ) |
| 26 | |
| 27 | |
| 28 | def test_auto_fragment_quality_rejects_action_history_and_transient_artifacts(): |
| 29 | rejected = [ |
| 30 | "Agent created a temporary CLI demo file and ran a shell test.", |
| 31 | "The user asked to build a tiny CLI todo app in Python.", |
| 32 | "Temporary marker ABC123 was used in a memory test.", |
| 33 | "The markdown-to-HTML script generated sample.html with 181 bytes.", |
| 34 | "Fixed AsyncRaceError in primary_modules.py by adding a thread lock on line 123.", |
| 35 | "The live UI was reachable at a machine-local endpoint during this session.", |
| 36 | "Project repository path is a personal absolute path on this machine.", |
| 37 | ] |
| 38 | |
| 39 | for memory in rejected: |
| 40 | assert not is_auto_fragment_worth_saving(memory) |
| 41 | |
| 42 | |
| 43 | def test_auto_fragment_filter_normalizes_and_preserves_kept_order(): |
| 44 | memories = [ |
| 45 | "User currently prefers Linux paths in examples.", |
| 46 | "Agent created a demo file and reported success.", |
| 47 | "Project repository uses a configured source workspace.", |
| 48 | ] |
| 49 | |
| 50 | assert filter_auto_memory_fragments(memories) == [ |
| 51 | "User currently prefers Linux paths in examples.", |
| 52 | "Project repository uses a configured source workspace.", |
| 53 | ] |