Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit989c43f

Browse files
committed
Make JSONRPC easier in conformance tests
1 parent26f9668 commit989c43f

File tree

1 file changed

+23
-35
lines changed

1 file changed

+23
-35
lines changed

‎conformance/conformance_test.go

Lines changed: 23 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -130,16 +130,19 @@ func TestCapabilities(t *testing.T) {
130130
anthropicServer:=start(t,anthropic)
131131
githubServer:=start(t,github)
132132

133-
req:=newInitializeRequest(
134-
initializeRequestParams{
133+
req:=initializeRequest{
134+
JSONRPC:"2.0",
135+
ID:1,
136+
Method:"initialize",
137+
Params:initializeParams{
135138
ProtocolVersion:"2025-03-26",
136139
Capabilities:clientCapabilities{},
137140
ClientInfo:clientInfo{
138141
Name:"ConformanceTest",
139142
Version:"0.0.1",
140143
},
141144
},
142-
)
145+
}
143146

144147
require.NoError(t,anthropicServer.send(req))
145148

@@ -274,48 +277,39 @@ func (s server) receive(res response) error {
274277
returnres.unmarshal(line)
275278
}
276279

280+
typerequestinterface {
281+
marshal() ([]byte,error)
282+
}
283+
284+
typeresponseinterface {
285+
unmarshal([]byte)error
286+
}
287+
277288
typejsonRPRCRequest[paramsany]struct {
278289
JSONRPCstring`json:"jsonrpc"`
279290
IDint`json:"id"`
280291
Methodstring`json:"method"`
281292
Paramsparams`json:"params"`
282293
}
283294

295+
func (rjsonRPRCRequest[any])marshal() ([]byte,error) {
296+
returnjson.Marshal(r)
297+
}
298+
284299
typejsonRPRCResponse[resultany]struct {
285300
JSONRPCstring`json:"jsonrpc"`
286301
IDint`json:"id"`
287302
Methodstring`json:"method"`
288303
Resultresult`json:"result"`
289304
}
290305

291-
typerequestinterface {
292-
marshal() ([]byte,error)
293-
}
294-
295-
typeresponseinterface {
296-
unmarshal([]byte)error
297-
}
298-
299-
funcnewInitializeRequest(paramsinitializeRequestParams)initializeRequest {
300-
returninitializeRequest{
301-
jsonRPRCRequest:jsonRPRCRequest[initializeRequestParams]{
302-
JSONRPC:"2.0",
303-
ID:1,
304-
Method:"initialize",
305-
Params:params,
306-
},
307-
}
308-
}
309-
310-
typeinitializeRequeststruct {
311-
jsonRPRCRequest[initializeRequestParams]
306+
func (r*jsonRPRCResponse[any])unmarshal(b []byte)error {
307+
returnjson.Unmarshal(b,r)
312308
}
313309

314-
func (rinitializeRequest)marshal() ([]byte,error) {
315-
returnjson.Marshal(r)
316-
}
310+
typeinitializeRequest=jsonRPRCRequest[initializeParams]
317311

318-
typeinitializeRequestParamsstruct {
312+
typeinitializeParamsstruct {
319313
ProtocolVersionstring`json:"protocolVersion"`
320314
CapabilitiesclientCapabilities`json:"capabilities"`
321315
ClientInfoclientInfo`json:"clientInfo"`
@@ -328,13 +322,7 @@ type clientInfo struct {
328322
Versionstring`json:"version"`
329323
}
330324

331-
typeinitializeResponsestruct {
332-
jsonRPRCResponse[initializeResult]
333-
}
334-
335-
func (r*initializeResponse)unmarshal(b []byte)error {
336-
returnjson.Unmarshal(b,r)
337-
}
325+
typeinitializeResponse=jsonRPRCResponse[initializeResult]
338326

339327
typeinitializeResultstruct {
340328
ProtocolVersionstring`json:"protocolVersion"`

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp