From a799a9f62e3763c8b5eecc937441a5412fcca207 Mon Sep 17 00:00:00 2001 From: 7000pctAUTO Date: Fri, 30 Jan 2026 11:56:17 +0000 Subject: [PATCH] Initial commit: Add shell-memory-cli project A CLI tool that learns from terminal command patterns to automate repetitive workflows. Features: - Command recording with tags and descriptions - Pattern detection for command sequences - Session recording and replay - Natural language script generation --- tests/test_patterns.py | 63 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 tests/test_patterns.py diff --git a/tests/test_patterns.py b/tests/test_patterns.py new file mode 100644 index 0000000..f3f93d8 --- /dev/null +++ b/tests/test_patterns.py @@ -0,0 +1,63 @@ +"""Tests for pattern detection.""" + +import pytest +import tempfile +import os +import sys +sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) + +from shell_memory.database import Database +from shell_memory.patterns import PatternDetector +from shell_memory.commands import CommandLibrary + + +@pytest.fixture +def db_with_commands(): + with tempfile.NamedTemporaryFile(suffix=".db", delete=False) as f: + db_path = f.name + db = Database(db_path) + lib = CommandLibrary(db) + for i in range(10): + lib.add(f"command_{i}") + yield db + os.unlink(db_path) + + +class TestPatternDetector: + def test_analyze_recent_commands_empty(self, db_with_commands): + detector = PatternDetector(db_with_commands) + patterns = detector.analyze_recent_commands(limit=10) + assert isinstance(patterns, list) + + def test_analyze_recent_commands_with_data(self, db_with_commands): + detector = PatternDetector(db_with_commands) + patterns = detector.analyze_recent_commands(limit=50) + assert isinstance(patterns, list) + + def test_get_detected_patterns(self, db_with_commands): + detector = PatternDetector(db_with_commands) + patterns = detector.get_detected_patterns() + assert isinstance(patterns, list) + + def test_suggest_shortcuts(self, db_with_commands): + detector = PatternDetector(db_with_commands) + shortcuts = detector.suggest_shortcuts() + assert isinstance(shortcuts, list) + + def test_get_workflow_stats(self, db_with_commands): + detector = PatternDetector(db_with_commands) + stats = detector.get_workflow_stats(days=7) + assert "total_commands" in stats + assert "patterns_found" in stats + + +class TestPatternNgramDetection: + def test_ngram_patterns_creation(self, db_with_commands): + detector = PatternDetector(db_with_commands) + detector.min_frequency = 2 + detector.window_size = 3 + commands = db_with_commands.get_all_commands() + command_ids = [cmd.id for cmd in commands if cmd.id is not None] + if len(command_ids) >= 3: + result = detector._find_ngram_patterns(command_ids) + assert isinstance(result, list) \ No newline at end of file