From 0787ea07c825e6aeffd463337e88e5964f86503a Mon Sep 17 00:00:00 2001 From: kshitijk4poor <82637225+kshitijk4poor@users.noreply.github.com> Date: Thu, 18 Jun 2026 13:00:01 +0530 Subject: [PATCH] test(langfuse): pin exact surviving key in turn-isolation test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The prior assertion `all("turn1" in k or "turn2" in k for k in keys)` was weak on two counts: it passes vacuously when keys is empty (a regression that lost all state would slip through), and after turn 2 finalizes only turn 1 lingers, so it only ever inspected turn 1 anyway. Replace it with an exact check that one key survives, it is turn 1, and turn 2 never merged into it — the real isolation invariant the test name claims. --- tests/plugins/test_langfuse_plugin.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/plugins/test_langfuse_plugin.py b/tests/plugins/test_langfuse_plugin.py index 446503b30d2..dd58149eba2 100644 --- a/tests/plugins/test_langfuse_plugin.py +++ b/tests/plugins/test_langfuse_plugin.py @@ -354,9 +354,14 @@ class TestTurnTraceIsolation: # turn reused turn 1's lingering state and only one trace was opened. assert len(started) == 2 - # The two turns are tracked under distinct, turn-scoped keys. + # Turn 2 finalized and was popped by _finish_trace; only turn 1's + # (non-finalizing) state lingers. Assert the surviving key is turn 1's + # and that turn 2 never merged into it — `all(...)` over an empty set + # would pass vacuously, so pin the exact surviving key instead. keys = list(mod._TRACE_STATE.keys()) - assert all("turn1" in k or "turn2" in k for k in keys) + assert len(keys) == 1 + assert "turn1" in keys[0] + assert "turn2" not in keys[0] def test_pre_and_post_hooks_share_one_key_within_a_turn(self, monkeypatch): """turn_id is preferred over api_request_id so the turn-scoped