Track Langfuse sessions and users (#174)

This commit is contained in:
Juan José Mata
2025-10-01 19:46:25 +02:00
committed by GitHub
parent ed99a4dcab
commit cbc653a63a
4 changed files with 63 additions and 8 deletions

View File

@@ -12,6 +12,8 @@ class AssistantTest < ActiveSupport::TestCase
)
@assistant = Assistant.for_chat(@chat)
@provider = mock
@expected_session_id = @chat.id.to_s
@expected_user_identifier = ::Digest::SHA256.hexdigest(@chat.user_id.to_s)
end
test "errors get added to chat" do
@@ -46,6 +48,8 @@ class AssistantTest < ActiveSupport::TestCase
response = provider_success_response(response_chunk.data)
@provider.expects(:chat_response).with do |message, **options|
assert_equal @expected_session_id, options[:session_id]
assert_equal @expected_user_identifier, options[:user_identifier]
text_chunks.each do |text_chunk|
options[:streamer].call(text_chunk)
end
@@ -98,6 +102,8 @@ class AssistantTest < ActiveSupport::TestCase
sequence = sequence("provider_chat_response")
@provider.expects(:chat_response).with do |message, **options|
assert_equal @expected_session_id, options[:session_id]
assert_equal @expected_user_identifier, options[:user_identifier]
call2_text_chunks.each do |text_chunk|
options[:streamer].call(text_chunk)
end
@@ -107,6 +113,8 @@ class AssistantTest < ActiveSupport::TestCase
end.returns(call2_response).once.in_sequence(sequence)
@provider.expects(:chat_response).with do |message, **options|
assert_equal @expected_session_id, options[:session_id]
assert_equal @expected_user_identifier, options[:user_identifier]
options[:streamer].call(call1_response_chunk)
true
end.returns(call1_response).once.in_sequence(sequence)