Timmy can now introspect which session he's running in (cli, dashboard, loop).
- Add {session_id} placeholder to both lite and full system prompts
- get_system_prompt() accepts session_id param (default: 'unknown')
- create_timmy() accepts session_id param, forwards to prompt
- CLI chat/think/status pass their session_id to create_timmy()
- session.py passes _DEFAULT_SESSION_ID to create_timmy()
- 7 new tests in test_session_identity.py
- Updated 2 existing CLI test mocks
Closes #64
55 lines
2.2 KiB
Python
55 lines
2.2 KiB
Python
"""Tests for session identity awareness in system prompts.
|
|
|
|
Issue #64: Timmy should know what session it is running in.
|
|
"""
|
|
|
|
from timmy.prompts import get_system_prompt
|
|
|
|
|
|
class TestSessionIdentity:
|
|
"""Test that session_id is properly injected into system prompts."""
|
|
|
|
def test_lite_prompt_includes_session_id(self):
|
|
"""Lite prompt should include the session_id in the output."""
|
|
prompt = get_system_prompt(tools_enabled=False, session_id="cli")
|
|
assert "cli" in prompt
|
|
assert 'session "cli"' in prompt
|
|
|
|
def test_full_prompt_includes_session_id(self):
|
|
"""Full prompt should include the session_id in the output."""
|
|
prompt = get_system_prompt(tools_enabled=True, session_id="dashboard")
|
|
assert "dashboard" in prompt
|
|
assert 'session "dashboard"' in prompt
|
|
|
|
def test_default_session_id_is_unknown(self):
|
|
"""When no session_id is provided, default should be 'unknown'."""
|
|
prompt = get_system_prompt()
|
|
assert "unknown" in prompt
|
|
assert 'session "unknown"' in prompt
|
|
|
|
def test_lite_prompt_session_format(self):
|
|
"""Lite prompt should have session info after the rules."""
|
|
prompt = get_system_prompt(tools_enabled=False, session_id="loop")
|
|
# Should contain the session line
|
|
assert '- You are running in session "loop".' in prompt
|
|
|
|
def test_full_prompt_session_format(self):
|
|
"""Full prompt should have session info in IDENTITY section."""
|
|
prompt = get_system_prompt(tools_enabled=True, session_id="custom")
|
|
# Should contain session type explanation
|
|
assert 'session "custom"' in prompt
|
|
assert "Session types:" in prompt
|
|
|
|
def test_various_session_ids(self):
|
|
"""Test that different session IDs are properly handled."""
|
|
test_cases = ["cli", "dashboard", "loop", "custom", "test-session-123"]
|
|
for sid in test_cases:
|
|
prompt = get_system_prompt(session_id=sid)
|
|
assert f'"{sid}"' in prompt, f"Session ID '{sid}' not found in prompt"
|
|
|
|
def test_session_id_with_special_chars(self):
|
|
"""Test session IDs with special characters."""
|
|
sid = "user_123-test.session"
|
|
prompt = get_system_prompt(session_id=sid)
|
|
assert sid in prompt
|