Skip to content

Commit 981d834

Browse files
authored
downgrade golang version to 1.20 (#82)
* downgrade golang version to 1.20 * fix implict memory aliasing in loop for go1.20
1 parent 44ab1c9 commit 981d834

File tree

11 files changed

+133
-193
lines changed

11 files changed

+133
-193
lines changed

examples/go.mod

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
module trpc.group/trpc-go/trpc-a2a-go/examples
22

3-
go 1.23.0
3+
go 1.20.0
44

5-
toolchain go1.23.7
5+
replace trpc.group/trpc-go/trpc-a2a-go => ../
6+
7+
replace trpc.group/trpc-go/trpc-a2a-go/taskmanager/redis => ../taskmanager/redis
68

79
require (
810
github.com/go-chi/chi/v5 v5.2.2
911
github.com/google/uuid v1.6.0
1012
github.com/lestrrat-go/jwx/v2 v2.1.4
1113
github.com/redis/go-redis/v9 v9.10.0
12-
golang.org/x/oauth2 v0.29.0
14+
golang.org/x/oauth2 v0.26.0
1315
trpc.group/trpc-go/trpc-a2a-go v0.0.3
1416
trpc.group/trpc-go/trpc-a2a-go/taskmanager/redis v0.0.0-20250625115112-3bb198d0dc98
1517
)
@@ -28,10 +30,6 @@ require (
2830
github.com/segmentio/asm v1.2.0 // indirect
2931
go.uber.org/multierr v1.10.0 // indirect
3032
go.uber.org/zap v1.27.0 // indirect
31-
golang.org/x/crypto v0.35.0 // indirect
33+
golang.org/x/crypto v0.32.0 // indirect
3234
golang.org/x/sys v0.30.0 // indirect
3335
)
34-
35-
replace trpc.group/trpc-go/trpc-a2a-go => ../
36-
37-
replace trpc.group/trpc-go/trpc-a2a-go/taskmanager/redis => ../taskmanager/redis

examples/go.sum

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
2-
github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c=
32
github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=
4-
github.com/bsm/gomega v1.27.10/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0=
53
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
64
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
75
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
86
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
9-
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
107
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0 h1:NMZiJj8QnKe1LgsbDayM4UoHwbvwDRwnI3hwNaAHRnc=
118
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0/go.mod h1:ZXNYxsqcloTdSy/rNShjYzMhyjf0LaoftYK0p+A3h40=
129
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
@@ -18,7 +15,6 @@ github.com/goccy/go-json v0.10.3/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PU
1815
github.com/golang-jwt/jwt/v5 v5.2.2 h1:Rl4B7itRWVtYIHFrSNd7vhTiz9UpLdi6gZhZ3wEeDy8=
1916
github.com/golang-jwt/jwt/v5 v5.2.2/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
2017
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
21-
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
2218
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
2319
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
2420
github.com/lestrrat-go/blackmagic v1.0.2 h1:Cg2gVSc9h7sz9NOByczrbUvLopQmXrfFx//N+AkAr5k=
@@ -43,20 +39,17 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
4339
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
4440
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
4541
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
46-
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
4742
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
48-
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
4943
go.uber.org/multierr v1.10.0 h1:S0h4aNzvfcFsC3dRF1jLoaov7oRaKqRGC/pUEJ2yvPQ=
5044
go.uber.org/multierr v1.10.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
5145
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
5246
go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
53-
golang.org/x/crypto v0.35.0 h1:b15kiHdrGCHrP6LvwaQ3c03kgNhhiMgvlhxHQhmg2Xs=
54-
golang.org/x/crypto v0.35.0/go.mod h1:dy7dXNW32cAb/6/PRuTNsix8T+vJAqvuIy5Bli/x0YQ=
55-
golang.org/x/oauth2 v0.29.0 h1:WdYw2tdTK1S8olAzWHdgeqfy+Mtm9XNhv/xJsY65d98=
56-
golang.org/x/oauth2 v0.29.0/go.mod h1:onh5ek6nERTohokkhCD/y2cV4Do3fxFHFuAejCkRWT8=
47+
golang.org/x/crypto v0.32.0 h1:euUpcYgM8WcP71gNpTqQCn6rC2t6ULUPiOzfWaXVVfc=
48+
golang.org/x/crypto v0.32.0/go.mod h1:ZnnJkOaASj8g0AjIduWNlq2NRxL0PlBrbKVyZ6V/Ugc=
49+
golang.org/x/oauth2 v0.26.0 h1:afQXWNNaeC4nvZ0Ed9XvCCzXM6UHJG7iCg0W4fPqSBE=
50+
golang.org/x/oauth2 v0.26.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
5751
golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc=
5852
golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
5953
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
6054
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
6155
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
62-
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

examples/subpath/go.mod

Lines changed: 0 additions & 26 deletions
This file was deleted.

examples/subpath/go.sum

Lines changed: 0 additions & 50 deletions
This file was deleted.

go.mod

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
module trpc.group/trpc-go/trpc-a2a-go
22

3-
go 1.23.0
4-
5-
toolchain go1.23.7
3+
go 1.20.0
64

75
require (
86
github.com/golang-jwt/jwt/v5 v5.2.2
97
github.com/google/uuid v1.6.0
108
github.com/lestrrat-go/jwx/v2 v2.1.4
119
github.com/stretchr/testify v1.10.0
1210
go.uber.org/zap v1.27.0
13-
golang.org/x/oauth2 v0.29.0
11+
golang.org/x/oauth2 v0.26.0
1412
)
1513

1614
require (
@@ -25,7 +23,7 @@ require (
2523
github.com/pmezard/go-difflib v1.0.0 // indirect
2624
github.com/segmentio/asm v1.2.0 // indirect
2725
go.uber.org/multierr v1.10.0 // indirect
28-
golang.org/x/crypto v0.35.0 // indirect
26+
golang.org/x/crypto v0.32.0 // indirect
2927
golang.org/x/sys v0.30.0 // indirect
3028
gopkg.in/yaml.v3 v3.0.1 // indirect
3129
)

go.sum

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ github.com/goccy/go-json v0.10.3/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PU
88
github.com/golang-jwt/jwt/v5 v5.2.2 h1:Rl4B7itRWVtYIHFrSNd7vhTiz9UpLdi6gZhZ3wEeDy8=
99
github.com/golang-jwt/jwt/v5 v5.2.2/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
1010
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
11-
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
1211
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
1312
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
1413
github.com/lestrrat-go/blackmagic v1.0.2 h1:Cg2gVSc9h7sz9NOByczrbUvLopQmXrfFx//N+AkAr5k=
@@ -33,15 +32,14 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
3332
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
3433
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
3534
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
36-
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
3735
go.uber.org/multierr v1.10.0 h1:S0h4aNzvfcFsC3dRF1jLoaov7oRaKqRGC/pUEJ2yvPQ=
3836
go.uber.org/multierr v1.10.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
3937
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
4038
go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
41-
golang.org/x/crypto v0.35.0 h1:b15kiHdrGCHrP6LvwaQ3c03kgNhhiMgvlhxHQhmg2Xs=
42-
golang.org/x/crypto v0.35.0/go.mod h1:dy7dXNW32cAb/6/PRuTNsix8T+vJAqvuIy5Bli/x0YQ=
43-
golang.org/x/oauth2 v0.29.0 h1:WdYw2tdTK1S8olAzWHdgeqfy+Mtm9XNhv/xJsY65d98=
44-
golang.org/x/oauth2 v0.29.0/go.mod h1:onh5ek6nERTohokkhCD/y2cV4Do3fxFHFuAejCkRWT8=
39+
golang.org/x/crypto v0.32.0 h1:euUpcYgM8WcP71gNpTqQCn6rC2t6ULUPiOzfWaXVVfc=
40+
golang.org/x/crypto v0.32.0/go.mod h1:ZnnJkOaASj8g0AjIduWNlq2NRxL0PlBrbKVyZ6V/Ugc=
41+
golang.org/x/oauth2 v0.26.0 h1:afQXWNNaeC4nvZ0Ed9XvCCzXM6UHJG7iCg0W4fPqSBE=
42+
golang.org/x/oauth2 v0.26.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
4543
golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc=
4644
golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
4745
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=

internal/sse/sse_test.go

Lines changed: 99 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -244,55 +244,121 @@ func TestCloseEventDataMarshaling(t *testing.T) {
244244
}
245245
}
246246

247-
func TestFormatJSONRPCEvent(t *testing.T) {
248-
// Test data
249-
eventType := "test_event"
250-
eventID := "test-request-123"
251-
eventData := map[string]string{
252-
"key1": "value1",
253-
"key2": "value2",
247+
func TestFormatJSONRPCEventBatch(t *testing.T) {
248+
// Test data - multiple events
249+
events := []EventBatch{
250+
{
251+
EventType: "status_update",
252+
ID: "test-request-123",
253+
Data: map[string]string{
254+
"status": "working",
255+
"task_id": "task-1",
256+
},
257+
},
258+
{
259+
EventType: "artifact_update",
260+
ID: "test-request-123",
261+
Data: map[string]string{
262+
"artifact_id": "artifact-1",
263+
"content": "test content",
264+
},
265+
},
266+
{
267+
EventType: "status_update",
268+
ID: "test-request-123",
269+
Data: map[string]string{
270+
"status": "completed",
271+
"task_id": "task-1",
272+
},
273+
},
254274
}
255275

256276
// Buffer to capture the output
257277
var buf bytes.Buffer
258278

259-
// Format the event
260-
err := FormatJSONRPCEvent(&buf, eventType, eventID, eventData)
261-
assert.NoError(t, err, "FormatJSONRPCEvent should not return an error")
279+
// Format the batch
280+
err := FormatJSONRPCEventBatch(&buf, events)
281+
assert.NoError(t, err, "FormatJSONRPCEventBatch should not return an error")
262282

263283
// Get the formatted output
264284
output := buf.String()
265285

266-
// Verify the SSE format structure
267-
assert.Contains(t, output, "event: test_event", "Output should contain the event type")
268-
assert.Contains(t, output, "data: {", "Output should contain JSON data")
286+
// Verify the SSE format structure for all events
287+
assert.Contains(t, output, "event: status_update", "Output should contain status_update event type")
288+
assert.Contains(t, output, "event: artifact_update", "Output should contain artifact_update event type")
269289
assert.Contains(t, output, "\"jsonrpc\":\"2.0\"", "Output should contain JSON-RPC version")
270290
assert.Contains(t, output, "\"id\":\"test-request-123\"", "Output should contain the request ID")
271291

272-
// Verify the content can be parsed back
292+
// Verify we have the expected number of events (3 events = 3 event: lines)
293+
eventLines := strings.Count(output, "event: ")
294+
assert.Equal(t, 3, eventLines, "Should have 3 event lines")
295+
296+
// Verify we have the expected number of data lines (3 events = 3 data: lines)
297+
dataLines := strings.Count(output, "data: ")
298+
assert.Equal(t, 3, dataLines, "Should have 3 data lines")
299+
300+
// Parse and verify each event
273301
scanner := bufio.NewScanner(strings.NewReader(output))
274-
var dataLine string
302+
var currentEventType string
303+
var eventCount int
304+
275305
for scanner.Scan() {
276306
line := scanner.Text()
277-
if strings.HasPrefix(line, "data: ") {
278-
dataLine = strings.TrimPrefix(line, "data: ")
279-
break
307+
if strings.HasPrefix(line, "event: ") {
308+
currentEventType = strings.TrimPrefix(line, "event: ")
309+
} else if strings.HasPrefix(line, "data: ") {
310+
dataLine := strings.TrimPrefix(line, "data: ")
311+
312+
// Parse the JSON-RPC response
313+
var response jsonrpc.Response
314+
err = json.Unmarshal([]byte(dataLine), &response)
315+
assert.NoError(t, err, "Should be able to unmarshal the JSON-RPC response")
316+
317+
// Check response structure
318+
assert.Equal(t, "2.0", response.JSONRPC, "JSONRPC version should be 2.0")
319+
assert.Equal(t, "test-request-123", response.ID, "ID should match the provided request ID")
320+
321+
// Verify result based on event type
322+
resultMap, ok := response.Result.(map[string]interface{})
323+
assert.True(t, ok, "Result should be a map")
324+
325+
switch currentEventType {
326+
case "status_update":
327+
if resultMap["status"] == "working" {
328+
assert.Equal(t, "working", resultMap["status"], "Working status should match")
329+
assert.Equal(t, "task-1", resultMap["task_id"], "Task ID should match")
330+
} else if resultMap["status"] == "completed" {
331+
assert.Equal(t, "completed", resultMap["status"], "Completed status should match")
332+
assert.Equal(t, "task-1", resultMap["task_id"], "Task ID should match")
333+
}
334+
case "artifact_update":
335+
assert.Equal(t, "artifact-1", resultMap["artifact_id"], "Artifact ID should match")
336+
assert.Equal(t, "test content", resultMap["content"], "Content should match")
337+
}
338+
339+
eventCount++
280340
}
281341
}
282342

283-
// Parse the JSON-RPC response
284-
var response jsonrpc.Response
285-
err = json.Unmarshal([]byte(dataLine), &response)
286-
assert.NoError(t, err, "Should be able to unmarshal the JSON-RPC response")
287-
288-
// Check response structure
289-
assert.Equal(t, "2.0", response.JSONRPC, "JSONRPC version should be 2.0")
290-
assert.Equal(t, eventID, response.ID, "ID should match the provided request ID")
291-
292-
// Verify result contains the same key-value pairs
293-
// JSON unmarshaling creates map[string]interface{}, so we can't use direct equality
294-
resultMap, ok := response.Result.(map[string]interface{})
295-
assert.True(t, ok, "Result should be a map")
296-
assert.Equal(t, "value1", resultMap["key1"], "Value for key1 should match")
297-
assert.Equal(t, "value2", resultMap["key2"], "Value for key2 should match")
343+
assert.Equal(t, 3, eventCount, "Should have processed 3 events")
344+
}
345+
346+
func TestFormatJSONRPCEventBatch_EmptySlice(t *testing.T) {
347+
// Test with empty events slice
348+
var buf bytes.Buffer
349+
err := FormatJSONRPCEventBatch(&buf, []EventBatch{})
350+
assert.NoError(t, err, "FormatJSONRPCEventBatch with empty slice should not return an error")
351+
352+
output := buf.String()
353+
assert.Empty(t, output, "Output should be empty for empty events slice")
354+
}
355+
356+
func TestFormatJSONRPCEventBatch_NilSlice(t *testing.T) {
357+
// Test with nil events slice
358+
var buf bytes.Buffer
359+
err := FormatJSONRPCEventBatch(&buf, nil)
360+
assert.NoError(t, err, "FormatJSONRPCEventBatch with nil slice should not return an error")
361+
362+
output := buf.String()
363+
assert.Empty(t, output, "Output should be empty for nil events slice")
298364
}

0 commit comments

Comments
 (0)