test: add coverage for chat_topic in SessionSource and session context prompt
Tests added: - Roundtrip serialization of chat_topic via to_dict/from_dict - chat_topic defaults to None when missing from dict - Channel Topic line appears in session context prompt when set - Channel Topic line is omitted when chat_topic is None Follow-up to PR #248 (feat: Discord channel topic in session context).
This commit is contained in:
parent
6bf3aad62e
commit
e265006fd6
1 changed files with 65 additions and 0 deletions
|
|
@ -35,6 +35,24 @@ class TestSessionSourceRoundtrip:
|
||||||
assert restored.user_name == "alice"
|
assert restored.user_name == "alice"
|
||||||
assert restored.thread_id == "t1"
|
assert restored.thread_id == "t1"
|
||||||
|
|
||||||
|
def test_full_roundtrip_with_chat_topic(self):
|
||||||
|
"""chat_topic should survive to_dict/from_dict roundtrip."""
|
||||||
|
source = SessionSource(
|
||||||
|
platform=Platform.DISCORD,
|
||||||
|
chat_id="789",
|
||||||
|
chat_name="Server / #project-planning",
|
||||||
|
chat_type="group",
|
||||||
|
user_id="42",
|
||||||
|
user_name="bob",
|
||||||
|
chat_topic="Planning and coordination for Project X",
|
||||||
|
)
|
||||||
|
d = source.to_dict()
|
||||||
|
assert d["chat_topic"] == "Planning and coordination for Project X"
|
||||||
|
|
||||||
|
restored = SessionSource.from_dict(d)
|
||||||
|
assert restored.chat_topic == "Planning and coordination for Project X"
|
||||||
|
assert restored.chat_name == "Server / #project-planning"
|
||||||
|
|
||||||
def test_minimal_roundtrip(self):
|
def test_minimal_roundtrip(self):
|
||||||
source = SessionSource(platform=Platform.LOCAL, chat_id="cli")
|
source = SessionSource(platform=Platform.LOCAL, chat_id="cli")
|
||||||
d = source.to_dict()
|
d = source.to_dict()
|
||||||
|
|
@ -61,6 +79,7 @@ class TestSessionSourceRoundtrip:
|
||||||
assert restored.user_id is None
|
assert restored.user_id is None
|
||||||
assert restored.user_name is None
|
assert restored.user_name is None
|
||||||
assert restored.thread_id is None
|
assert restored.thread_id is None
|
||||||
|
assert restored.chat_topic is None
|
||||||
assert restored.chat_type == "dm"
|
assert restored.chat_type == "dm"
|
||||||
|
|
||||||
def test_invalid_platform_raises(self):
|
def test_invalid_platform_raises(self):
|
||||||
|
|
@ -178,6 +197,52 @@ class TestBuildSessionContextPrompt:
|
||||||
|
|
||||||
assert "Discord" in prompt
|
assert "Discord" in prompt
|
||||||
|
|
||||||
|
def test_discord_prompt_with_channel_topic(self):
|
||||||
|
"""Channel topic should appear in the session context prompt."""
|
||||||
|
config = GatewayConfig(
|
||||||
|
platforms={
|
||||||
|
Platform.DISCORD: PlatformConfig(
|
||||||
|
enabled=True,
|
||||||
|
token="fake-discord-token",
|
||||||
|
),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
source = SessionSource(
|
||||||
|
platform=Platform.DISCORD,
|
||||||
|
chat_id="guild-123",
|
||||||
|
chat_name="Server / #project-planning",
|
||||||
|
chat_type="group",
|
||||||
|
user_name="alice",
|
||||||
|
chat_topic="Planning and coordination for Project X",
|
||||||
|
)
|
||||||
|
ctx = build_session_context(source, config)
|
||||||
|
prompt = build_session_context_prompt(ctx)
|
||||||
|
|
||||||
|
assert "Discord" in prompt
|
||||||
|
assert "**Channel Topic:** Planning and coordination for Project X" in prompt
|
||||||
|
|
||||||
|
def test_prompt_omits_channel_topic_when_none(self):
|
||||||
|
"""Channel Topic line should NOT appear when chat_topic is None."""
|
||||||
|
config = GatewayConfig(
|
||||||
|
platforms={
|
||||||
|
Platform.DISCORD: PlatformConfig(
|
||||||
|
enabled=True,
|
||||||
|
token="fake-discord-token",
|
||||||
|
),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
source = SessionSource(
|
||||||
|
platform=Platform.DISCORD,
|
||||||
|
chat_id="guild-123",
|
||||||
|
chat_name="Server / #general",
|
||||||
|
chat_type="group",
|
||||||
|
user_name="alice",
|
||||||
|
)
|
||||||
|
ctx = build_session_context(source, config)
|
||||||
|
prompt = build_session_context_prompt(ctx)
|
||||||
|
|
||||||
|
assert "Channel Topic" not in prompt
|
||||||
|
|
||||||
def test_local_prompt_mentions_machine(self):
|
def test_local_prompt_mentions_machine(self):
|
||||||
config = GatewayConfig()
|
config = GatewayConfig()
|
||||||
source = SessionSource.local_cli()
|
source = SessionSource.local_cli()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue