-
Notifications
You must be signed in to change notification settings - Fork 744
[fix][evaluation] call evaluator with target reentering #470
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
Open
lsy357
wants to merge
11
commits into
main
Choose a base branch
from
fix/expt
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
071287c
fix(evaluation): call evaluator with target reentering
lsy357 80c4b71
fix(foundation): resetpwd session check
lsy357 8ac5061
fix(infra): readme security warning
lsy357 74eab69
fix(evaluation): sql quote
lsy357 842f46a
Merge branch 'main' into fix/expt
lsy357 df6fd00
fix: ut
lsy357 4eb8f97
fix(evaluation): async report err
lsy357 7a29b2d
fix(evaluation): evaluator async retry
lsy357 a15dda7
fix(evaluation): ExecuteEvalTargetParam
lsy357 c69174c
fix(backend): SessionHMACKey in env
lsy357 2efe771
Merge branch 'main' into fix/expt
lsy357 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| // Copyright (c) 2026 coze-dev Authors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package db | ||
|
|
||
| import ( | ||
| "bytes" | ||
| ) | ||
|
|
||
| func QuoteSQLData(data string) string { | ||
| return "'" + escapeSQL(data) + "'" | ||
| } | ||
|
|
||
| func EscapeSQLData(data string) string { | ||
| return escapeSQL(data) | ||
| } | ||
|
|
||
| func escapeSQL(data string) string { | ||
lsy357 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| buf := bytes.NewBuffer(nil) | ||
| for _, c := range data { | ||
| switch c { | ||
| case 0x00: | ||
| buf.WriteByte('\\') | ||
| buf.WriteByte('0') | ||
| case '\'': | ||
| buf.WriteByte('\\') | ||
| buf.WriteByte('\'') | ||
| case '"': | ||
| buf.WriteByte('\\') | ||
| buf.WriteByte('"') | ||
| case 0x08: | ||
| buf.WriteByte('\\') | ||
| buf.WriteByte('b') | ||
| case 0x0A: | ||
| buf.WriteByte('\\') | ||
| buf.WriteByte('n') | ||
| case 0x0D: | ||
| buf.WriteByte('\\') | ||
| buf.WriteByte('r') | ||
| case 0x09: | ||
| buf.WriteByte('\\') | ||
| buf.WriteByte('t') | ||
| case 0x1A: | ||
| buf.WriteByte('\\') | ||
| buf.WriteByte('Z') | ||
| case '\\': | ||
| buf.WriteByte('\\') | ||
| buf.WriteByte('\\') | ||
| // case '%': | ||
| // buf.WriteByte('\\') | ||
| // buf.WriteByte('%') | ||
| // case '_': | ||
| // buf.WriteByte('\\') | ||
| // buf.WriteByte('_') | ||
| default: | ||
| buf.WriteRune(c) | ||
| } | ||
| } | ||
| return buf.String() | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| // Copyright (c) 2026 coze-dev Authors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package db | ||
|
|
||
| import "testing" | ||
|
|
||
| func TestQuoteSQLData(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| in string | ||
| want string | ||
| }{ | ||
| {name: "empty", in: "", want: "''"}, | ||
| {name: "simple", in: "abc", want: "'abc'"}, | ||
| {name: "single_quote", in: "O'Reilly", want: "'O\\'Reilly'"}, | ||
| {name: "double_quote", in: "a\"b", want: "'a\\\"b'"}, | ||
| {name: "backslash", in: `a\b`, want: "'a\\\\b'"}, | ||
| {name: "newline", in: "line1\nline2", want: "'line1\\nline2'"}, | ||
| {name: "tab", in: "a\tb", want: "'a\\tb'"}, | ||
| {name: "carriage_return", in: "a\rb", want: "'a\\rb'"}, | ||
| {name: "null_byte", in: string([]byte{0}), want: "'\\0'"}, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| got := QuoteSQLData(tt.in) | ||
| if got != tt.want { | ||
| t.Fatalf("QuoteSQLData(%q) = %q, want %q", tt.in, got, tt.want) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestEscapeSQLData(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| in string | ||
| want string | ||
| }{ | ||
| {name: "empty", in: "", want: ""}, | ||
| {name: "simple", in: "abc", want: "abc"}, | ||
| {name: "single_quote", in: "O'Reilly", want: "O\\'Reilly"}, | ||
| {name: "double_quote", in: "a\"b", want: "a\\\"b"}, | ||
| {name: "backslash", in: `a\b`, want: "a\\\\b"}, | ||
| {name: "newline", in: "line1\nline2", want: "line1\\nline2"}, | ||
| {name: "tab", in: "a\tb", want: "a\\tb"}, | ||
| {name: "carriage_return", in: "a\rb", want: "a\\rb"}, | ||
| {name: "null_byte", in: string([]byte{0}), want: "\\0"}, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| got := EscapeSQLData(tt.in) | ||
| if got != tt.want { | ||
| t.Fatalf("EscapeSQLData(%q) = %q, want %q", tt.in, got, tt.want) | ||
| } | ||
| }) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| // Copyright (c) 2025 coze-dev Authors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package entity | ||
|
|
||
| import ( | ||
| "context" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
|
|
||
| "github.com/coze-dev/coze-loop/backend/pkg/ctxcache" | ||
| ) | ||
|
|
||
| func TestExptItemEvalEvent_WithCtxTargetCalled(t *testing.T) { | ||
| t.Run("ctx not init: Store is no-op", func(t *testing.T) { | ||
| ctx := context.Background() | ||
| e := &ExptItemEvalEvent{} | ||
|
|
||
| e.WithCtxTargetCalled(ctx) | ||
| _, ok := ctxcache.Get[struct{}](ctx, ctxTargetCalledCacheKey{}) | ||
| assert.False(t, ok) | ||
| }) | ||
|
|
||
| t.Run("ctx init: should be stored and retrievable", func(t *testing.T) { | ||
| ctx := ctxcache.Init(context.Background()) | ||
| e := &ExptItemEvalEvent{} | ||
|
|
||
| e.WithCtxTargetCalled(ctx) | ||
| _, ok := ctxcache.Get[struct{}](ctx, ctxTargetCalledCacheKey{}) | ||
| assert.True(t, ok) | ||
| }) | ||
| } | ||
|
|
||
| func TestExptItemEvalEvent_CtxTargetCalled(t *testing.T) { | ||
| t.Run("ctx not init: always false", func(t *testing.T) { | ||
| ctx := context.Background() | ||
| e := &ExptItemEvalEvent{} | ||
|
|
||
| assert.False(t, e.CtxTargetCalled(ctx)) | ||
| }) | ||
|
|
||
| t.Run("ctx init but not marked: false", func(t *testing.T) { | ||
| ctx := ctxcache.Init(context.Background()) | ||
| e := &ExptItemEvalEvent{} | ||
|
|
||
| assert.False(t, e.CtxTargetCalled(ctx)) | ||
| }) | ||
|
|
||
| t.Run("ctx init and marked: true", func(t *testing.T) { | ||
| ctx := ctxcache.Init(context.Background()) | ||
| e := &ExptItemEvalEvent{} | ||
|
|
||
| e.WithCtxTargetCalled(ctx) | ||
| assert.True(t, e.CtxTargetCalled(ctx)) | ||
| }) | ||
|
|
||
| t.Run("different contexts are isolated", func(t *testing.T) { | ||
| ctx1 := ctxcache.Init(context.Background()) | ||
| ctx2 := ctxcache.Init(context.Background()) | ||
| e := &ExptItemEvalEvent{} | ||
|
|
||
| e.WithCtxTargetCalled(ctx1) | ||
| assert.True(t, e.CtxTargetCalled(ctx1)) | ||
| assert.False(t, e.CtxTargetCalled(ctx2)) | ||
| }) | ||
| } | ||
|
|
||
| func TestExptItemEvalEvent_IgnoreExistedEvaluatorResult(t *testing.T) { | ||
| t.Run("ctx init and target called: always false", func(t *testing.T) { | ||
| ctx := ctxcache.Init(context.Background()) | ||
|
|
||
| tests := []struct { | ||
| name string | ||
| runMode ExptRunMode | ||
| retry int | ||
| }{ | ||
| {name: "retry all with retryTimes=0", runMode: EvaluationModeRetryAll, retry: 0}, | ||
| {name: "retry items with retryTimes=0", runMode: EvaluationModeRetryItems, retry: 0}, | ||
| {name: "retry all with retryTimes=1", runMode: EvaluationModeRetryAll, retry: 1}, | ||
| {name: "submit mode", runMode: EvaluationModeSubmit, retry: 0}, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| e := &ExptItemEvalEvent{ExptRunMode: tt.runMode, RetryTimes: tt.retry} | ||
| e.WithCtxTargetCalled(ctx) | ||
| assert.False(t, e.IgnoreExistedEvaluatorResult(ctx)) | ||
| }) | ||
| } | ||
| }) | ||
|
|
||
| t.Run("ctx init but target not called: falls back to ignoreExistedResult", func(t *testing.T) { | ||
| ctx := ctxcache.Init(context.Background()) | ||
|
|
||
| e1 := &ExptItemEvalEvent{ExptRunMode: EvaluationModeRetryAll, RetryTimes: 0} | ||
| assert.True(t, e1.IgnoreExistedEvaluatorResult(ctx)) | ||
|
|
||
| e2 := &ExptItemEvalEvent{ExptRunMode: EvaluationModeRetryItems, RetryTimes: 0} | ||
| assert.True(t, e2.IgnoreExistedEvaluatorResult(ctx)) | ||
|
|
||
| e3 := &ExptItemEvalEvent{ExptRunMode: EvaluationModeRetryAll, RetryTimes: 1} | ||
| assert.False(t, e3.IgnoreExistedEvaluatorResult(ctx)) | ||
|
|
||
| e4 := &ExptItemEvalEvent{ExptRunMode: EvaluationModeSubmit, RetryTimes: 0} | ||
| assert.False(t, e4.IgnoreExistedEvaluatorResult(ctx)) | ||
| }) | ||
|
|
||
| t.Run("ctx not init: falls back to ignoreExistedResult", func(t *testing.T) { | ||
| ctx := context.Background() | ||
|
|
||
| e1 := &ExptItemEvalEvent{ExptRunMode: EvaluationModeRetryAll, RetryTimes: 0} | ||
| assert.True(t, e1.IgnoreExistedEvaluatorResult(ctx)) | ||
|
|
||
| e2 := &ExptItemEvalEvent{ExptRunMode: EvaluationModeRetryItems, RetryTimes: 0} | ||
| assert.True(t, e2.IgnoreExistedEvaluatorResult(ctx)) | ||
|
|
||
| e3 := &ExptItemEvalEvent{ExptRunMode: EvaluationModeRetryAll, RetryTimes: 1} | ||
| assert.False(t, e3.IgnoreExistedEvaluatorResult(ctx)) | ||
|
|
||
| e4 := &ExptItemEvalEvent{ExptRunMode: EvaluationModeSubmit, RetryTimes: 0} | ||
| assert.False(t, e4.IgnoreExistedEvaluatorResult(ctx)) | ||
| }) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.