Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(server): fix string wrapping for triggers #4034

Merged
merged 1 commit into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions server/executor/trigger/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/kubeshop/tracetest/agent/workers/trigger"
triggerer "github.com/kubeshop/tracetest/server/executor/trigger"
"github.com/kubeshop/tracetest/server/expression"
"github.com/kubeshop/tracetest/server/pkg/id"
"github.com/kubeshop/tracetest/server/test"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -295,3 +296,30 @@ func TestTriggerPostWithBearerAuth(t *testing.T) {
assert.Equal(t, 200, resp.Result.HTTP.StatusCode)
assert.Equal(t, "OK", resp.Result.HTTP.Body)
}

func TestTriggerResolveLargePayloadWithSingleQuote(t *testing.T) {
testObject := test.Test{
Name: "Run API to trigger Gemini ",
Trigger: trigger.Trigger{
Type: trigger.TriggerTypeHTTP,
HTTP: &trigger.HTTPRequest{
URL: "http://llm-api:8800/summarizeText",
Method: trigger.HTTPMethodPOST,
Headers: []trigger.HTTPHeader{
{Key: "Content-Type", Value: "application/json"},
},
Body: "{\n \"provider\": \"Google (Gemini)\",\n \"text\": \"Born in London, Turing was raised in southern England. He graduated from King's College, Cambridge, and in 1938, earned a doctorate degree from Princeton University. During World War II, Turing worked for the Government Code and Cypher School at Bletchley Park, Britain's codebreaking centre that produced Ultra intelligence. He led Hut 8, the section responsible for German naval cryptanalysis. Turing devised techniques for speeding the breaking of German ciphers, including improvements to the pre-war Polish bomba method, an electromechanical machine that could find settings for the Enigma machine. He played a crucial role in cracking intercepted messages that enabled the Allies to defeat the Axis powers in many crucial engagements, including the Battle of the Atlantic.\\n\\nAfter the war, Turing worked at the National Physical Laboratory, where he designed the Automatic Computing Engine, one of the first designs for a stored-program computer. In 1948, Turing joined Max Newman's Computing Machine Laboratory at the Victoria University of Manchester, where he helped develop the Manchester computers[12] and became interested in mathematical biology. Turing wrote on the chemical basis of morphogenesis and predicted oscillating chemical reactions such as the Belousov–Zhabotinsky reaction, first observed in the 1960s. Despite these accomplishments, he was never fully recognised during his lifetime because much of his work was covered by the Official Secrets Act.\"\n }",
},
},
}

triggerOptions := &triggerer.ResolveOptions{
Executor: expression.NewExecutor(),
}

httpTriggerer := triggerer.HTTP()
resolvedTest, err := httpTriggerer.Resolve(context.Background(), testObject, triggerOptions)

assert.NoError(t, err)
assert.NotNil(t, resolvedTest)
}
2 changes: 2 additions & 0 deletions server/executor/trigger/triggerer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"strings"
"sync"

"github.com/kubeshop/tracetest/agent/workers/trigger"
Expand Down Expand Up @@ -74,5 +75,6 @@ func (r *Registry) Get(triggererType trigger.TriggerType) (Triggerer, error) {
}

func WrapInQuotes(input string, quoteChar string) string {
input = strings.ReplaceAll(input, quoteChar, fmt.Sprintf("\\%s", quoteChar))
return fmt.Sprintf("%s%s%s", quoteChar, input, quoteChar)
}
Loading