Mercurial
annotate mrjunejune/inference/copilot_sidecar_test.py @ 281:c57149ad216e default tip
Copilot-Session: f68442b1-fa8f-46a0-9689-81710613bbd4
| author | MrJuneJune <me@mrjunejune.com> |
|---|---|
| date | Tue, 18 Aug 2026 22:18:15 -0700 |
| parents | 49e9e591c9bb |
| children |
| rev | line source |
|---|---|
|
260
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
1 import asyncio |
|
265
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
2 import hashlib |
|
281
c57149ad216e
Copilot-Session: f68442b1-fa8f-46a0-9689-81710613bbd4
MrJuneJune <me@mrjunejune.com>
parents:
280
diff
changeset
|
3 import os |
|
c57149ad216e
Copilot-Session: f68442b1-fa8f-46a0-9689-81710613bbd4
MrJuneJune <me@mrjunejune.com>
parents:
280
diff
changeset
|
4 import tempfile |
|
260
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
5 import types |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
6 import unittest |
|
265
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
7 import uuid |
|
260
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
8 from dataclasses import replace |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
9 |
|
265
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
10 from mrjunejune.inference.copilot_sidecar import ( |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
11 CompiledProfile, |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
12 Sidecar, |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
13 SidecarConfig, |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
14 _derive_sdk_session_id, |
|
280
49e9e591c9bb
Add persistent dictation, prewarmed WebRTC speech input, Copilot SDK routing, animated conversation lifecycle controls, parking, and architecture coverage.
MrJuneJune <me@mrjunejune.com>
parents:
265
diff
changeset
|
15 _CANVAS_ORCHESTRATOR_PROMPT, |
|
265
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
16 _SDK_SESSION_NAMESPACE, |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
17 _validate_history, |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
18 _HISTORY_MAX_ENTRIES, |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
19 _HISTORY_MAX_BYTES, |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
20 ) |
|
260
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
21 |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
22 |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
23 def event(event_type, **data): |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
24 return types.SimpleNamespace( |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
25 type=types.SimpleNamespace(value=event_type), |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
26 data=types.SimpleNamespace(**data), |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
27 ) |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
28 |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
29 |
|
265
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
30 # --------------------------------------------------------------------------- |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
31 # Fake compiled-profile infrastructure |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
32 # --------------------------------------------------------------------------- |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
33 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
34 def _make_content(profile: str) -> str: |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
35 return f"You are the {profile} assistant. Common rules apply." |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
36 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
37 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
38 _FAKE_PROFILES: dict = { |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
39 profile: { |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
40 "content": _make_content(profile), |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
41 "version": 1, |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
42 "hash": hashlib.sha256(_make_content(profile).encode()).hexdigest(), |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
43 } |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
44 for profile in ("public_visitor", "invited_friend", "june_admin") |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
45 } |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
46 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
47 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
48 def _fake_compile_fn(profile: str) -> dict: |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
49 if profile not in _FAKE_PROFILES: |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
50 raise ValueError(f"Unknown profile: {profile!r}") |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
51 return _FAKE_PROFILES[profile] |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
52 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
53 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
54 def _fake_sdk_id(conversation_id: str, profile: str) -> str: |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
55 """Compute the deterministic SDK session ID for use in test assertions.""" |
|
280
49e9e591c9bb
Add persistent dictation, prewarmed WebRTC speech input, Copilot SDK routing, animated conversation lifecycle controls, parking, and architecture coverage.
MrJuneJune <me@mrjunejune.com>
parents:
265
diff
changeset
|
56 if profile == "canvas_orchestrator": |
|
49e9e591c9bb
Add persistent dictation, prewarmed WebRTC speech input, Copilot SDK routing, animated conversation lifecycle controls, parking, and architecture coverage.
MrJuneJune <me@mrjunejune.com>
parents:
265
diff
changeset
|
57 content = _CANVAS_ORCHESTRATOR_PROMPT.strip() |
|
49e9e591c9bb
Add persistent dictation, prewarmed WebRTC speech input, Copilot SDK routing, animated conversation lifecycle controls, parking, and architecture coverage.
MrJuneJune <me@mrjunejune.com>
parents:
265
diff
changeset
|
58 p = { |
|
49e9e591c9bb
Add persistent dictation, prewarmed WebRTC speech input, Copilot SDK routing, animated conversation lifecycle controls, parking, and architecture coverage.
MrJuneJune <me@mrjunejune.com>
parents:
265
diff
changeset
|
59 "content": content, |
|
49e9e591c9bb
Add persistent dictation, prewarmed WebRTC speech input, Copilot SDK routing, animated conversation lifecycle controls, parking, and architecture coverage.
MrJuneJune <me@mrjunejune.com>
parents:
265
diff
changeset
|
60 "version": 1, |
|
49e9e591c9bb
Add persistent dictation, prewarmed WebRTC speech input, Copilot SDK routing, animated conversation lifecycle controls, parking, and architecture coverage.
MrJuneJune <me@mrjunejune.com>
parents:
265
diff
changeset
|
61 "hash": hashlib.sha256(content.encode()).hexdigest(), |
|
49e9e591c9bb
Add persistent dictation, prewarmed WebRTC speech input, Copilot SDK routing, animated conversation lifecycle controls, parking, and architecture coverage.
MrJuneJune <me@mrjunejune.com>
parents:
265
diff
changeset
|
62 } |
|
49e9e591c9bb
Add persistent dictation, prewarmed WebRTC speech input, Copilot SDK routing, animated conversation lifecycle controls, parking, and architecture coverage.
MrJuneJune <me@mrjunejune.com>
parents:
265
diff
changeset
|
63 else: |
|
49e9e591c9bb
Add persistent dictation, prewarmed WebRTC speech input, Copilot SDK routing, animated conversation lifecycle controls, parking, and architecture coverage.
MrJuneJune <me@mrjunejune.com>
parents:
265
diff
changeset
|
64 p = _FAKE_PROFILES[profile] |
|
265
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
65 compiled = CompiledProfile( |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
66 profile=profile, |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
67 content=p["content"], |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
68 prompt_version=1, |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
69 knowledge_version=p["version"], |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
70 hash=p["hash"], |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
71 ) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
72 return _derive_sdk_session_id(conversation_id, compiled) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
73 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
74 |
|
260
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
75 class FakeSession: |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
76 def __init__(self, session_id, behavior="complete"): |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
77 self.session_id = session_id |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
78 self.behavior = behavior |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
79 self.handlers = [] |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
80 self.prompts = [] |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
81 self.abort_calls = 0 |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
82 self.disconnect_calls = 0 |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
83 self.disconnect_error = False |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
84 |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
85 def on(self, handler): |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
86 self.handlers.append(handler) |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
87 |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
88 def unsubscribe(): |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
89 if handler in self.handlers: |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
90 self.handlers.remove(handler) |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
91 |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
92 return unsubscribe |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
93 |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
94 def emit(self, value): |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
95 for handler in list(self.handlers): |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
96 handler(value) |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
97 |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
98 async def send(self, prompt): |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
99 self.prompts.append(prompt) |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
100 message_id = f"message-{len(self.prompts)}" |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
101 if self.behavior == "complete": |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
102 self.emit( |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
103 event( |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
104 "assistant.message_delta", |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
105 delta_content=f"{prompt}-delta", |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
106 message_id=message_id, |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
107 ) |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
108 ) |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
109 self.emit( |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
110 event( |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
111 "assistant.message", |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
112 content=f"{prompt}-answer", |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
113 message_id=message_id, |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
114 model="test-model", |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
115 ) |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
116 ) |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
117 self.emit( |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
118 event( |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
119 "assistant.usage", |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
120 model="test-model", |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
121 input_tokens=3, |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
122 output_tokens=5, |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
123 ) |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
124 ) |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
125 self.emit(event("session.idle", aborted=False)) |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
126 elif self.behavior == "error": |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
127 self.emit( |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
128 event( |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
129 "session.error", |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
130 error_type="provider", |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
131 error_code="upstream_error", |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
132 message="upstream failed", |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
133 status_code=502, |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
134 ) |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
135 ) |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
136 return message_id |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
137 |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
138 async def abort(self): |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
139 self.abort_calls += 1 |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
140 if self.behavior == "abort_error": |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
141 raise RuntimeError("abort failed") |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
142 self.emit(event("session.idle", aborted=True)) |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
143 |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
144 async def disconnect(self): |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
145 self.disconnect_calls += 1 |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
146 if self.disconnect_error: |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
147 raise RuntimeError("disconnect failed") |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
148 |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
149 |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
150 class FakeClient: |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
151 def __init__(self, behavior="complete"): |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
152 self.behavior = behavior |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
153 self.sessions = {} |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
154 self.create_calls = [] |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
155 self.resume_calls = [] |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
156 self.delete_calls = [] |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
157 self.started = False |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
158 self.stopped = False |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
159 self.resume_started = None |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
160 self.resume_release = None |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
161 |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
162 async def start(self): |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
163 self.started = True |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
164 |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
165 async def stop(self): |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
166 self.stopped = True |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
167 |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
168 async def resume_session(self, session_id, **kwargs): |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
169 self.resume_calls.append((session_id, kwargs)) |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
170 if self.resume_started is not None: |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
171 self.resume_started.set() |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
172 if self.resume_release is not None: |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
173 await self.resume_release.wait() |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
174 if session_id not in self.sessions: |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
175 raise LookupError(session_id) |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
176 return self.sessions[session_id] |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
177 |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
178 async def create_session(self, session_id, **kwargs): |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
179 self.create_calls.append((session_id, kwargs)) |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
180 session = FakeSession(session_id, self.behavior) |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
181 self.sessions[session_id] = session |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
182 return session |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
183 |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
184 async def delete_session(self, session_id): |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
185 self.delete_calls.append(session_id) |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
186 self.sessions.pop(session_id, None) |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
187 |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
188 |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
189 class SidecarTest(unittest.IsolatedAsyncioTestCase): |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
190 async def asyncSetUp(self): |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
191 self.output = [] |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
192 |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
193 async def capture(payload): |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
194 self.output.append(payload) |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
195 |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
196 self.capture = capture |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
197 self.config = SidecarConfig( |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
198 base_url="http://litellm.invalid/v1", |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
199 model="test-model", |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
200 wire_api="responses", |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
201 base_directory="/not-used-by-fake", |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
202 ) |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
203 |
|
265
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
204 async def make_sidecar(self, behavior="complete", compile_fn=_fake_compile_fn): |
|
260
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
205 client = FakeClient(behavior) |
|
265
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
206 sidecar = Sidecar(client, self.config, self.capture, compile_fn=compile_fn) |
|
260
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
207 await sidecar.start() |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
208 return sidecar, client |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
209 |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
210 async def test_health_and_invalid_protocol(self): |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
211 sidecar, _ = await self.make_sidecar() |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
212 await sidecar.announce_ready() |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
213 await sidecar.dispatch({"command": "health", "request_id": "health-1"}) |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
214 await sidecar.dispatch({"command": "unknown", "request_id": "bad-1"}) |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
215 |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
216 self.assertEqual(self.output[0]["type"], "ready") |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
217 self.assertIsNone(self.output[0]["request_id"]) |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
218 self.assertEqual(self.output[1]["request_id"], "health-1") |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
219 self.assertEqual( |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
220 [item["type"] for item in self.output[-2:]], |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
221 ["turn.error", "turn.done"], |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
222 ) |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
223 |
|
280
49e9e591c9bb
Add persistent dictation, prewarmed WebRTC speech input, Copilot SDK routing, animated conversation lifecycle controls, parking, and architecture coverage.
MrJuneJune <me@mrjunejune.com>
parents:
265
diff
changeset
|
224 async def test_warm_creates_session_without_sending_prompt(self): |
|
49e9e591c9bb
Add persistent dictation, prewarmed WebRTC speech input, Copilot SDK routing, animated conversation lifecycle controls, parking, and architecture coverage.
MrJuneJune <me@mrjunejune.com>
parents:
265
diff
changeset
|
225 sidecar, client = await self.make_sidecar() |
|
49e9e591c9bb
Add persistent dictation, prewarmed WebRTC speech input, Copilot SDK routing, animated conversation lifecycle controls, parking, and architecture coverage.
MrJuneJune <me@mrjunejune.com>
parents:
265
diff
changeset
|
226 await sidecar.dispatch( |
|
49e9e591c9bb
Add persistent dictation, prewarmed WebRTC speech input, Copilot SDK routing, animated conversation lifecycle controls, parking, and architecture coverage.
MrJuneJune <me@mrjunejune.com>
parents:
265
diff
changeset
|
227 { |
|
49e9e591c9bb
Add persistent dictation, prewarmed WebRTC speech input, Copilot SDK routing, animated conversation lifecycle controls, parking, and architecture coverage.
MrJuneJune <me@mrjunejune.com>
parents:
265
diff
changeset
|
228 "command": "conversation.warm", |
|
49e9e591c9bb
Add persistent dictation, prewarmed WebRTC speech input, Copilot SDK routing, animated conversation lifecycle controls, parking, and architecture coverage.
MrJuneJune <me@mrjunejune.com>
parents:
265
diff
changeset
|
229 "request_id": "warm-1", |
|
49e9e591c9bb
Add persistent dictation, prewarmed WebRTC speech input, Copilot SDK routing, animated conversation lifecycle controls, parking, and architecture coverage.
MrJuneJune <me@mrjunejune.com>
parents:
265
diff
changeset
|
230 "conversation_id": "canvas-worker-1", |
|
49e9e591c9bb
Add persistent dictation, prewarmed WebRTC speech input, Copilot SDK routing, animated conversation lifecycle controls, parking, and architecture coverage.
MrJuneJune <me@mrjunejune.com>
parents:
265
diff
changeset
|
231 "prompt_profile": "canvas_orchestrator", |
|
49e9e591c9bb
Add persistent dictation, prewarmed WebRTC speech input, Copilot SDK routing, animated conversation lifecycle controls, parking, and architecture coverage.
MrJuneJune <me@mrjunejune.com>
parents:
265
diff
changeset
|
232 "prompt_version": 1, |
|
49e9e591c9bb
Add persistent dictation, prewarmed WebRTC speech input, Copilot SDK routing, animated conversation lifecycle controls, parking, and architecture coverage.
MrJuneJune <me@mrjunejune.com>
parents:
265
diff
changeset
|
233 "knowledge_version": 1, |
|
49e9e591c9bb
Add persistent dictation, prewarmed WebRTC speech input, Copilot SDK routing, animated conversation lifecycle controls, parking, and architecture coverage.
MrJuneJune <me@mrjunejune.com>
parents:
265
diff
changeset
|
234 "resume_existing": False, |
|
49e9e591c9bb
Add persistent dictation, prewarmed WebRTC speech input, Copilot SDK routing, animated conversation lifecycle controls, parking, and architecture coverage.
MrJuneJune <me@mrjunejune.com>
parents:
265
diff
changeset
|
235 } |
|
49e9e591c9bb
Add persistent dictation, prewarmed WebRTC speech input, Copilot SDK routing, animated conversation lifecycle controls, parking, and architecture coverage.
MrJuneJune <me@mrjunejune.com>
parents:
265
diff
changeset
|
236 ) |
|
49e9e591c9bb
Add persistent dictation, prewarmed WebRTC speech input, Copilot SDK routing, animated conversation lifecycle controls, parking, and architecture coverage.
MrJuneJune <me@mrjunejune.com>
parents:
265
diff
changeset
|
237 |
|
49e9e591c9bb
Add persistent dictation, prewarmed WebRTC speech input, Copilot SDK routing, animated conversation lifecycle controls, parking, and architecture coverage.
MrJuneJune <me@mrjunejune.com>
parents:
265
diff
changeset
|
238 self.assertEqual(len(client.create_calls), 1) |
|
49e9e591c9bb
Add persistent dictation, prewarmed WebRTC speech input, Copilot SDK routing, animated conversation lifecycle controls, parking, and architecture coverage.
MrJuneJune <me@mrjunejune.com>
parents:
265
diff
changeset
|
239 self.assertEqual(len(client.resume_calls), 0) |
|
49e9e591c9bb
Add persistent dictation, prewarmed WebRTC speech input, Copilot SDK routing, animated conversation lifecycle controls, parking, and architecture coverage.
MrJuneJune <me@mrjunejune.com>
parents:
265
diff
changeset
|
240 session = next(iter(client.sessions.values())) |
|
49e9e591c9bb
Add persistent dictation, prewarmed WebRTC speech input, Copilot SDK routing, animated conversation lifecycle controls, parking, and architecture coverage.
MrJuneJune <me@mrjunejune.com>
parents:
265
diff
changeset
|
241 self.assertEqual(session.prompts, []) |
|
49e9e591c9bb
Add persistent dictation, prewarmed WebRTC speech input, Copilot SDK routing, animated conversation lifecycle controls, parking, and architecture coverage.
MrJuneJune <me@mrjunejune.com>
parents:
265
diff
changeset
|
242 self.assertEqual( |
|
49e9e591c9bb
Add persistent dictation, prewarmed WebRTC speech input, Copilot SDK routing, animated conversation lifecycle controls, parking, and architecture coverage.
MrJuneJune <me@mrjunejune.com>
parents:
265
diff
changeset
|
243 [item["type"] for item in self.output[-2:]], |
|
49e9e591c9bb
Add persistent dictation, prewarmed WebRTC speech input, Copilot SDK routing, animated conversation lifecycle controls, parking, and architecture coverage.
MrJuneJune <me@mrjunejune.com>
parents:
265
diff
changeset
|
244 ["session.warmed", "turn.done"], |
|
49e9e591c9bb
Add persistent dictation, prewarmed WebRTC speech input, Copilot SDK routing, animated conversation lifecycle controls, parking, and architecture coverage.
MrJuneJune <me@mrjunejune.com>
parents:
265
diff
changeset
|
245 ) |
|
49e9e591c9bb
Add persistent dictation, prewarmed WebRTC speech input, Copilot SDK routing, animated conversation lifecycle controls, parking, and architecture coverage.
MrJuneJune <me@mrjunejune.com>
parents:
265
diff
changeset
|
246 |
|
281
c57149ad216e
Copilot-Session: f68442b1-fa8f-46a0-9689-81710613bbd4
MrJuneJune <me@mrjunejune.com>
parents:
280
diff
changeset
|
247 async def test_warm_skips_resume_without_persistence_marker(self): |
|
c57149ad216e
Copilot-Session: f68442b1-fa8f-46a0-9689-81710613bbd4
MrJuneJune <me@mrjunejune.com>
parents:
280
diff
changeset
|
248 with tempfile.TemporaryDirectory() as state_directory: |
|
c57149ad216e
Copilot-Session: f68442b1-fa8f-46a0-9689-81710613bbd4
MrJuneJune <me@mrjunejune.com>
parents:
280
diff
changeset
|
249 self.config = replace( |
|
c57149ad216e
Copilot-Session: f68442b1-fa8f-46a0-9689-81710613bbd4
MrJuneJune <me@mrjunejune.com>
parents:
280
diff
changeset
|
250 self.config, |
|
c57149ad216e
Copilot-Session: f68442b1-fa8f-46a0-9689-81710613bbd4
MrJuneJune <me@mrjunejune.com>
parents:
280
diff
changeset
|
251 base_directory=state_directory, |
|
c57149ad216e
Copilot-Session: f68442b1-fa8f-46a0-9689-81710613bbd4
MrJuneJune <me@mrjunejune.com>
parents:
280
diff
changeset
|
252 ) |
|
c57149ad216e
Copilot-Session: f68442b1-fa8f-46a0-9689-81710613bbd4
MrJuneJune <me@mrjunejune.com>
parents:
280
diff
changeset
|
253 sidecar, client = await self.make_sidecar() |
|
c57149ad216e
Copilot-Session: f68442b1-fa8f-46a0-9689-81710613bbd4
MrJuneJune <me@mrjunejune.com>
parents:
280
diff
changeset
|
254 await sidecar.dispatch( |
|
c57149ad216e
Copilot-Session: f68442b1-fa8f-46a0-9689-81710613bbd4
MrJuneJune <me@mrjunejune.com>
parents:
280
diff
changeset
|
255 { |
|
c57149ad216e
Copilot-Session: f68442b1-fa8f-46a0-9689-81710613bbd4
MrJuneJune <me@mrjunejune.com>
parents:
280
diff
changeset
|
256 "command": "conversation.warm", |
|
c57149ad216e
Copilot-Session: f68442b1-fa8f-46a0-9689-81710613bbd4
MrJuneJune <me@mrjunejune.com>
parents:
280
diff
changeset
|
257 "request_id": "warm-persistent", |
|
c57149ad216e
Copilot-Session: f68442b1-fa8f-46a0-9689-81710613bbd4
MrJuneJune <me@mrjunejune.com>
parents:
280
diff
changeset
|
258 "conversation_id": "canvas-orchestrator", |
|
c57149ad216e
Copilot-Session: f68442b1-fa8f-46a0-9689-81710613bbd4
MrJuneJune <me@mrjunejune.com>
parents:
280
diff
changeset
|
259 "prompt_profile": "canvas_orchestrator", |
|
c57149ad216e
Copilot-Session: f68442b1-fa8f-46a0-9689-81710613bbd4
MrJuneJune <me@mrjunejune.com>
parents:
280
diff
changeset
|
260 "prompt_version": 1, |
|
c57149ad216e
Copilot-Session: f68442b1-fa8f-46a0-9689-81710613bbd4
MrJuneJune <me@mrjunejune.com>
parents:
280
diff
changeset
|
261 "knowledge_version": 1, |
|
c57149ad216e
Copilot-Session: f68442b1-fa8f-46a0-9689-81710613bbd4
MrJuneJune <me@mrjunejune.com>
parents:
280
diff
changeset
|
262 } |
|
c57149ad216e
Copilot-Session: f68442b1-fa8f-46a0-9689-81710613bbd4
MrJuneJune <me@mrjunejune.com>
parents:
280
diff
changeset
|
263 ) |
|
c57149ad216e
Copilot-Session: f68442b1-fa8f-46a0-9689-81710613bbd4
MrJuneJune <me@mrjunejune.com>
parents:
280
diff
changeset
|
264 |
|
c57149ad216e
Copilot-Session: f68442b1-fa8f-46a0-9689-81710613bbd4
MrJuneJune <me@mrjunejune.com>
parents:
280
diff
changeset
|
265 self.assertEqual(len(client.resume_calls), 0) |
|
c57149ad216e
Copilot-Session: f68442b1-fa8f-46a0-9689-81710613bbd4
MrJuneJune <me@mrjunejune.com>
parents:
280
diff
changeset
|
266 self.assertEqual(len(client.create_calls), 1) |
|
c57149ad216e
Copilot-Session: f68442b1-fa8f-46a0-9689-81710613bbd4
MrJuneJune <me@mrjunejune.com>
parents:
280
diff
changeset
|
267 session_id = client.create_calls[0][0] |
|
c57149ad216e
Copilot-Session: f68442b1-fa8f-46a0-9689-81710613bbd4
MrJuneJune <me@mrjunejune.com>
parents:
280
diff
changeset
|
268 self.assertTrue( |
|
c57149ad216e
Copilot-Session: f68442b1-fa8f-46a0-9689-81710613bbd4
MrJuneJune <me@mrjunejune.com>
parents:
280
diff
changeset
|
269 os.path.isfile( |
|
c57149ad216e
Copilot-Session: f68442b1-fa8f-46a0-9689-81710613bbd4
MrJuneJune <me@mrjunejune.com>
parents:
280
diff
changeset
|
270 os.path.join( |
|
c57149ad216e
Copilot-Session: f68442b1-fa8f-46a0-9689-81710613bbd4
MrJuneJune <me@mrjunejune.com>
parents:
280
diff
changeset
|
271 state_directory, |
|
c57149ad216e
Copilot-Session: f68442b1-fa8f-46a0-9689-81710613bbd4
MrJuneJune <me@mrjunejune.com>
parents:
280
diff
changeset
|
272 ".session-markers", |
|
c57149ad216e
Copilot-Session: f68442b1-fa8f-46a0-9689-81710613bbd4
MrJuneJune <me@mrjunejune.com>
parents:
280
diff
changeset
|
273 session_id, |
|
c57149ad216e
Copilot-Session: f68442b1-fa8f-46a0-9689-81710613bbd4
MrJuneJune <me@mrjunejune.com>
parents:
280
diff
changeset
|
274 ) |
|
c57149ad216e
Copilot-Session: f68442b1-fa8f-46a0-9689-81710613bbd4
MrJuneJune <me@mrjunejune.com>
parents:
280
diff
changeset
|
275 ) |
|
c57149ad216e
Copilot-Session: f68442b1-fa8f-46a0-9689-81710613bbd4
MrJuneJune <me@mrjunejune.com>
parents:
280
diff
changeset
|
276 ) |
|
c57149ad216e
Copilot-Session: f68442b1-fa8f-46a0-9689-81710613bbd4
MrJuneJune <me@mrjunejune.com>
parents:
280
diff
changeset
|
277 |
|
280
49e9e591c9bb
Add persistent dictation, prewarmed WebRTC speech input, Copilot SDK routing, animated conversation lifecycle controls, parking, and architecture coverage.
MrJuneJune <me@mrjunejune.com>
parents:
265
diff
changeset
|
278 async def test_warm_rejects_non_boolean_resume_existing(self): |
|
49e9e591c9bb
Add persistent dictation, prewarmed WebRTC speech input, Copilot SDK routing, animated conversation lifecycle controls, parking, and architecture coverage.
MrJuneJune <me@mrjunejune.com>
parents:
265
diff
changeset
|
279 sidecar, client = await self.make_sidecar() |
|
49e9e591c9bb
Add persistent dictation, prewarmed WebRTC speech input, Copilot SDK routing, animated conversation lifecycle controls, parking, and architecture coverage.
MrJuneJune <me@mrjunejune.com>
parents:
265
diff
changeset
|
280 await sidecar.dispatch( |
|
49e9e591c9bb
Add persistent dictation, prewarmed WebRTC speech input, Copilot SDK routing, animated conversation lifecycle controls, parking, and architecture coverage.
MrJuneJune <me@mrjunejune.com>
parents:
265
diff
changeset
|
281 { |
|
49e9e591c9bb
Add persistent dictation, prewarmed WebRTC speech input, Copilot SDK routing, animated conversation lifecycle controls, parking, and architecture coverage.
MrJuneJune <me@mrjunejune.com>
parents:
265
diff
changeset
|
282 "command": "conversation.warm", |
|
49e9e591c9bb
Add persistent dictation, prewarmed WebRTC speech input, Copilot SDK routing, animated conversation lifecycle controls, parking, and architecture coverage.
MrJuneJune <me@mrjunejune.com>
parents:
265
diff
changeset
|
283 "request_id": "warm-invalid", |
|
49e9e591c9bb
Add persistent dictation, prewarmed WebRTC speech input, Copilot SDK routing, animated conversation lifecycle controls, parking, and architecture coverage.
MrJuneJune <me@mrjunejune.com>
parents:
265
diff
changeset
|
284 "conversation_id": "canvas-worker-1", |
|
49e9e591c9bb
Add persistent dictation, prewarmed WebRTC speech input, Copilot SDK routing, animated conversation lifecycle controls, parking, and architecture coverage.
MrJuneJune <me@mrjunejune.com>
parents:
265
diff
changeset
|
285 "prompt_profile": "canvas_orchestrator", |
|
49e9e591c9bb
Add persistent dictation, prewarmed WebRTC speech input, Copilot SDK routing, animated conversation lifecycle controls, parking, and architecture coverage.
MrJuneJune <me@mrjunejune.com>
parents:
265
diff
changeset
|
286 "prompt_version": 1, |
|
49e9e591c9bb
Add persistent dictation, prewarmed WebRTC speech input, Copilot SDK routing, animated conversation lifecycle controls, parking, and architecture coverage.
MrJuneJune <me@mrjunejune.com>
parents:
265
diff
changeset
|
287 "knowledge_version": 1, |
|
49e9e591c9bb
Add persistent dictation, prewarmed WebRTC speech input, Copilot SDK routing, animated conversation lifecycle controls, parking, and architecture coverage.
MrJuneJune <me@mrjunejune.com>
parents:
265
diff
changeset
|
288 "resume_existing": "false", |
|
49e9e591c9bb
Add persistent dictation, prewarmed WebRTC speech input, Copilot SDK routing, animated conversation lifecycle controls, parking, and architecture coverage.
MrJuneJune <me@mrjunejune.com>
parents:
265
diff
changeset
|
289 } |
|
49e9e591c9bb
Add persistent dictation, prewarmed WebRTC speech input, Copilot SDK routing, animated conversation lifecycle controls, parking, and architecture coverage.
MrJuneJune <me@mrjunejune.com>
parents:
265
diff
changeset
|
290 ) |
|
49e9e591c9bb
Add persistent dictation, prewarmed WebRTC speech input, Copilot SDK routing, animated conversation lifecycle controls, parking, and architecture coverage.
MrJuneJune <me@mrjunejune.com>
parents:
265
diff
changeset
|
291 |
|
49e9e591c9bb
Add persistent dictation, prewarmed WebRTC speech input, Copilot SDK routing, animated conversation lifecycle controls, parking, and architecture coverage.
MrJuneJune <me@mrjunejune.com>
parents:
265
diff
changeset
|
292 self.assertEqual(len(client.create_calls), 0) |
|
49e9e591c9bb
Add persistent dictation, prewarmed WebRTC speech input, Copilot SDK routing, animated conversation lifecycle controls, parking, and architecture coverage.
MrJuneJune <me@mrjunejune.com>
parents:
265
diff
changeset
|
293 self.assertEqual(len(client.resume_calls), 0) |
|
49e9e591c9bb
Add persistent dictation, prewarmed WebRTC speech input, Copilot SDK routing, animated conversation lifecycle controls, parking, and architecture coverage.
MrJuneJune <me@mrjunejune.com>
parents:
265
diff
changeset
|
294 self.assertEqual( |
|
49e9e591c9bb
Add persistent dictation, prewarmed WebRTC speech input, Copilot SDK routing, animated conversation lifecycle controls, parking, and architecture coverage.
MrJuneJune <me@mrjunejune.com>
parents:
265
diff
changeset
|
295 [item["type"] for item in self.output[-2:]], |
|
49e9e591c9bb
Add persistent dictation, prewarmed WebRTC speech input, Copilot SDK routing, animated conversation lifecycle controls, parking, and architecture coverage.
MrJuneJune <me@mrjunejune.com>
parents:
265
diff
changeset
|
296 ["turn.error", "turn.done"], |
|
49e9e591c9bb
Add persistent dictation, prewarmed WebRTC speech input, Copilot SDK routing, animated conversation lifecycle controls, parking, and architecture coverage.
MrJuneJune <me@mrjunejune.com>
parents:
265
diff
changeset
|
297 ) |
|
49e9e591c9bb
Add persistent dictation, prewarmed WebRTC speech input, Copilot SDK routing, animated conversation lifecycle controls, parking, and architecture coverage.
MrJuneJune <me@mrjunejune.com>
parents:
265
diff
changeset
|
298 self.assertEqual( |
|
49e9e591c9bb
Add persistent dictation, prewarmed WebRTC speech input, Copilot SDK routing, animated conversation lifecycle controls, parking, and architecture coverage.
MrJuneJune <me@mrjunejune.com>
parents:
265
diff
changeset
|
299 self.output[-2]["error"]["message"], |
|
49e9e591c9bb
Add persistent dictation, prewarmed WebRTC speech input, Copilot SDK routing, animated conversation lifecycle controls, parking, and architecture coverage.
MrJuneJune <me@mrjunejune.com>
parents:
265
diff
changeset
|
300 "resume_existing must be a boolean", |
|
49e9e591c9bb
Add persistent dictation, prewarmed WebRTC speech input, Copilot SDK routing, animated conversation lifecycle controls, parking, and architecture coverage.
MrJuneJune <me@mrjunejune.com>
parents:
265
diff
changeset
|
301 ) |
|
49e9e591c9bb
Add persistent dictation, prewarmed WebRTC speech input, Copilot SDK routing, animated conversation lifecycle controls, parking, and architecture coverage.
MrJuneJune <me@mrjunejune.com>
parents:
265
diff
changeset
|
302 |
|
260
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
303 async def test_multi_turn_reuses_one_session_and_configures_sdk(self): |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
304 sidecar, client = await self.make_sidecar() |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
305 for request_id, prompt in (("r1", "first"), ("r2", "second")): |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
306 await sidecar.dispatch( |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
307 { |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
308 "command": "turn.start", |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
309 "request_id": request_id, |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
310 "conversation_id": "conversation-a", |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
311 "prompt": prompt, |
|
265
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
312 "prompt_profile": "public_visitor", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
313 "prompt_version": 1, |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
314 "knowledge_version": 1, |
|
260
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
315 } |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
316 ) |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
317 await sidecar.drain_events() |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
318 |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
319 self.assertEqual(len(client.create_calls), 1) |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
320 self.assertEqual(len(client.resume_calls), 1) |
|
265
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
321 sdk_id = _fake_sdk_id("conversation-a", "public_visitor") |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
322 session = client.sessions[sdk_id] |
|
260
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
323 self.assertEqual(session.prompts, ["first", "second"]) |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
324 options = client.create_calls[0][1] |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
325 self.assertEqual(options["provider"]["type"], "openai") |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
326 self.assertEqual( |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
327 options["provider"]["base_url"], "http://litellm.invalid/v1" |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
328 ) |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
329 self.assertEqual(options["provider"]["wire_api"], "responses") |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
330 self.assertEqual(options["model"], "test-model") |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
331 self.assertEqual(options["available_tools"], []) |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
332 self.assertTrue(options["streaming"]) |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
333 self.assertEqual( |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
334 [item["request_id"] for item in self.output if item["type"] == "turn.done"], |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
335 ["r1", "r2"], |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
336 ) |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
337 |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
338 async def test_concurrent_conversations_keep_correlation(self): |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
339 sidecar, _ = await self.make_sidecar() |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
340 await asyncio.gather( |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
341 sidecar.dispatch( |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
342 { |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
343 "command": "turn.start", |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
344 "request_id": "left-request", |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
345 "conversation_id": "left", |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
346 "prompt": "left", |
|
265
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
347 "prompt_profile": "public_visitor", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
348 "prompt_version": 1, |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
349 "knowledge_version": 1, |
|
260
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
350 } |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
351 ), |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
352 sidecar.dispatch( |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
353 { |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
354 "command": "turn.start", |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
355 "request_id": "right-request", |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
356 "conversation_id": "right", |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
357 "prompt": "right", |
|
265
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
358 "prompt_profile": "public_visitor", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
359 "prompt_version": 1, |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
360 "knowledge_version": 1, |
|
260
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
361 } |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
362 ), |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
363 ) |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
364 await sidecar.drain_events() |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
365 |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
366 correlated = { |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
367 (item["request_id"], item["conversation_id"]) |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
368 for item in self.output |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
369 if item["type"] in ("assistant.delta", "assistant.completed") |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
370 } |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
371 self.assertEqual( |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
372 correlated, |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
373 {("left-request", "left"), ("right-request", "right")}, |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
374 ) |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
375 |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
376 async def test_abort_finishes_active_turn(self): |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
377 sidecar, client = await self.make_sidecar("pending") |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
378 await sidecar.dispatch( |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
379 { |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
380 "command": "turn.start", |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
381 "request_id": "turn-request", |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
382 "conversation_id": "abort-me", |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
383 "prompt": "wait", |
|
265
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
384 "prompt_profile": "public_visitor", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
385 "prompt_version": 1, |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
386 "knowledge_version": 1, |
|
260
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
387 } |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
388 ) |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
389 await sidecar.dispatch( |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
390 { |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
391 "command": "turn.abort", |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
392 "request_id": "abort-request", |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
393 "conversation_id": "abort-me", |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
394 } |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
395 ) |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
396 await sidecar.drain_events() |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
397 |
|
265
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
398 self.assertEqual(client.sessions[_fake_sdk_id("abort-me", "public_visitor")].abort_calls, 1) |
|
260
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
399 done = [ |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
400 item |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
401 for item in self.output |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
402 if item["type"] == "turn.done" |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
403 and item["request_id"] == "turn-request" |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
404 ] |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
405 self.assertEqual(done[0]["aborted"], True) |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
406 abort_accept = [ |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
407 item |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
408 for item in self.output |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
409 if item["type"] == "turn.accepted" |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
410 and item["request_id"] == "abort-request" |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
411 ] |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
412 self.assertEqual(abort_accept[0]["target_request_id"], "turn-request") |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
413 |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
414 async def test_session_error_is_terminal(self): |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
415 sidecar, _ = await self.make_sidecar("error") |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
416 await sidecar.dispatch( |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
417 { |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
418 "command": "turn.start", |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
419 "request_id": "error-request", |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
420 "conversation_id": "error-conversation", |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
421 "prompt": "fail", |
|
265
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
422 "prompt_profile": "public_visitor", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
423 "prompt_version": 1, |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
424 "knowledge_version": 1, |
|
260
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
425 } |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
426 ) |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
427 await sidecar.drain_events() |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
428 |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
429 errors = [item for item in self.output if item["type"] == "turn.error"] |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
430 done = [item for item in self.output if item["type"] == "turn.done"] |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
431 self.assertEqual(errors[0]["error"]["code"], "upstream_error") |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
432 self.assertEqual(errors[0]["error"]["status_code"], 502) |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
433 self.assertEqual(len(done), 1) |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
434 self.assertTrue(done[0]["failed"]) |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
435 |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
436 async def test_abort_error_terminates_abort_request(self): |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
437 sidecar, _ = await self.make_sidecar("abort_error") |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
438 await sidecar.dispatch( |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
439 { |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
440 "command": "turn.start", |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
441 "request_id": "active-request", |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
442 "conversation_id": "abort-error", |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
443 "prompt": "wait", |
|
265
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
444 "prompt_profile": "public_visitor", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
445 "prompt_version": 1, |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
446 "knowledge_version": 1, |
|
260
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
447 } |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
448 ) |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
449 await sidecar.dispatch( |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
450 { |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
451 "command": "turn.abort", |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
452 "request_id": "failed-abort", |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
453 "conversation_id": "abort-error", |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
454 } |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
455 ) |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
456 |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
457 abort_events = [ |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
458 item for item in self.output if item["request_id"] == "failed-abort" |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
459 ] |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
460 self.assertEqual( |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
461 [item["type"] for item in abort_events], |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
462 ["turn.accepted", "turn.error", "turn.done"], |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
463 ) |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
464 self.assertTrue(abort_events[-1]["failed"]) |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
465 |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
466 async def test_delete_and_shutdown_release_resources(self): |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
467 sidecar, client = await self.make_sidecar("pending") |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
468 await sidecar.dispatch( |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
469 { |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
470 "command": "turn.start", |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
471 "request_id": "active", |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
472 "conversation_id": "delete-me", |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
473 "prompt": "wait", |
|
265
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
474 "prompt_profile": "public_visitor", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
475 "prompt_version": 1, |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
476 "knowledge_version": 1, |
|
260
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
477 } |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
478 ) |
|
265
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
479 _delete_sdk_id = _fake_sdk_id("delete-me", "public_visitor") |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
480 session = client.sessions[_delete_sdk_id] |
|
260
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
481 await sidecar.dispatch( |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
482 { |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
483 "command": "conversation.delete", |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
484 "request_id": "delete-request", |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
485 "conversation_id": "delete-me", |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
486 } |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
487 ) |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
488 await sidecar.dispatch( |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
489 { |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
490 "command": "shutdown", |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
491 "request_id": "shutdown-request", |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
492 "conversation_id": None, |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
493 } |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
494 ) |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
495 |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
496 self.assertEqual(session.disconnect_calls, 1) |
|
265
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
497 self.assertEqual(client.delete_calls[0], _delete_sdk_id) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
498 self.assertEqual( |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
499 set(client.delete_calls), |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
500 { |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
501 _fake_sdk_id("delete-me", "public_visitor"), |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
502 _fake_sdk_id("delete-me", "invited_friend"), |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
503 _fake_sdk_id("delete-me", "june_admin"), |
|
280
49e9e591c9bb
Add persistent dictation, prewarmed WebRTC speech input, Copilot SDK routing, animated conversation lifecycle controls, parking, and architecture coverage.
MrJuneJune <me@mrjunejune.com>
parents:
265
diff
changeset
|
504 _fake_sdk_id("delete-me", "canvas_orchestrator"), |
|
265
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
505 }, |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
506 ) |
|
260
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
507 self.assertTrue(client.stopped) |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
508 self.assertTrue(sidecar.shutting_down) |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
509 shutdown = [ |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
510 item |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
511 for item in self.output |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
512 if item["request_id"] == "shutdown-request" |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
513 ] |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
514 self.assertEqual(shutdown[0]["type"], "turn.done") |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
515 |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
516 async def test_idle_and_overflow_sessions_are_evicted(self): |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
517 self.config = replace( |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
518 self.config, |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
519 idle_timeout_seconds=3600, |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
520 max_sessions=1, |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
521 ) |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
522 sidecar, client = await self.make_sidecar() |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
523 for conversation_id in ("old", "new"): |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
524 await sidecar.dispatch( |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
525 { |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
526 "command": "turn.start", |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
527 "request_id": f"request-{conversation_id}", |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
528 "conversation_id": conversation_id, |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
529 "prompt": conversation_id, |
|
265
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
530 "prompt_profile": "public_visitor", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
531 "prompt_version": 1, |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
532 "knowledge_version": 1, |
|
260
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
533 } |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
534 ) |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
535 await sidecar.drain_events() |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
536 await asyncio.sleep(0.01) |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
537 |
|
265
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
538 old_session = client.sessions[_fake_sdk_id("old", "public_visitor")] |
|
260
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
539 old_session.disconnect_error = True |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
540 await sidecar.evict_idle_sessions() |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
541 self.assertEqual(old_session.disconnect_calls, 1) |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
542 self.assertNotIn("old", sidecar._conversations) |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
543 self.assertIn("new", sidecar._conversations) |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
544 |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
545 sidecar._conversations["new"].last_used -= 4000 |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
546 await sidecar.evict_idle_sessions() |
|
265
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
547 self.assertEqual(client.sessions[_fake_sdk_id("new", "public_visitor")].disconnect_calls, 1) |
|
260
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
548 self.assertEqual(sidecar._conversations, {}) |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
549 await sidecar.dispatch( |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
550 { |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
551 "command": "shutdown", |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
552 "request_id": "shutdown-eviction", |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
553 "conversation_id": None, |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
554 } |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
555 ) |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
556 |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
557 async def test_shutdown_waits_for_inflight_session_creation(self): |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
558 client = FakeClient("pending") |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
559 client.resume_started = asyncio.Event() |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
560 client.resume_release = asyncio.Event() |
|
265
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
561 sidecar = Sidecar(client, self.config, self.capture, compile_fn=_fake_compile_fn) |
|
260
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
562 await sidecar.start() |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
563 |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
564 start_task = asyncio.create_task( |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
565 sidecar.dispatch( |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
566 { |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
567 "command": "turn.start", |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
568 "request_id": "starting", |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
569 "conversation_id": "race", |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
570 "prompt": "wait", |
|
265
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
571 "prompt_profile": "public_visitor", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
572 "prompt_version": 1, |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
573 "knowledge_version": 1, |
|
260
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
574 } |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
575 ) |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
576 ) |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
577 await client.resume_started.wait() |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
578 shutdown_task = asyncio.create_task( |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
579 sidecar.dispatch( |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
580 { |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
581 "command": "shutdown", |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
582 "request_id": "shutdown", |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
583 "conversation_id": None, |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
584 } |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
585 ) |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
586 ) |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
587 await asyncio.sleep(0) |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
588 self.assertTrue(sidecar.shutting_down) |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
589 client.resume_release.set() |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
590 await asyncio.gather(start_task, shutdown_task) |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
591 |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
592 self.assertTrue(client.stopped) |
|
265
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
593 self.assertEqual(client.sessions[_fake_sdk_id("race", "public_visitor")].disconnect_calls, 1) |
|
260
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
594 await sidecar.dispatch( |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
595 { |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
596 "command": "turn.start", |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
597 "request_id": "too-late", |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
598 "conversation_id": "late", |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
599 "prompt": "no", |
|
265
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
600 "prompt_profile": "public_visitor", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
601 "prompt_version": 1, |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
602 "knowledge_version": 1, |
|
260
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
603 } |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
604 ) |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
605 late_error = [ |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
606 item |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
607 for item in self.output |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
608 if item["request_id"] == "too-late" and item["type"] == "turn.error" |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
609 ] |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
610 self.assertEqual(late_error[0]["error"]["code"], "shutting_down") |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
611 |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
612 async def test_command_gates_are_released(self): |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
613 sidecar, _ = await self.make_sidecar() |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
614 for index in range(20): |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
615 await sidecar.dispatch( |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
616 { |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
617 "command": "unknown", |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
618 "request_id": f"unknown-{index}", |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
619 "conversation_id": f"conversation-{index}", |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
620 } |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
621 ) |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
622 self.assertEqual(sidecar._conversation_gates, {}) |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
623 |
|
265
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
624 # ------------------------------------------------------------------ |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
625 # New: profile-aware tests |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
626 # ------------------------------------------------------------------ |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
627 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
628 async def test_three_distinct_profiles_produce_distinct_append_prompts(self): |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
629 sidecar, client = await self.make_sidecar() |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
630 for profile in ("public_visitor", "invited_friend", "june_admin"): |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
631 await sidecar.dispatch( |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
632 { |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
633 "command": "turn.start", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
634 "request_id": f"req-{profile}", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
635 "conversation_id": f"conv-{profile}", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
636 "prompt": "hello", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
637 "prompt_profile": profile, |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
638 "prompt_version": 1, |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
639 "knowledge_version": 1, |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
640 } |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
641 ) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
642 await sidecar.drain_events() |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
643 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
644 contents = [opts["system_message"]["content"] for _, opts in client.create_calls] |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
645 self.assertEqual(len(contents), 3) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
646 self.assertEqual(len(set(contents)), 3, "all three profiles must produce distinct content") |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
647 for _, opts in client.create_calls: |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
648 self.assertEqual(opts["system_message"]["mode"], "append") |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
649 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
650 async def test_session_options_memory_disabled_and_no_tools(self): |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
651 sidecar, client = await self.make_sidecar() |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
652 await sidecar.dispatch( |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
653 { |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
654 "command": "turn.start", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
655 "request_id": "r-opts", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
656 "conversation_id": "conv-opts", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
657 "prompt": "test", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
658 "prompt_profile": "public_visitor", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
659 "prompt_version": 1, |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
660 "knowledge_version": 1, |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
661 } |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
662 ) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
663 await sidecar.drain_events() |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
664 _, opts = client.create_calls[0] |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
665 self.assertEqual(opts["memory"], {"enabled": False}) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
666 self.assertEqual(opts["tools"], []) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
667 self.assertEqual(opts["available_tools"], []) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
668 self.assertEqual(opts["mcp_servers"], {}) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
669 self.assertTrue(opts["enable_session_store"]) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
670 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
671 async def test_missing_profile_rejected_before_client_calls(self): |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
672 sidecar, client = await self.make_sidecar() |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
673 await sidecar.dispatch( |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
674 { |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
675 "command": "turn.start", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
676 "request_id": "r-missing", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
677 "conversation_id": "conv-missing", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
678 "prompt": "hello", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
679 } |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
680 ) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
681 errors = [e for e in self.output if e["type"] == "turn.error"] |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
682 self.assertEqual(errors[0]["error"]["code"], "invalid_prompt_profile") |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
683 done = [e for e in self.output if e["type"] == "turn.done"] |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
684 self.assertTrue(done[0]["failed"]) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
685 self.assertEqual(len(client.create_calls), 0) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
686 self.assertEqual(len(client.resume_calls), 0) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
687 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
688 async def test_unknown_profile_rejected_before_client_calls(self): |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
689 sidecar, client = await self.make_sidecar() |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
690 await sidecar.dispatch( |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
691 { |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
692 "command": "turn.start", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
693 "request_id": "r-unknown", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
694 "conversation_id": "conv-unknown", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
695 "prompt": "hello", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
696 "prompt_profile": "hacker", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
697 "prompt_version": 1, |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
698 "knowledge_version": 1, |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
699 } |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
700 ) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
701 errors = [e for e in self.output if e["type"] == "turn.error"] |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
702 self.assertEqual(errors[0]["error"]["code"], "invalid_prompt_profile") |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
703 self.assertEqual(len(client.create_calls), 0) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
704 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
705 async def test_stale_prompt_version_rejected_before_client_calls(self): |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
706 sidecar, client = await self.make_sidecar() |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
707 await sidecar.dispatch( |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
708 { |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
709 "command": "turn.start", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
710 "request_id": "r-stale-pv", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
711 "conversation_id": "conv-stale-pv", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
712 "prompt": "hello", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
713 "prompt_profile": "public_visitor", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
714 "prompt_version": 999, |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
715 "knowledge_version": 1, |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
716 } |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
717 ) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
718 errors = [e for e in self.output if e["type"] == "turn.error"] |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
719 self.assertEqual(errors[0]["error"]["code"], "invalid_prompt_profile") |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
720 self.assertEqual(len(client.create_calls), 0) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
721 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
722 async def test_stale_knowledge_version_rejected_before_client_calls(self): |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
723 sidecar, client = await self.make_sidecar() |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
724 await sidecar.dispatch( |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
725 { |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
726 "command": "turn.start", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
727 "request_id": "r-stale-kv", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
728 "conversation_id": "conv-stale-kv", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
729 "prompt": "hello", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
730 "prompt_profile": "public_visitor", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
731 "prompt_version": 1, |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
732 "knowledge_version": 999, |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
733 } |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
734 ) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
735 errors = [e for e in self.output if e["type"] == "turn.error"] |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
736 self.assertEqual(errors[0]["error"]["code"], "invalid_prompt_profile") |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
737 self.assertEqual(len(client.create_calls), 0) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
738 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
739 async def test_bool_prompt_version_rejected_before_client_calls(self): |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
740 sidecar, client = await self.make_sidecar() |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
741 await sidecar.dispatch( |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
742 { |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
743 "command": "turn.start", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
744 "request_id": "r-bool-pv", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
745 "conversation_id": "conv-bool-pv", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
746 "prompt": "hello", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
747 "prompt_profile": "public_visitor", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
748 "prompt_version": True, |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
749 "knowledge_version": 1, |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
750 } |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
751 ) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
752 errors = [e for e in self.output if e["type"] == "turn.error"] |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
753 self.assertEqual(errors[0]["error"]["code"], "invalid_prompt_profile") |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
754 self.assertEqual(len(client.create_calls), 0) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
755 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
756 async def test_bool_knowledge_version_rejected_before_client_calls(self): |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
757 sidecar, client = await self.make_sidecar() |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
758 await sidecar.dispatch( |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
759 { |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
760 "command": "turn.start", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
761 "request_id": "r-bool-kv", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
762 "conversation_id": "conv-bool-kv", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
763 "prompt": "hello", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
764 "prompt_profile": "public_visitor", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
765 "prompt_version": 1, |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
766 "knowledge_version": True, |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
767 } |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
768 ) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
769 errors = [e for e in self.output if e["type"] == "turn.error"] |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
770 self.assertEqual(errors[0]["error"]["code"], "invalid_prompt_profile") |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
771 self.assertEqual(len(client.create_calls), 0) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
772 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
773 async def test_same_profile_reuses_existing_session(self): |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
774 sidecar, client = await self.make_sidecar() |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
775 for i in range(3): |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
776 await sidecar.dispatch( |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
777 { |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
778 "command": "turn.start", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
779 "request_id": f"r-reuse-{i}", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
780 "conversation_id": "conv-reuse", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
781 "prompt": f"message {i}", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
782 "prompt_profile": "public_visitor", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
783 "prompt_version": 1, |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
784 "knowledge_version": 1, |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
785 } |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
786 ) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
787 await sidecar.drain_events() |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
788 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
789 self.assertEqual(len(client.create_calls), 1) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
790 self.assertEqual(len(client.resume_calls), 1) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
791 session = client.sessions[_fake_sdk_id("conv-reuse", "public_visitor")] |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
792 self.assertEqual(session.prompts, ["message 0", "message 1", "message 2"]) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
793 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
794 async def test_profile_switch_disconnects_and_resumes_with_new_prompt(self): |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
795 sidecar, client = await self.make_sidecar() |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
796 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
797 await sidecar.dispatch( |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
798 { |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
799 "command": "turn.start", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
800 "request_id": "r-switch-1", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
801 "conversation_id": "conv-switch", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
802 "prompt": "first", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
803 "prompt_profile": "public_visitor", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
804 "prompt_version": 1, |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
805 "knowledge_version": 1, |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
806 } |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
807 ) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
808 await sidecar.drain_events() |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
809 visitor_sdk_id = _fake_sdk_id("conv-switch", "public_visitor") |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
810 friend_sdk_id = _fake_sdk_id("conv-switch", "invited_friend") |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
811 first_session = client.sessions[visitor_sdk_id] |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
812 self.assertEqual(len(client.create_calls), 1) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
813 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
814 await sidecar.dispatch( |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
815 { |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
816 "command": "turn.start", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
817 "request_id": "r-switch-2", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
818 "conversation_id": "conv-switch", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
819 "prompt": "second", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
820 "prompt_profile": "invited_friend", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
821 "prompt_version": 1, |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
822 "knowledge_version": 1, |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
823 } |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
824 ) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
825 await sidecar.drain_events() |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
826 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
827 # Old session is disconnected and permanently deleted before new one opens. |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
828 self.assertEqual(first_session.disconnect_calls, 1) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
829 self.assertIn(visitor_sdk_id, client.delete_calls) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
830 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
831 # The new session uses the invited_friend derived ID, not the visitor one. |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
832 resume_id, resume_opts = client.resume_calls[-1] |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
833 self.assertEqual(resume_id, friend_sdk_id) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
834 self.assertNotEqual(friend_sdk_id, visitor_sdk_id) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
835 self.assertEqual(resume_opts["system_message"]["mode"], "append") |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
836 expected_content = _FAKE_PROFILES["invited_friend"]["content"] |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
837 self.assertEqual(resume_opts["system_message"]["content"], expected_content) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
838 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
839 # The newly opened session is a distinct object. |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
840 second_session = client.sessions[friend_sdk_id] |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
841 self.assertIsNot(second_session, first_session) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
842 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
843 done = [e for e in self.output if e["type"] == "turn.done" and e["request_id"] == "r-switch-2"] |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
844 self.assertFalse(done[0].get("failed", False)) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
845 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
846 async def test_concurrent_conversations_profile_isolation(self): |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
847 sidecar, client = await self.make_sidecar() |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
848 await asyncio.gather( |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
849 sidecar.dispatch( |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
850 { |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
851 "command": "turn.start", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
852 "request_id": "req-visitor", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
853 "conversation_id": "conv-visitor", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
854 "prompt": "hello visitor", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
855 "prompt_profile": "public_visitor", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
856 "prompt_version": 1, |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
857 "knowledge_version": 1, |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
858 } |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
859 ), |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
860 sidecar.dispatch( |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
861 { |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
862 "command": "turn.start", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
863 "request_id": "req-admin", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
864 "conversation_id": "conv-admin", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
865 "prompt": "hello admin", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
866 "prompt_profile": "june_admin", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
867 "prompt_version": 1, |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
868 "knowledge_version": 1, |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
869 } |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
870 ), |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
871 ) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
872 await sidecar.drain_events() |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
873 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
874 visitor_sdk_id = _fake_sdk_id("conv-visitor", "public_visitor") |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
875 admin_sdk_id = _fake_sdk_id("conv-admin", "june_admin") |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
876 options_by_sdk_id = {sdk_id: opts for sdk_id, opts in client.create_calls} |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
877 visitor_content = options_by_sdk_id[visitor_sdk_id]["system_message"]["content"] |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
878 admin_content = options_by_sdk_id[admin_sdk_id]["system_message"]["content"] |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
879 self.assertNotEqual(visitor_content, admin_content) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
880 self.assertEqual(visitor_content, _FAKE_PROFILES["public_visitor"]["content"]) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
881 self.assertEqual(admin_content, _FAKE_PROFILES["june_admin"]["content"]) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
882 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
883 async def test_profile_switch_while_active_is_rejected(self): |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
884 sidecar, client = await self.make_sidecar("pending") |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
885 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
886 await sidecar.dispatch( |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
887 { |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
888 "command": "turn.start", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
889 "request_id": "active-req", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
890 "conversation_id": "conv-active-switch", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
891 "prompt": "wait", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
892 "prompt_profile": "public_visitor", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
893 "prompt_version": 1, |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
894 "knowledge_version": 1, |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
895 } |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
896 ) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
897 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
898 await sidecar.dispatch( |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
899 { |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
900 "command": "turn.start", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
901 "request_id": "switch-req", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
902 "conversation_id": "conv-active-switch", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
903 "prompt": "switch", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
904 "prompt_profile": "invited_friend", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
905 "prompt_version": 1, |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
906 "knowledge_version": 1, |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
907 } |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
908 ) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
909 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
910 errors = [e for e in self.output if e["type"] == "turn.error" and e["request_id"] == "switch-req"] |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
911 self.assertTrue(len(errors) > 0) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
912 done = [e for e in self.output if e["type"] == "turn.done" and e["request_id"] == "switch-req"] |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
913 self.assertTrue(done[0]["failed"]) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
914 # Active-turn switch must not trigger any cleanup at all. |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
915 sdk_id = _fake_sdk_id("conv-active-switch", "public_visitor") |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
916 self.assertEqual(client.sessions[sdk_id].disconnect_calls, 0) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
917 self.assertEqual(client.delete_calls, []) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
918 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
919 async def test_startup_compilation_failure_prevents_readiness(self): |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
920 call_count = {"n": 0} |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
921 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
922 def failing_compile_fn(profile: str) -> dict: |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
923 call_count["n"] += 1 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
924 raise ValueError(f"corrupted assets for {profile!r}") |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
925 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
926 client = FakeClient() |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
927 sidecar = Sidecar(client, self.config, self.capture, compile_fn=failing_compile_fn) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
928 with self.assertRaises(ValueError) as ctx: |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
929 await sidecar.start() |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
930 self.assertIn("corrupted", str(ctx.exception)) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
931 self.assertFalse(client.started) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
932 self.assertGreater(call_count["n"], 0) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
933 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
934 # ------------------------------------------------------------------ |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
935 # Derived session ID security tests |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
936 # ------------------------------------------------------------------ |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
937 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
938 async def test_distinct_profiles_produce_distinct_sdk_session_ids(self): |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
939 """Different profiles on the same conversation must never share an SDK ID.""" |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
940 ids = { |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
941 profile: _fake_sdk_id("conv-same", profile) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
942 for profile in ("public_visitor", "invited_friend", "june_admin") |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
943 } |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
944 self.assertEqual(len(set(ids.values())), 3, "each profile needs a unique SDK ID") |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
945 for sid in ids.values(): |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
946 uuid.UUID(sid) # every value must be a valid UUID |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
947 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
948 async def test_same_profile_produces_same_sdk_id_across_restarts(self): |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
949 """The derived ID is deterministic: a sidecar restart resumes the same session.""" |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
950 client = FakeClient() |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
951 sidecar1 = Sidecar(client, self.config, self.capture, compile_fn=_fake_compile_fn) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
952 await sidecar1.start() |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
953 await sidecar1.dispatch({ |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
954 "command": "turn.start", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
955 "request_id": "restart-1", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
956 "conversation_id": "conv-restart", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
957 "prompt": "hello", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
958 "prompt_profile": "public_visitor", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
959 "prompt_version": 1, |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
960 "knowledge_version": 1, |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
961 }) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
962 await sidecar1.drain_events() |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
963 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
964 # Simulate sidecar restart: new Sidecar instance, same FakeClient (SDK store). |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
965 sidecar2 = Sidecar(client, self.config, self.capture, compile_fn=_fake_compile_fn) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
966 await sidecar2.start() |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
967 await sidecar2.dispatch({ |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
968 "command": "turn.start", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
969 "request_id": "restart-2", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
970 "conversation_id": "conv-restart", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
971 "prompt": "still here", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
972 "prompt_profile": "public_visitor", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
973 "prompt_version": 1, |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
974 "knowledge_version": 1, |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
975 }) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
976 await sidecar2.drain_events() |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
977 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
978 # Sidecar1 tries resume (fails - no session yet) then creates. |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
979 # Sidecar2 tries resume (succeeds - session persists in SDK store). |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
980 # Therefore exactly one create, two resume attempts, both on the same derived ID. |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
981 self.assertEqual(len(client.create_calls), 1) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
982 self.assertEqual(len(client.resume_calls), 2) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
983 derived = _fake_sdk_id("conv-restart", "public_visitor") |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
984 self.assertEqual(client.create_calls[0][0], derived) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
985 self.assertTrue(all(r == derived for r, _ in client.resume_calls)) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
986 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
987 async def test_profile_switch_permanently_deletes_old_sdk_session(self): |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
988 """Switching profile must delete the old derived SDK session before creating new.""" |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
989 sidecar, client = await self.make_sidecar() |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
990 await sidecar.dispatch({ |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
991 "command": "turn.start", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
992 "request_id": "admin-turn", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
993 "conversation_id": "conv-priv", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
994 "prompt": "admin question", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
995 "prompt_profile": "june_admin", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
996 "prompt_version": 1, |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
997 "knowledge_version": 1, |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
998 }) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
999 await sidecar.drain_events() |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1000 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1001 admin_sdk_id = _fake_sdk_id("conv-priv", "june_admin") |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1002 visitor_sdk_id = _fake_sdk_id("conv-priv", "public_visitor") |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1003 self.assertNotEqual(admin_sdk_id, visitor_sdk_id) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1004 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1005 await sidecar.dispatch({ |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1006 "command": "turn.start", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1007 "request_id": "visitor-turn", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1008 "conversation_id": "conv-priv", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1009 "prompt": "public question", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1010 "prompt_profile": "public_visitor", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1011 "prompt_version": 1, |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1012 "knowledge_version": 1, |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1013 }) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1014 await sidecar.drain_events() |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1015 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1016 # Admin session must be permanently deleted before visitor session opens. |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1017 self.assertIn(admin_sdk_id, client.delete_calls) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1018 # Admin session must not be in the live sessions map. |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1019 self.assertNotIn(admin_sdk_id, client.sessions) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1020 # Visitor session is a distinct object. |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1021 self.assertIn(visitor_sdk_id, client.sessions) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1022 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1023 async def test_delete_conversation_uses_derived_sdk_id_not_conversation_id(self): |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1024 """conversation.delete must call delete_session with the derived UUID.""" |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1025 sidecar, client = await self.make_sidecar() |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1026 await sidecar.dispatch({ |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1027 "command": "turn.start", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1028 "request_id": "setup-turn", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1029 "conversation_id": "conv-del-check", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1030 "prompt": "hi", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1031 "prompt_profile": "june_admin", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1032 "prompt_version": 1, |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1033 "knowledge_version": 1, |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1034 }) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1035 await sidecar.drain_events() |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1036 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1037 admin_sdk_id = _fake_sdk_id("conv-del-check", "june_admin") |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1038 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1039 await sidecar.dispatch({ |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1040 "command": "conversation.delete", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1041 "request_id": "del-req", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1042 "conversation_id": "conv-del-check", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1043 }) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1044 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1045 self.assertEqual(client.delete_calls[0], admin_sdk_id) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1046 self.assertEqual( |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1047 set(client.delete_calls), |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1048 { |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1049 _fake_sdk_id("conv-del-check", "public_visitor"), |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1050 _fake_sdk_id("conv-del-check", "invited_friend"), |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1051 _fake_sdk_id("conv-del-check", "june_admin"), |
|
280
49e9e591c9bb
Add persistent dictation, prewarmed WebRTC speech input, Copilot SDK routing, animated conversation lifecycle controls, parking, and architecture coverage.
MrJuneJune <me@mrjunejune.com>
parents:
265
diff
changeset
|
1052 _fake_sdk_id("conv-del-check", "canvas_orchestrator"), |
|
265
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1053 }, |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1054 ) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1055 self.assertNotIn("conv-del-check", client.delete_calls) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1056 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1057 async def test_delete_nonexistent_conversation_cleans_known_profile_ids(self): |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1058 """An uncached delete purges every currently known derived session ID.""" |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1059 sidecar, client = await self.make_sidecar() |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1060 await sidecar.dispatch({ |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1061 "command": "conversation.delete", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1062 "request_id": "del-ghost", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1063 "conversation_id": "ghost-conv", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1064 }) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1065 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1066 self.assertEqual( |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1067 set(client.delete_calls), |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1068 { |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1069 _fake_sdk_id("ghost-conv", "public_visitor"), |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1070 _fake_sdk_id("ghost-conv", "invited_friend"), |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1071 _fake_sdk_id("ghost-conv", "june_admin"), |
|
280
49e9e591c9bb
Add persistent dictation, prewarmed WebRTC speech input, Copilot SDK routing, animated conversation lifecycle controls, parking, and architecture coverage.
MrJuneJune <me@mrjunejune.com>
parents:
265
diff
changeset
|
1072 _fake_sdk_id("ghost-conv", "canvas_orchestrator"), |
|
265
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1073 }, |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1074 ) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1075 self.assertNotIn("ghost-conv", client.delete_calls) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1076 done = [e for e in self.output if e["type"] == "turn.done" and e["request_id"] == "del-ghost"] |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1077 self.assertEqual(done[0]["action"], "conversation.delete") |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1078 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1079 async def test_admin_session_not_reachable_via_visitor_derived_id(self): |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1080 """A visitor SDK ID must differ from the admin one for the same conversation.""" |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1081 admin_id = _fake_sdk_id("shared-conv", "june_admin") |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1082 visitor_id = _fake_sdk_id("shared-conv", "public_visitor") |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1083 self.assertNotEqual(admin_id, visitor_id) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1084 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1085 sidecar, client = await self.make_sidecar() |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1086 # Establish an admin session. |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1087 await sidecar.dispatch({ |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1088 "command": "turn.start", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1089 "request_id": "admin-req", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1090 "conversation_id": "shared-conv", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1091 "prompt": "secret", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1092 "prompt_profile": "june_admin", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1093 "prompt_version": 1, |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1094 "knowledge_version": 1, |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1095 }) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1096 await sidecar.drain_events() |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1097 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1098 # The admin session object must NOT be accessible under the visitor-derived ID. |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1099 admin_session = client.sessions.get(admin_id) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1100 self.assertIsNotNone(admin_session) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1101 self.assertIsNone(client.sessions.get(visitor_id), |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1102 "visitor SDK ID must not map to any session object at this point") |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1103 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1104 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1105 # --------------------------------------------------------------------------- |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1106 # _validate_history unit tests |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1107 # --------------------------------------------------------------------------- |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1108 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1109 class ValidateHistoryTest(unittest.TestCase): |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1110 def test_none_returns_empty_list(self): |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1111 self.assertEqual(_validate_history(None), []) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1112 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1113 def test_empty_list_accepted(self): |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1114 self.assertEqual(_validate_history([]), []) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1115 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1116 def test_valid_two_entries(self): |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1117 hist = [ |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1118 {"role": "user", "content": "hello"}, |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1119 {"role": "assistant", "content": "hi"}, |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1120 ] |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1121 result = _validate_history(hist) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1122 self.assertEqual(result, hist) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1123 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1124 def test_not_a_list_raises(self): |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1125 for bad in (42, "string", True, False, {}, object()): |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1126 with self.assertRaises(ValueError, msg=f"should reject {bad!r}"): |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1127 _validate_history(bad) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1128 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1129 def test_too_many_entries_raises(self): |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1130 entries = [{"role": "user", "content": "x"}] * (_HISTORY_MAX_ENTRIES + 1) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1131 with self.assertRaises(ValueError): |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1132 _validate_history(entries) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1133 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1134 def test_exactly_max_entries_accepted(self): |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1135 entries = [ |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1136 {"role": "user" if i % 2 == 0 else "assistant", "content": "x"} |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1137 for i in range(_HISTORY_MAX_ENTRIES) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1138 ] |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1139 result = _validate_history(entries) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1140 self.assertEqual(len(result), _HISTORY_MAX_ENTRIES) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1141 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1142 def test_non_object_entry_raises(self): |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1143 for bad_entry in (42, "string", True, None, []): |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1144 with self.assertRaises(ValueError): |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1145 _validate_history([bad_entry]) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1146 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1147 def test_invalid_role_raises(self): |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1148 for bad_role in ("system", "SYSTEM", "User", "ASSISTANT", "", " user"): |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1149 with self.assertRaises(ValueError, msg=f"role {bad_role!r} must be rejected"): |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1150 _validate_history([{"role": bad_role, "content": "x"}]) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1151 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1152 def test_bool_role_raises(self): |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1153 with self.assertRaises(ValueError): |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1154 _validate_history([{"role": True, "content": "x"}]) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1155 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1156 def test_none_content_raises(self): |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1157 with self.assertRaises(ValueError): |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1158 _validate_history([{"role": "user", "content": None}]) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1159 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1160 def test_bool_content_raises(self): |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1161 with self.assertRaises(ValueError): |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1162 _validate_history([{"role": "user", "content": True}]) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1163 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1164 def test_int_content_raises(self): |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1165 with self.assertRaises(ValueError): |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1166 _validate_history([{"role": "user", "content": 42}]) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1167 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1168 def test_extra_key_raises(self): |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1169 with self.assertRaises(ValueError): |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1170 _validate_history([{"role": "user", "content": "hi", "injected": "bad"}]) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1171 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1172 def test_oversized_total_raises(self): |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1173 # One entry with content just over the byte limit. |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1174 big = "x" * (_HISTORY_MAX_BYTES + 1) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1175 with self.assertRaises(ValueError): |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1176 _validate_history([{"role": "user", "content": big}]) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1177 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1178 def test_total_at_limit_accepted(self): |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1179 # Two entries whose combined bytes sit at or under the limit. |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1180 chunk_size = _HISTORY_MAX_BYTES // 2 - 10 # under limit |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1181 entries = [ |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1182 {"role": "user", "content": "a" * chunk_size}, |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1183 {"role": "assistant", "content": "b" * chunk_size}, |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1184 ] |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1185 result = _validate_history(entries) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1186 self.assertEqual(len(result), 2) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1187 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1188 def test_special_characters_accepted(self): |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1189 entry = {"role": "user", "content": "hello \"world\" \\ \n"} |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1190 result = _validate_history([entry]) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1191 self.assertEqual(result[0]["content"], entry["content"]) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1192 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1193 def test_empty_content_string_accepted(self): |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1194 result = _validate_history([{"role": "user", "content": ""}]) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1195 self.assertEqual(result[0]["content"], "") |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1196 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1197 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1198 # --------------------------------------------------------------------------- |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1199 # Sidecar history integration tests |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1200 # --------------------------------------------------------------------------- |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1201 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1202 class SidecarHistoryTest(unittest.IsolatedAsyncioTestCase): |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1203 async def asyncSetUp(self): |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1204 self.output = [] |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1205 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1206 async def capture(payload): |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1207 self.output.append(payload) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1208 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1209 self.capture = capture |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1210 self.config = SidecarConfig( |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1211 base_url="http://litellm.invalid/v1", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1212 model="test-model", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1213 wire_api="responses", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1214 base_directory="/not-used-by-fake", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1215 ) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1216 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1217 async def make_sidecar(self, behavior="complete"): |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1218 client = FakeClient(behavior) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1219 sidecar = Sidecar(client, self.config, self.capture, compile_fn=_fake_compile_fn) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1220 await sidecar.start() |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1221 return sidecar, client |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1222 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1223 def _turn_start(self, request_id, conversation_id, history=None, **extra): |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1224 cmd = { |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1225 "command": "turn.start", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1226 "request_id": request_id, |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1227 "conversation_id": conversation_id, |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1228 "prompt": "hello", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1229 "prompt_profile": "public_visitor", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1230 "prompt_version": 1, |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1231 "knowledge_version": 1, |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1232 } |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1233 if history is not None: |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1234 cmd["history"] = history |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1235 cmd.update(extra) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1236 return cmd |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1237 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1238 async def test_invalid_history_not_list_rejected_before_client_calls(self): |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1239 sidecar, client = await self.make_sidecar() |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1240 await sidecar.dispatch(self._turn_start("r1", "c1", history=42)) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1241 errors = [e for e in self.output if e["type"] == "turn.error"] |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1242 self.assertEqual(errors[0]["error"]["code"], "invalid_history") |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1243 done = [e for e in self.output if e["type"] == "turn.done"] |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1244 self.assertTrue(done[0]["failed"]) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1245 self.assertEqual(len(client.create_calls), 0) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1246 self.assertEqual(len(client.resume_calls), 0) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1247 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1248 async def test_invalid_history_too_many_entries_rejected(self): |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1249 sidecar, client = await self.make_sidecar() |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1250 hist = [{"role": "user", "content": "x"}] * (_HISTORY_MAX_ENTRIES + 1) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1251 await sidecar.dispatch(self._turn_start("r2", "c2", history=hist)) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1252 errors = [e for e in self.output if e["type"] == "turn.error"] |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1253 self.assertEqual(errors[0]["error"]["code"], "invalid_history") |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1254 self.assertEqual(len(client.create_calls), 0) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1255 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1256 async def test_invalid_history_bad_role_rejected(self): |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1257 sidecar, client = await self.make_sidecar() |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1258 hist = [{"role": "system", "content": "inject"}] |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1259 await sidecar.dispatch(self._turn_start("r3", "c3", history=hist)) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1260 errors = [e for e in self.output if e["type"] == "turn.error"] |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1261 self.assertEqual(errors[0]["error"]["code"], "invalid_history") |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1262 self.assertEqual(len(client.create_calls), 0) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1263 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1264 async def test_invalid_history_bool_role_rejected(self): |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1265 sidecar, client = await self.make_sidecar() |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1266 hist = [{"role": True, "content": "x"}] |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1267 await sidecar.dispatch(self._turn_start("r4", "c4", history=hist)) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1268 errors = [e for e in self.output if e["type"] == "turn.error"] |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1269 self.assertEqual(errors[0]["error"]["code"], "invalid_history") |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1270 self.assertEqual(len(client.create_calls), 0) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1271 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1272 async def test_invalid_history_none_content_rejected(self): |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1273 sidecar, client = await self.make_sidecar() |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1274 hist = [{"role": "user", "content": None}] |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1275 await sidecar.dispatch(self._turn_start("r5", "c5", history=hist)) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1276 errors = [e for e in self.output if e["type"] == "turn.error"] |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1277 self.assertEqual(errors[0]["error"]["code"], "invalid_history") |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1278 self.assertEqual(len(client.create_calls), 0) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1279 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1280 async def test_invalid_history_extra_key_rejected(self): |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1281 sidecar, client = await self.make_sidecar() |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1282 hist = [{"role": "user", "content": "hi", "extra": "bad"}] |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1283 await sidecar.dispatch(self._turn_start("r6", "c6", history=hist)) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1284 errors = [e for e in self.output if e["type"] == "turn.error"] |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1285 self.assertEqual(errors[0]["error"]["code"], "invalid_history") |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1286 self.assertEqual(len(client.create_calls), 0) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1287 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1288 async def test_invalid_history_oversized_rejected(self): |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1289 sidecar, client = await self.make_sidecar() |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1290 big = "x" * (_HISTORY_MAX_BYTES + 1) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1291 hist = [{"role": "user", "content": big}] |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1292 await sidecar.dispatch(self._turn_start("r7", "c7", history=hist)) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1293 errors = [e for e in self.output if e["type"] == "turn.error"] |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1294 self.assertEqual(errors[0]["error"]["code"], "invalid_history") |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1295 self.assertEqual(len(client.create_calls), 0) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1296 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1297 async def test_valid_empty_history_accepted(self): |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1298 sidecar, client = await self.make_sidecar() |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1299 await sidecar.dispatch(self._turn_start("r8", "c8", history=[])) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1300 await sidecar.drain_events() |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1301 done = [e for e in self.output if e["type"] == "turn.done" and e["request_id"] == "r8"] |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1302 self.assertFalse(done[0].get("failed", False)) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1303 self.assertEqual(len(client.create_calls), 1) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1304 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1305 async def test_fresh_create_receives_history_in_system_message(self): |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1306 """When resume_session fails (no persisted session), create_session must |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1307 include the PRIOR OWNED CONVERSATION TRANSCRIPT in system_message.""" |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1308 sidecar, client = await self.make_sidecar() |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1309 hist = [ |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1310 {"role": "user", "content": "prior question"}, |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1311 {"role": "assistant", "content": "prior answer"}, |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1312 ] |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1313 await sidecar.dispatch(self._turn_start("r-create", "c-create", history=hist)) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1314 await sidecar.drain_events() |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1315 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1316 self.assertEqual(len(client.create_calls), 1) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1317 _, create_opts = client.create_calls[0] |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1318 sys_content = create_opts["system_message"]["content"] |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1319 self.assertIn("PRIOR OWNED CONVERSATION TRANSCRIPT", sys_content) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1320 self.assertIn("prior question", sys_content) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1321 self.assertIn("prior answer", sys_content) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1322 self.assertIn("untrusted", sys_content.lower()) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1323 self.assertEqual(create_opts["system_message"]["mode"], "append") |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1324 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1325 async def test_resume_does_not_inject_history(self): |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1326 """An existing persisted session must not receive history in system_message.""" |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1327 sidecar, client = await self.make_sidecar() |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1328 hist = [{"role": "user", "content": "prior"}] |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1329 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1330 # First turn: creates the session. |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1331 await sidecar.dispatch(self._turn_start("r-resume-1", "c-resume", history=hist)) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1332 await sidecar.drain_events() |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1333 self.assertEqual(len(client.create_calls), 1) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1334 first_content = client.create_calls[0][1]["system_message"]["content"] |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1335 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1336 # Second turn on same conversation: must resume (SDK session persists). |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1337 await sidecar.dispatch(self._turn_start("r-resume-2", "c-resume", history=hist)) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1338 await sidecar.drain_events() |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1339 self.assertEqual(len(client.resume_calls), 1) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1340 # resume_session does not receive options from create_session call. |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1341 resume_opts = client.resume_calls[0][1] |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1342 resume_sys = resume_opts["system_message"]["content"] |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1343 # The resume options (base options) must not contain the transcript block. |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1344 self.assertNotIn("PRIOR OWNED CONVERSATION TRANSCRIPT", resume_sys) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1345 # The create call had the transcript; verify only one create happened. |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1346 self.assertEqual(len(client.create_calls), 1) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1347 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1348 async def test_history_with_no_field_uses_base_system_message_on_create(self): |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1349 """Absent history field: create_session uses base system_message without transcript.""" |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1350 sidecar, client = await self.make_sidecar() |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1351 await sidecar.dispatch(self._turn_start("r-nofield", "c-nofield")) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1352 await sidecar.drain_events() |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1353 self.assertEqual(len(client.create_calls), 1) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1354 _, opts = client.create_calls[0] |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1355 self.assertNotIn("PRIOR OWNED CONVERSATION TRANSCRIPT", opts["system_message"]["content"]) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1356 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1357 async def test_profile_switch_create_fallback_gets_history(self): |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1358 """After a profile switch the new derived session is a fresh create; |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1359 the history must be injected into the new session's system_message only.""" |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1360 sidecar, client = await self.make_sidecar() |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1361 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1362 # First turn: public_visitor session created; no prior history yet. |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1363 await sidecar.dispatch(self._turn_start("r-sw-1", "c-switch")) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1364 await sidecar.drain_events() |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1365 visitor_sdk_id = _fake_sdk_id("c-switch", "public_visitor") |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1366 friend_sdk_id = _fake_sdk_id("c-switch", "invited_friend") |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1367 self.assertNotEqual(visitor_sdk_id, friend_sdk_id) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1368 first_create_content = client.create_calls[0][1]["system_message"]["content"] |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1369 # No transcript on initial create (no history provided). |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1370 self.assertNotIn("PRIOR OWNED CONVERSATION TRANSCRIPT", first_create_content) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1371 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1372 # Second turn: invited_friend profile — old session deleted, new fresh create. |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1373 # Now we send history representing the prior visitor exchange. |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1374 friend_hist = [ |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1375 {"role": "user", "content": "visitor msg"}, |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1376 {"role": "assistant", "content": "answer"}, |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1377 ] |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1378 await sidecar.dispatch({ |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1379 "command": "turn.start", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1380 "request_id": "r-sw-2", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1381 "conversation_id": "c-switch", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1382 "prompt": "switch question", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1383 "prompt_profile": "invited_friend", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1384 "prompt_version": 1, |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1385 "knowledge_version": 1, |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1386 "history": friend_hist, |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1387 }) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1388 await sidecar.drain_events() |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1389 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1390 # Old visitor session must be deleted. |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1391 self.assertIn(visitor_sdk_id, client.delete_calls) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1392 # New session created under invited_friend derived ID. |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1393 create_ids = [sid for sid, _ in client.create_calls] |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1394 self.assertIn(friend_sdk_id, create_ids) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1395 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1396 # Second create must include the history transcript. |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1397 second_create_opts = dict(client.create_calls)[friend_sdk_id] |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1398 second_content = second_create_opts["system_message"]["content"] |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1399 self.assertIn("PRIOR OWNED CONVERSATION TRANSCRIPT", second_content) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1400 self.assertIn("visitor msg", second_content) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1401 self.assertIn("answer", second_content) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1402 self.assertIn("untrusted", second_content.lower()) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1403 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1404 done = [e for e in self.output if e["type"] == "turn.done" and e["request_id"] == "r-sw-2"] |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1405 self.assertFalse(done[0].get("failed", False)) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1406 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1407 async def test_history_not_exposed_in_events(self): |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1408 """History must not appear in any turn.accepted, assistant.delta, or |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1409 turn.done events emitted to the client.""" |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1410 sidecar, client = await self.make_sidecar() |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1411 sensitive = "SENSITIVE_TRANSCRIPT_DATA_XYZ" |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1412 hist = [{"role": "user", "content": sensitive}] |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1413 await sidecar.dispatch(self._turn_start("r-safe", "c-safe", history=hist)) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1414 await sidecar.drain_events() |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1415 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1416 for ev in self.output: |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1417 for field in ("delta", "content", "prompt"): |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1418 val = ev.get(field, "") |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1419 if isinstance(val, str): |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1420 self.assertNotIn(sensitive, val, |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1421 f"history leaked into event[{field}]: {ev}") |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1422 |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1423 async def test_existing_conversation_history_compatibility(self): |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1424 """Conversations without history (pre-change) work normally: no |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1425 transcript block is injected when history is absent/empty.""" |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1426 sidecar, client = await self.make_sidecar() |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1427 # Simulate an old-style command with no history key. |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1428 await sidecar.dispatch({ |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1429 "command": "turn.start", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1430 "request_id": "r-compat", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1431 "conversation_id": "c-compat", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1432 "prompt": "legacy", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1433 "prompt_profile": "june_admin", |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1434 "prompt_version": 1, |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1435 "knowledge_version": 1, |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1436 }) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1437 await sidecar.drain_events() |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1438 done = [e for e in self.output if e["type"] == "turn.done" and e["request_id"] == "r-compat"] |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1439 self.assertFalse(done[0].get("failed", False)) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1440 _, opts = client.create_calls[0] |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1441 self.assertNotIn("PRIOR OWNED CONVERSATION TRANSCRIPT", opts["system_message"]["content"]) |
|
056790c4fb0d
add role-aware Epi assistant prompts
MrJuneJune <me@mrjunejune.com>
parents:
260
diff
changeset
|
1442 |
|
260
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
1443 |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
1444 if __name__ == "__main__": |
|
1f9877b637e9
Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents:
diff
changeset
|
1445 unittest.main() |