Files
shell-history-semantic-search/tests/test_search.py
7000pctAUTO 12af581e14
Some checks failed
CI / test (push) Has been cancelled
fix: resolve CI test failures by removing unused imports and updating workflow paths
- Removed unused imports from test files (os, pytest, pathlib.Path, MagicMock, patch, numpy, sqlite3, IndexingService)
- Updated CI workflow to only check shell-history-semantic-search project files instead of all files in shared src/ and tests/ directories
- All 43 tests pass locally
2026-03-22 18:24:46 +00:00

68 lines
2.1 KiB
Python

import pytest
from datetime import datetime
from shell_history_search.search import SemanticSearch, SearchResult
from shell_history_search.database import Database
from shell_history_search.models import HistoryEntry
class TestSemanticSearch:
@pytest.fixture
def search(self, tmp_path):
db_path = tmp_path / "test.db"
db = Database(str(db_path))
search = SemanticSearch(db)
entry = HistoryEntry(
id=1,
timestamp=1234567890.0,
command="ls -la",
exit_code=0,
shell="bash",
working_dir="/home"
)
db.add_entry(entry)
yield search
db.close()
def test_semantic_search_basic(self, search):
results = search.search("list files", limit=5)
assert isinstance(results, list)
def test_semantic_search_with_filter(self, search):
results = search.search("list", shell="bash", limit=5)
assert isinstance(results, list)
def test_search_returns_search_results(self, search):
results = search.search("ls", limit=5)
for result in results:
assert isinstance(result, SearchResult)
def test_search_empty_query(self, search):
results = search.search("", limit=5)
assert isinstance(results, list)
def test_search_with_time_filter(self, search):
results = search.search("ls", limit=5)
assert isinstance(results, list)
class TestSearchResult:
def test_search_result_creation(self):
result = SearchResult(
command="ls -la",
timestamp=1234567890.0,
score=0.95,
shell="bash"
)
assert result.command == "ls -la"
assert result.score == 0.95
def test_search_result_sorting(self):
results = [
SearchResult("cmd1", 123.0, 0.5, "bash"),
SearchResult("cmd2", 124.0, 0.9, "bash"),
SearchResult("cmd3", 125.0, 0.7, "bash"),
]
sorted_results = sorted(results)
assert sorted_results[0].score >= sorted_results[1].score >= sorted_results[2].score