Skip to content

Commit bf4fcf9

Browse files
fix: update tests for v1.5.0 UNIQUE constraint compatibility
- test_session_tracking.py: use chain.seal_and_store() instead of manual seal() + store() to get proper sequence assignment - test_cli.py: update version assertion from 1.4.0 to 1.5.0
1 parent b0a585a commit bf4fcf9

File tree

2 files changed

+26
-43
lines changed

2 files changed

+26
-43
lines changed

reference/python/tests/test_cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ def test_version_flag(self, capsys, monkeypatch):
632632
main(["--version"])
633633
out = capsys.readouterr().out
634634
assert "capsule" in out
635-
assert "1.4.0" in out
635+
assert "1.5.0" in out
636636

637637
def test_verify_via_main(self, seal, temp_dir, monkeypatch):
638638
monkeypatch.setenv("NO_COLOR", "1")

reference/python/tests/test_session_tracking.py

Lines changed: 25 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -87,19 +87,17 @@ class TestListBySessionBasicFunctionality:
8787
"""
8888

8989
@pytest.mark.asyncio
90-
async def test_list_by_session_returns_matching_capsules(self, temp_storage, temp_seal):
90+
async def test_list_by_session_returns_matching_capsules(self, temp_storage, temp_seal, temp_chain):
9191
"""
9292
list_by_session returns all capsules with the given session_id.
9393
9494
SIGNAL: If this fails, session tracking is fundamentally broken.
9595
"""
9696
session_id = str(uuid.uuid4())
9797

98-
# Create 3 capsules in the same session
9998
for turn in range(1, 4):
10099
capsule = create_chat_capsule(session_id, f"Question {turn}", turn)
101-
temp_seal.seal(capsule)
102-
await temp_storage.store(capsule)
100+
await temp_chain.seal_and_store(capsule, seal=temp_seal)
103101

104102
# Query by session
105103
results = await temp_storage.list_by_session(session_id)
@@ -111,7 +109,7 @@ async def test_list_by_session_returns_matching_capsules(self, temp_storage, tem
111109
)
112110

113111
@pytest.mark.asyncio
114-
async def test_list_by_session_returns_chronological_order(self, temp_storage, temp_seal):
112+
async def test_list_by_session_returns_chronological_order(self, temp_storage, temp_seal, temp_chain):
115113
"""
116114
list_by_session returns capsules in chronological order (oldest first).
117115
@@ -123,12 +121,10 @@ async def test_list_by_session_returns_chronological_order(self, temp_storage, t
123121
questions = ["First question", "Second question", "Third question"]
124122
for turn, question in enumerate(questions, 1):
125123
capsule = create_chat_capsule(session_id, question, turn)
126-
temp_seal.seal(capsule)
127-
await temp_storage.store(capsule)
124+
await temp_chain.seal_and_store(capsule, seal=temp_seal)
128125

129126
results = await temp_storage.list_by_session(session_id)
130127

131-
# Verify order by checking questions
132128
actual_questions = [cap.trigger.request for cap in results]
133129
assert actual_questions == questions, (
134130
f"Expected chronological order: {questions}, "
@@ -169,7 +165,7 @@ class TestSessionIsolation:
169165
"""
170166

171167
@pytest.mark.asyncio
172-
async def test_sessions_are_completely_isolated(self, temp_storage, temp_seal):
168+
async def test_sessions_are_completely_isolated(self, temp_storage, temp_seal, temp_chain):
173169
"""
174170
Capsules from different sessions never mix.
175171
@@ -178,17 +174,13 @@ async def test_sessions_are_completely_isolated(self, temp_storage, temp_seal):
178174
session_a = str(uuid.uuid4())
179175
session_b = str(uuid.uuid4())
180176

181-
# Create capsules in session A
182177
for turn in range(1, 4):
183178
capsule = create_chat_capsule(session_a, f"Session A Turn {turn}", turn)
184-
temp_seal.seal(capsule)
185-
await temp_storage.store(capsule)
179+
await temp_chain.seal_and_store(capsule, seal=temp_seal)
186180

187-
# Create capsules in session B
188-
for turn in range(1, 6): # Different count to make detection easier
181+
for turn in range(1, 6):
189182
capsule = create_chat_capsule(session_b, f"Session B Turn {turn}", turn)
190-
temp_seal.seal(capsule)
191-
await temp_storage.store(capsule)
183+
await temp_chain.seal_and_store(capsule, seal=temp_seal)
192184

193185
# Query each session
194186
results_a = await temp_storage.list_by_session(session_a)
@@ -218,7 +210,7 @@ async def test_sessions_are_completely_isolated(self, temp_storage, temp_seal):
218210
)
219211

220212
@pytest.mark.asyncio
221-
async def test_many_concurrent_sessions_stay_isolated(self, temp_storage, temp_seal):
213+
async def test_many_concurrent_sessions_stay_isolated(self, temp_storage, temp_seal, temp_chain):
222214
"""
223215
Stress test: many sessions created concurrently remain isolated.
224216
@@ -237,8 +229,7 @@ async def test_many_concurrent_sessions_stay_isolated(self, temp_storage, temp_s
237229
f"Turn {turn} in session {session_id[:8]}",
238230
turn,
239231
)
240-
temp_seal.seal(capsule)
241-
await temp_storage.store(capsule)
232+
await temp_chain.seal_and_store(capsule, seal=temp_seal)
242233

243234
# Verify each session has exactly its capsules
244235
for session_id in sessions:
@@ -271,7 +262,7 @@ class TestSessionEdgeCases:
271262
"""
272263

273264
@pytest.mark.asyncio
274-
async def test_single_capsule_session(self, temp_storage, temp_seal):
265+
async def test_single_capsule_session(self, temp_storage, temp_seal, temp_chain):
275266
"""
276267
Session with only one capsule is retrievable.
277268
@@ -280,8 +271,7 @@ async def test_single_capsule_session(self, temp_storage, temp_seal):
280271
session_id = str(uuid.uuid4())
281272

282273
capsule = create_chat_capsule(session_id, "Only question", 1)
283-
temp_seal.seal(capsule)
284-
await temp_storage.store(capsule)
274+
await temp_chain.seal_and_store(capsule, seal=temp_seal)
285275

286276
results = await temp_storage.list_by_session(session_id)
287277

@@ -304,7 +294,7 @@ async def test_empty_session_id_handled_gracefully(self, temp_storage):
304294
)
305295

306296
@pytest.mark.asyncio
307-
async def test_capsules_without_session_id_excluded(self, temp_storage, temp_seal):
297+
async def test_capsules_without_session_id_excluded(self, temp_storage, temp_seal, temp_chain):
308298
"""
309299
Capsules with None session_id are not returned by session queries.
310300
@@ -314,8 +304,7 @@ async def test_capsules_without_session_id_excluded(self, temp_storage, temp_sea
314304

315305
# Create capsule WITH session_id
316306
capsule_with_session = create_chat_capsule(session_id, "Has session", 1)
317-
temp_seal.seal(capsule_with_session)
318-
await temp_storage.store(capsule_with_session)
307+
await temp_chain.seal_and_store(capsule_with_session, seal=temp_seal)
319308

320309
# Create capsule WITHOUT session_id (e.g., one-shot ask)
321310
capsule_no_session = Capsule(
@@ -331,8 +320,7 @@ async def test_capsules_without_session_id_excluded(self, temp_storage, temp_sea
331320
),
332321
outcome=OutcomeSection(status="success", result="done"),
333322
)
334-
temp_seal.seal(capsule_no_session)
335-
await temp_storage.store(capsule_no_session)
323+
await temp_chain.seal_and_store(capsule_no_session, seal=temp_seal)
336324

337325
results = await temp_storage.list_by_session(session_id)
338326

@@ -344,7 +332,7 @@ async def test_capsules_without_session_id_excluded(self, temp_storage, temp_sea
344332
assert results[0].context.session_id == session_id
345333

346334
@pytest.mark.asyncio
347-
async def test_session_id_is_case_sensitive(self, temp_storage, temp_seal):
335+
async def test_session_id_is_case_sensitive(self, temp_storage, temp_seal, temp_chain):
348336
"""
349337
Session IDs are case-sensitive (UUIDs should match exactly).
350338
@@ -355,8 +343,7 @@ async def test_session_id_is_case_sensitive(self, temp_storage, temp_seal):
355343

356344
# Create capsule with lowercase session
357345
capsule = create_chat_capsule(session_lower, "Lowercase session", 1)
358-
temp_seal.seal(capsule)
359-
await temp_storage.store(capsule)
346+
await temp_chain.seal_and_store(capsule, seal=temp_seal)
360347

361348
# Query with uppercase should return nothing
362349
results = await temp_storage.list_by_session(session_upper)
@@ -380,7 +367,7 @@ class TestSessionStress:
380367
"""
381368

382369
@pytest.mark.asyncio
383-
async def test_long_conversation_retrieval(self, temp_storage, temp_seal):
370+
async def test_long_conversation_retrieval(self, temp_storage, temp_seal, temp_chain):
384371
"""
385372
Long conversation (100 turns) retrieves correctly in order.
386373
@@ -392,8 +379,7 @@ async def test_long_conversation_retrieval(self, temp_storage, temp_seal):
392379
# Create a long conversation
393380
for turn in range(1, num_turns + 1):
394381
capsule = create_chat_capsule(session_id, f"Turn {turn}", turn)
395-
temp_seal.seal(capsule)
396-
await temp_storage.store(capsule)
382+
await temp_chain.seal_and_store(capsule, seal=temp_seal)
397383

398384
results = await temp_storage.list_by_session(session_id)
399385

@@ -410,7 +396,7 @@ async def test_long_conversation_retrieval(self, temp_storage, temp_seal):
410396
)
411397

412398
@pytest.mark.asyncio
413-
async def test_uuid_session_ids_dont_collide(self, temp_storage, temp_seal):
399+
async def test_uuid_session_ids_dont_collide(self, temp_storage, temp_seal, temp_chain):
414400
"""
415401
Property: UUIDs should never collide in practice.
416402
@@ -426,8 +412,7 @@ async def test_uuid_session_ids_dont_collide(self, temp_storage, temp_seal):
426412
# Create one capsule per session
427413
for session_id in sessions:
428414
capsule = create_chat_capsule(session_id, "Single turn", 1)
429-
temp_seal.seal(capsule)
430-
await temp_storage.store(capsule)
415+
await temp_chain.seal_and_store(capsule, seal=temp_seal)
431416

432417
# Verify each session has exactly one capsule
433418
for session_id in sessions:
@@ -451,7 +436,7 @@ class TestConversationFlow:
451436
"""
452437

453438
@pytest.mark.asyncio
454-
async def test_conversation_capsules_contain_full_context(self, temp_storage, temp_seal):
439+
async def test_conversation_capsules_contain_full_context(self, temp_storage, temp_seal, temp_chain):
455440
"""
456441
Each capsule in a conversation contains full audit context.
457442
@@ -495,8 +480,7 @@ async def test_conversation_capsules_contain_full_context(self, temp_storage, te
495480
result=response,
496481
),
497482
)
498-
temp_seal.seal(capsule)
499-
await temp_storage.store(capsule)
483+
await temp_chain.seal_and_store(capsule, seal=temp_seal)
500484

501485
# Retrieve and verify full context
502486
results = await temp_storage.list_by_session(session_id)
@@ -535,7 +519,7 @@ async def test_conversation_capsules_contain_full_context(self, temp_storage, te
535519
)
536520

537521
@pytest.mark.asyncio
538-
async def test_new_session_starts_fresh(self, temp_storage, temp_seal):
522+
async def test_new_session_starts_fresh(self, temp_storage, temp_seal, temp_chain):
539523
"""
540524
Starting a new session (/new command) gives fresh empty history.
541525
@@ -547,8 +531,7 @@ async def test_new_session_starts_fresh(self, temp_storage, temp_seal):
547531
# Create conversation in old session
548532
for turn in range(1, 6):
549533
capsule = create_chat_capsule(old_session, f"Old turn {turn}", turn)
550-
temp_seal.seal(capsule)
551-
await temp_storage.store(capsule)
534+
await temp_chain.seal_and_store(capsule, seal=temp_seal)
552535

553536
# New session should be empty
554537
new_results = await temp_storage.list_by_session(new_session)

0 commit comments

Comments
 (0)