-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathtest_session_continuity.py
More file actions
125 lines (89 loc) ยท 3.91 KB
/
Copy pathtest_session_continuity.py
File metadata and controls
125 lines (89 loc) ยท 3.91 KB
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/usr/bin/env python3
"""
Test script for CLI session continuity implementation.
"""
import sys
import os
import tempfile
from pathlib import Path
# Project paths should be handled by proper package installation
def test_project_identification():
"""Test project identification functionality."""
print("=== Testing Project Identification ===")
from praisonai.cli.utils.project import get_project_id, get_project_name, get_git_root
# Test in current directory (should be PraisonAI repo)
project_id = get_project_id()
project_name = get_project_name()
git_root = get_git_root()
print(f"โ
Project ID: {project_id}")
print(f"โ
Project Name: {project_name}")
print(f"โ
Git Root: {git_root}")
# Test in a non-git directory
with tempfile.TemporaryDirectory() as temp_dir:
temp_project_id = get_project_id(temp_dir)
temp_project_name = get_project_name(temp_dir)
print(f"โ
Temp Project ID: {temp_project_id}")
print(f"โ
Temp Project Name: {temp_project_name}")
print("โ
Project identification tests passed\n")
def test_project_session_store():
"""Test project-scoped session store."""
print("=== Testing Project Session Store ===")
from praisonai.cli.state.project_sessions import ProjectSessionStore, get_project_session_store
# Test project session store creation
store = get_project_session_store()
print("โ
Session store created")
print(f" Project ID: {store.project_id}")
print(f" Project Name: {store.project_name}")
print(f" Session Dir: {store.session_dir}")
# Test adding messages
test_session_id = "test-session-123"
success = store.add_user_message(test_session_id, "Hello, this is a test message")
print(f"โ
Added user message: {success}")
success = store.add_assistant_message(test_session_id, "Hi! I'm responding to your test message.")
print(f"โ
Added assistant message: {success}")
# Test retrieving chat history
history = store.get_chat_history(test_session_id)
print(f"โ
Retrieved chat history ({len(history)} messages):")
for msg in history:
print(f" {msg['role']}: {msg['content']}")
# Test listing sessions
sessions = store.list_sessions(limit=5)
print(f"โ
Listed sessions ({len(sessions)} found)")
for session in sessions:
print(f" ID: {session.get('session_id')}, Messages: {session.get('message_count')}")
# Test getting last session
last_session_id = store.get_last_session_id()
print(f"โ
Last session ID: {last_session_id}")
# Cleanup
store.delete_session(test_session_id)
print("โ
Cleaned up test session")
print("โ
Project session store tests passed\n")
def test_session_discovery():
"""Test session discovery functionality."""
print("=== Testing Session Discovery ===")
from praisonai.cli.state.project_sessions import find_last_session, get_project_session_store
# Create a test session
store = get_project_session_store()
test_session_id = "discovery-test-456"
store.add_user_message(test_session_id, "Test message for discovery")
# Test finding last session
last_session = find_last_session()
print(f"โ
Found last session: {last_session}")
# Cleanup
store.delete_session(test_session_id)
print("โ
Session discovery tests passed\n")
def main():
"""Run all tests."""
print("๐งช Testing CLI Session Continuity Implementation\n")
try:
test_project_identification()
test_project_session_store()
test_session_discovery()
print("๐ All tests passed! Session continuity implementation is working.")
except Exception as e:
print(f"โ Test failed: {e}")
import traceback
traceback.print_exc()
sys.exit(1)
if __name__ == "__main__":
main()