Go: fix context (#18118)

Signed-off-by: Jin Hai <haijin.chn@gmail.com>
This commit is contained in:
Jin Hai
2026-08-11 19:19:29 +08:00
committed by GitHub
parent 8bd5768ebc
commit c75edbfbe8
36 changed files with 492 additions and 352 deletions

View File

@@ -17,7 +17,6 @@
package component
import (
"context"
"reflect"
"testing"
@@ -34,7 +33,7 @@ func TestStringTransform_SplitBasic(t *testing.T) {
t.Fatalf("NewStringTransformComponent: %v", err)
}
state := canvas.NewCanvasState("run-1", "task-1")
ctx := canvas.WithState(context.Background(), state)
ctx := canvas.WithState(t.Context(), state)
out, err := c.Invoke(ctx, nil, map[string]any{"line": "a,b;c"})
if err != nil {
@@ -54,7 +53,7 @@ func TestStringTransform_SplitNoDelim(t *testing.T) {
"delimiters": []string{","},
})
state := canvas.NewCanvasState("run-2", "task-2")
ctx := canvas.WithState(context.Background(), state)
ctx := canvas.WithState(t.Context(), state)
out, err := c.Invoke(ctx, nil, map[string]any{"line": "abc"})
if err != nil {
@@ -75,7 +74,7 @@ func TestStringTransform_Merge(t *testing.T) {
"script": "{{x}} and {{y}}",
})
state := canvas.NewCanvasState("run-3", "task-3")
ctx := canvas.WithState(context.Background(), state)
ctx := canvas.WithState(t.Context(), state)
out, err := c.Invoke(ctx, nil, map[string]any{"x": "foo", "y": "bar"})
if err != nil {
@@ -95,7 +94,7 @@ func TestStringTransform_MergeIterationAliases(t *testing.T) {
state := canvas.NewCanvasState("run-iter", "task-iter")
state.Globals["__item__"] = "beta"
state.Globals["__index__"] = 1
ctx := canvas.WithState(context.Background(), state)
ctx := canvas.WithState(t.Context(), state)
out, err := c.Invoke(ctx, nil, map[string]any{})
if err != nil {
@@ -116,7 +115,7 @@ func TestStringTransform_SplitFromStateRef(t *testing.T) {
})
state := canvas.NewCanvasState("run-4", "task-4")
state.Outputs["cpn_0"] = map[string]any{"x": "alpha,beta,gamma"}
ctx := canvas.WithState(context.Background(), state)
ctx := canvas.WithState(t.Context(), state)
out, err := c.Invoke(ctx, nil, nil)
if err != nil {
@@ -138,7 +137,7 @@ func TestStringTransform_MergeMissingPlaceholder(t *testing.T) {
"script": "hello {{name}}",
})
state := canvas.NewCanvasState("run-5", "task-5")
ctx := canvas.WithState(context.Background(), state)
ctx := canvas.WithState(t.Context(), state)
out, err := c.Invoke(ctx, nil, map[string]any{})
if err != nil {