Skip to content

Commit

Permalink
WIP: Add system tests for Claude
Browse files Browse the repository at this point in the history
  • Loading branch information
chaecramb committed Jan 31, 2025
1 parent e7a2a7e commit e824b5c
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,7 @@
let(:question) { build :question }
let(:context) { build(:answer_pipeline_context, question:) }
let(:response) do
[
{
output: {
message: {
role: "assistant",
content: [
{
tool_use: {
input: { "answer" => "VAT (Value Added Tax) is a tax applied to most goods and services in the UK." },
tool_use_id: "tool_id",
name: "tool_name",
},
},
],
},
},
stop_reason: "end_turn",
usage: {
input_tokens: 10,
output_tokens: 20,
total_tokens: 30,
},
metrics: {
latency_ms: 999,
},
},
]
stub_claude_structured_answer_reponse("VAT (Value Added Tax) is a tax applied to most goods and services in the UK.")
end

it "uses Bedrock converse endpoint to assign the correct values to the context's answer" do
Expand Down
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
config.include MailerExamples
config.include StubOpenAIChat
config.include StubBedrockRequest
config.include StubClaudeConverse
config.include PasswordlessRequestHelpers, type: :request
config.include StubOpenAIEmbedding
config.include SidekiqHelpers
Expand Down
31 changes: 31 additions & 0 deletions spec/support/stub_claude_converse.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module StubClaudeConverse
def stub_claude_structured_answer_reponse(answer)
[
{
output: {
message: {
role: "assistant",
content: [
{
tool_use: {
input: { "answer" => answer },
tool_use_id: "tool_id",
name: "tool_name",
},
},
],
},
},
stop_reason: "end_turn",
usage: {
input_tokens: 10,
output_tokens: 20,
total_tokens: 30,
},
metrics: {
latency_ms: 999,
},
},
]
end
end
82 changes: 82 additions & 0 deletions spec/system/conversation_with_claude_structured_answer_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
RSpec.describe "Conversation with Claude with a structured answer" do
scenario do
given_i_am_a_signed_in_early_access_user
and_i_have_confirmed_i_understand_chat_risks
when_i_visit_the_conversation_page
and_i_enter_a_question
then_i_see_the_answer_is_pending

when_the_first_answer_is_generated
and_i_click_on_the_check_answer_button
then_i_see_my_question_on_the_page
and_i_can_see_the_first_answer

when_i_enter_a_second_question
then_i_see_the_answer_is_pending

when_the_second_answer_is_generated
and_i_click_on_the_check_answer_button
then_i_see_my_second_question_on_the_page
and_i_can_see_the_second_answer
end

def when_i_visit_the_conversation_page
visit show_conversation_path
end

def and_i_enter_a_question
@first_question = "How much tax should I be paying?"
fill_in "Message", with: @first_question
click_on "Send"
end

def then_i_see_the_answer_is_pending
expect(page).to have_content("GOV.UK Chat is generating an answer")
end

def when_the_first_answer_is_generated
@first_answer = "Lots of tax."
stub_bedrock_request(
:converse,
stub_claude_structured_answer_reponse(@first_answer),
)

execute_queued_sidekiq_jobs
end

def when_the_second_answer_is_generated
@second_answer = "Even more tax."
stub_bedrock_request(
:converse,
stub_claude_structured_answer_reponse(@second_answer),
)

execute_queued_sidekiq_jobs
end

def and_i_click_on_the_check_answer_button
click_on "Check if an answer has been generated"
end

def then_i_see_my_question_on_the_page
expect(page).to have_content(@first_question)
end

def then_i_see_my_second_question_on_the_page
expect(page).to have_content(@second_question)
end

def and_i_can_see_the_first_answer
expect(page).to have_content(@first_answer)
end

def and_i_can_see_the_second_answer
expect(page).to have_content(@second_answer)
end

def when_i_enter_a_second_question
@second_question = "Are you sure?"
fill_in "Message", with: @second_question
click_on "Send"
end
end

0 comments on commit e824b5c

Please sign in to comment.