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

@@ -102,12 +102,13 @@ func TestLLM_Invoke_OutputStructure_ValidFirstTry(t *testing.T) {
Model: "echo",
}}
withStubInvoker(t, stub)
ctx := t.Context()
c := NewLLMComponent(LLMParam{
ModelID: "echo",
OutputStructure: map[string]any{"name": "", "age": 0},
})
out, err := c.Invoke(context.Background(), nil, map[string]any{"user_prompt": "who?"})
out, err := c.Invoke(ctx, nil, map[string]any{"user_prompt": "who?"})
if err != nil {
t.Fatalf("Invoke: %v", err)
}
@@ -136,12 +137,13 @@ func TestLLM_Invoke_OutputStructure_RetryOnInvalid(t *testing.T) {
onCall: func() { calls++ },
}
withStubInvoker(t, inv)
ctx := t.Context()
c := NewLLMComponent(LLMParam{
ModelID: "echo",
OutputStructure: map[string]any{"name": ""},
})
out, err := c.Invoke(context.Background(), nil, map[string]any{"user_prompt": "who?"})
out, err := c.Invoke(ctx, nil, map[string]any{"user_prompt": "who?"})
if err != nil {
t.Fatalf("Invoke: %v", err)
}
@@ -173,12 +175,13 @@ func TestLLM_Invoke_OutputStructure_RetryStillFails(t *testing.T) {
onCall: func() { calls++ },
}
withStubInvoker(t, inv)
ctx := t.Context()
c := NewLLMComponent(LLMParam{
ModelID: "echo",
OutputStructure: map[string]any{"x": 0},
})
out, err := c.Invoke(context.Background(), nil, map[string]any{"user_prompt": "go"})
out, err := c.Invoke(ctx, nil, map[string]any{"user_prompt": "go"})
if err != nil {
t.Fatalf("Invoke should not error on parse failure: %v", err)
}