Skip to content

Commit 5b5dbda

Browse files
committed
test: cover normalize_job_name catch-all with non-string job_key
1 parent eda6d45 commit 5b5dbda

1 file changed

Lines changed: 59 additions & 0 deletions

File tree

test/lightning/ai_assistant/ai_assistant_test.exs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3793,6 +3793,65 @@ defmodule Lightning.AiAssistantTest do
37933793
assert is_nil(assistant_msg.job_id)
37943794
end
37953795

3796+
test "handles non-string job_key in attachment", %{
3797+
user: user,
3798+
project: project,
3799+
workflow: workflow
3800+
} do
3801+
session =
3802+
insert(:chat_session,
3803+
user: user,
3804+
project: project,
3805+
workflow: workflow,
3806+
session_type: "workflow_template",
3807+
meta: %{
3808+
"message_options" => %{
3809+
"use_global_assistant" => true,
3810+
"page" => "workflows/test/Some-job"
3811+
}
3812+
}
3813+
)
3814+
3815+
{:ok, session} =
3816+
AiAssistant.save_message(session, %{
3817+
role: :user,
3818+
content: "fix code",
3819+
user: user
3820+
})
3821+
3822+
# job_key is an integer instead of a string
3823+
complete_payload =
3824+
Jason.encode!(%{
3825+
"response" => "Fixed",
3826+
"attachments" => [
3827+
%{
3828+
"type" => "job_code",
3829+
"content" => "fn(state => state);",
3830+
"job_key" => 12345
3831+
}
3832+
],
3833+
"usage" => %{},
3834+
"meta" => %{}
3835+
})
3836+
3837+
sse_stream = [%{event: "complete", data: complete_payload}]
3838+
3839+
Mox.expect(Lightning.Tesla.Mock, :call, fn _env, _opts ->
3840+
{:ok, %Tesla.Env{status: 200, body: sse_stream}}
3841+
end)
3842+
3843+
{:ok, updated_session} =
3844+
AiAssistant.query_global_stream(session, "fix code",
3845+
workflow_yaml: "name: test",
3846+
page: "workflows/test/Some-job"
3847+
)
3848+
3849+
assistant_msg = List.last(updated_session.messages)
3850+
assert assistant_msg.code == "fn(state => state);"
3851+
# Non-string job_key won't match any job name
3852+
assert is_nil(assistant_msg.job_id)
3853+
end
3854+
37963855
test "handles non-list attachments", %{
37973856
user: user,
37983857
project: project,

0 commit comments

Comments
 (0)