Skip to content

Commit 7a27c16

Browse files
authored
all: run modernize happy (google#281)
$ go run golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@latest -fix -test ./... Signed-off-by: Koichi Shiraishi <zchee.io@gmail.com>
1 parent f1d3cc5 commit 7a27c16

File tree

8 files changed

+33
-39
lines changed

8 files changed

+33
-39
lines changed

‎agent/llmagent/llmagent_saveoutput_test.go‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func createTestEvent(author, contentText string, isFinal bool) *session.Event {
4444
InvocationID: "test_invocation",
4545
Author: author,
4646
LLMResponse: model.LLMResponse{Content: content, Partial: !isFinal},
47-
Actions: session.EventActions{StateDelta: make(map[string]interface{})},
47+
Actions: session.EventActions{StateDelta: make(map[string]any)},
4848
}
4949
}
5050

@@ -54,38 +54,38 @@ func TestLlmAgent_MaybeSaveOutputToState(t *testing.T) {
5454
name string
5555
agentConfig Config
5656
event *session.Event
57-
wantStateDelta map[string]interface{}
57+
wantStateDelta map[string]any
5858
customEventParts []*genai.Part // For multi-part test
5959
}{
6060
{
6161
name: "skips when event author differs from agentConfig name",
6262
agentConfig: Config{Name: "agent_a", OutputKey: "result"},
6363
event: createTestEvent("agent_b", "Response from B", true),
64-
wantStateDelta: map[string]interface{}{},
64+
wantStateDelta: map[string]any{},
6565
},
6666
{
6767
name: "saves when event author matches agentConfig name",
6868
agentConfig: Config{Name: "test_agent", OutputKey: "result"},
6969
event: createTestEvent("test_agent", "Test response", true),
70-
wantStateDelta: map[string]interface{}{"result": "Test response"},
70+
wantStateDelta: map[string]any{"result": "Test response"},
7171
},
7272
{
7373
name: "skips when output_key is not set",
7474
agentConfig: Config{Name: "test_agent"}, // No OutputKey
7575
event: createTestEvent("test_agent", "Test response", true),
76-
wantStateDelta: map[string]interface{}{},
76+
wantStateDelta: map[string]any{},
7777
},
7878
{
7979
name: "skips for non-final responses",
8080
agentConfig: Config{Name: "test_agent", OutputKey: "result"},
8181
event: createTestEvent("test_agent", "*genai.Partial response", false),
82-
wantStateDelta: map[string]interface{}{},
82+
wantStateDelta: map[string]any{},
8383
},
8484
{
8585
name: "skips when event has no content text",
8686
agentConfig: Config{Name: "test_agent", OutputKey: "result"},
8787
event: createTestEvent("test_agent", "", true),
88-
wantStateDelta: map[string]interface{}{},
88+
wantStateDelta: map[string]any{},
8989
},
9090
{
9191
name: "concatenates multiple text parts",
@@ -96,13 +96,13 @@ func TestLlmAgent_MaybeSaveOutputToState(t *testing.T) {
9696
{Text: "world"},
9797
{Text: "!"},
9898
},
99-
wantStateDelta: map[string]interface{}{"result": "Hello world!"},
99+
wantStateDelta: map[string]any{"result": "Hello world!"},
100100
},
101101
{
102102
name: "skips on case-sensitive name mismatch",
103103
agentConfig: Config{Name: "TestAgent", OutputKey: "result"},
104104
event: createTestEvent("testagent", "Test response", true),
105-
wantStateDelta: map[string]interface{}{},
105+
wantStateDelta: map[string]any{},
106106
},
107107
//TODO tests with OutputSchema
108108
}

‎agent/llmagent/state_agent_test.go‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"context"
1919
"fmt"
2020
"iter"
21+
"maps"
2122
"math"
2223
"math/rand"
2324
"strings"
@@ -429,9 +430,7 @@ func afterToolEnhancementCallback(ctx tool.Context, t tool.Tool, args map[string
429430
}
430431
fmt.Printf("✨ ENHANCE: Adding metadata to response from '%s'\n", t.Name())
431432
enhancedResponse := make(map[string]any)
432-
for k, v := range result {
433-
enhancedResponse[k] = v
434-
}
433+
maps.Copy(enhancedResponse, result)
435434
enhancedResponse["enhanced"] = true
436435
enhancedResponse["enhancement_timestamp"] = time.Now()
437436
enhancedResponse["tool_name"] = t.Name()
@@ -445,9 +444,7 @@ func afterToolAsyncCallback(ctx tool.Context, t tool.Tool, args map[string]any,
445444
}
446445
fmt.Printf("🔄 ASYNC AFTER: Post-processing response from '%s'\n", t.Name())
447446
processedResponse := make(map[string]any)
448-
for k, v := range result {
449-
processedResponse[k] = v
450-
}
447+
maps.Copy(processedResponse, result)
451448
processedResponse["async_processed"] = true
452449
processedResponse["processor"] = "async_after_callback"
453450
return processedResponse, nil

‎agent/workflowagents/sequentialagent/agent_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ func TestNewSequentialAgent(t *testing.T) {
229229

230230
// run twice, the second time it will need to determine which agent to use, and we want to get the same result
231231
gotEvents = make([]*session.Event, 0)
232-
for i := 0; i < 2; i++ {
232+
for range 2 {
233233
for event, err := range agentRunner.Run(ctx, "user_id", "session_id", genai.NewContentFromText("user input", genai.RoleUser), agent.RunConfig{}) {
234234
if err != nil {
235235
t.Errorf("got unexpected error: %v", err)

‎examples/workflowagents/parallel/main.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ type myAgent struct {
8080

8181
func (a myAgent) Run(ctx agent.InvocationContext) iter.Seq2[*session.Event, error] {
8282
return func(yield func(*session.Event, error) bool) {
83-
for i := 0; i < 3; i++ {
83+
for range 3 {
8484
if !yield(&session.Event{
8585
LLMResponse: model.LLMResponse{
8686
Content: &genai.Content{

‎internal/llminternal/instruction_processor.go‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package llminternal
1717
import (
1818
"fmt"
1919
"regexp"
20+
"slices"
2021
"strings"
2122
"unicode"
2223

@@ -122,8 +123,8 @@ func replaceMatch(ctx agent.InvocationContext, match string) (string, error) {
122123
varName = strings.TrimSuffix(varName, "?")
123124
}
124125

125-
if strings.HasPrefix(varName, "artifact.") {
126-
fileName := strings.TrimPrefix(varName, "artifact.")
126+
if after, ok := strings.CutPrefix(varName, "artifact."); ok {
127+
fileName := after
127128
if ctx.Artifacts() == nil {
128129
return "", fmt.Errorf("artifact service is not initialized")
129130
}
@@ -188,10 +189,8 @@ func isValidStateName(varName string) bool {
188189
if len(parts) == 2 {
189190
prefix := parts[0] + ":"
190191
validPrefixes := []string{appPrefix, userPrefix, tempPrefix}
191-
for _, p := range validPrefixes {
192-
if prefix == p {
193-
return isIdentifier(parts[1])
194-
}
192+
if slices.Contains(validPrefixes, prefix) {
193+
return isIdentifier(parts[1])
195194
}
196195
}
197196
return false

‎internal/llminternal/instruction_processor_test.go‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func TestInjectSessionState(t *testing.T) {
3333
testCases := []struct {
3434
name string // Name of the sub-test
3535
template string // Input template string
36-
state map[string]interface{} // Initial session state
36+
state map[string]any // Initial session state
3737
artifacts map[string]*genai.Part // Artifacts for the mock service
3838
expectNilService bool // Flag to test with a nil artifact service
3939
want string // Expected successful output
@@ -44,7 +44,7 @@ func TestInjectSessionState(t *testing.T) {
4444
{
4545
name: "successful state injection",
4646
template: "Hello {user_name}, you are in {app_state} state.",
47-
state: map[string]interface{}{"user_name": "Foo", "app_state": "active"},
47+
state: map[string]any{"user_name": "Foo", "app_state": "active"},
4848
want: "Hello Foo, you are in active state.",
4949
},
5050
// Corresponds to: test_inject_session_state_with_artifact
@@ -61,14 +61,14 @@ func TestInjectSessionState(t *testing.T) {
6161
{
6262
name: "optional missing state variable",
6363
template: "Optional value: {optional_value?}",
64-
state: map[string]interface{}{},
64+
state: map[string]any{},
6565
want: "Optional value: ",
6666
},
6767
// Corresponds to: test_inject_session_state_with_missing_state_raises_key_error
6868
{
6969
name: "missing required state variable",
7070
template: "Hello {missing_key}!",
71-
state: map[string]interface{}{"user_name": "Foo"},
71+
state: map[string]any{"user_name": "Foo"},
7272
wantErr: true,
7373
wantErrMsg: "failed to get key \"missing_key\" from state: state key does not exist",
7474
},
@@ -86,28 +86,28 @@ func TestInjectSessionState(t *testing.T) {
8686
{
8787
name: "invalid state name is not replaced",
8888
template: "Hello {invalid-key}!",
89-
state: map[string]interface{}{"user_name": "Foo"},
89+
state: map[string]any{"user_name": "Foo"},
9090
want: "Hello {invalid-key}!",
9191
},
9292
// Corresponds to: test_inject_session_state_with_invalid_prefix_state_name_returns_original
9393
{
9494
name: "invalid prefix state name is not replaced",
9595
template: "Hello {invalid:key}!",
96-
state: map[string]interface{}{"user_name": "Foo"},
96+
state: map[string]any{"user_name": "Foo"},
9797
want: "Hello {invalid:key}!",
9898
},
9999
// Corresponds to: test_inject_session_state_with_valid_prefix_state
100100
{
101101
name: "valid prefixed state variable",
102102
template: "Hello {app:user_name}!",
103-
state: map[string]interface{}{"app:user_name": "Foo"},
103+
state: map[string]any{"app:user_name": "Foo"},
104104
want: "Hello Foo!",
105105
},
106106
// Corresponds to: test_inject_session_state_with_none_state_value_returns_empty
107107
{
108108
name: "state value is nil",
109109
template: "Value: {test_key}",
110-
state: map[string]interface{}{"test_key": nil},
110+
state: map[string]any{"test_key": nil},
111111
want: "Value: ",
112112
},
113113
// Corresponds to: test_inject_session_state_with_optional_missing_artifact_returns_empty
@@ -145,7 +145,7 @@ Your favorite color is {favorite_color}.
145145
The artifact says: {artifact.my_file}
146146
And another optional artifact: {artifact.other_file?}
147147
`,
148-
state: map[string]interface{}{
148+
state: map[string]any{
149149
"user_name": "Foo",
150150
"user_age": 30,
151151
"favorite_color": "blue",

‎internal/sessioninternal/mutablesession_test.go‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package sessioninternal_test
1717
import (
1818
"context"
1919
"fmt"
20+
"maps"
2021
"reflect"
2122
"testing"
2223

@@ -105,10 +106,7 @@ func TestMutableSession_All(t *testing.T) {
105106
sessionID := fmt.Sprintf("testAll-%d", i)
106107
ms, _ := createMutableSession(ctx, t, sessionID, tc.initial)
107108

108-
gotMap := make(map[string]any)
109-
for k, v := range ms.All() {
110-
gotMap[k] = v
111-
}
109+
gotMap := maps.Collect(ms.All())
112110

113111
wantMap := tc.initial
114112
if wantMap == nil {

‎server/adka2a/metadata.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
package adka2a
1616

1717
import (
18+
"maps"
19+
1820
"github.com/a2aproject/a2a-go/a2asrv"
1921
"google.golang.org/adk/internal/converters"
2022
"google.golang.org/adk/session"
@@ -46,9 +48,7 @@ func toInvocationMeta(config ExecutorConfig, reqCtx *a2asrv.RequestContext) invo
4648

4749
func toEventMeta(meta invocationMeta, event *session.Event) (map[string]any, error) {
4850
result := make(map[string]any)
49-
for k, v := range meta.eventMeta {
50-
result[k] = v
51-
}
51+
maps.Copy(result, meta.eventMeta)
5252

5353
for k, v := range map[string]string{
5454
"invocation_id": event.InvocationID,

0 commit comments

Comments
 (0)