MCPcopy Create free account
hub / github.com/github/copilot-sdk / TestCanvasAdapter_DispatchesToHandler

Function TestCanvasAdapter_DispatchesToHandler

go/canvas_test.go:126–196  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

124}
125
126func TestCanvasAdapter_DispatchesToHandler(t *testing.T) {
127 title := "Echo"
128 url := "https://example.test/echo"
129 handler := &recordingCanvasHandler{
130 openResult: rpc.CanvasProviderOpenResult{URL: &url, Title: &title},
131 actionResult: map[string]any{
132 "count": float64(2),
133 },
134 }
135
136 session := newTestCanvasSession("s1")
137 session.registerCanvasHandler(handler)
138
139 openResp, err := session.clientSessionAPIs.Canvas.Open(&rpc.CanvasProviderOpenRequest{
140 SessionID: "s1",
141 ExtensionID: "project:echo",
142 CanvasID: "echo",
143 InstanceID: "echo-1",
144 Input: map[string]any{"x": float64(1)},
145 })
146 if err != nil {
147 t.Fatalf("unexpected open error: %v", err)
148 }
149 if handler.openCtx == nil {
150 t.Fatalf("handler.OnOpen was not called")
151 }
152 if handler.openCtx.CanvasID != "echo" || handler.openCtx.InstanceID != "echo-1" {
153 t.Fatalf("unexpected open ctx: %+v", handler.openCtx)
154 }
155 if openResp.URL == nil || *openResp.URL != url {
156 t.Fatalf("response URL not propagated: %+v", openResp)
157 }
158
159 actionResp, err := session.clientSessionAPIs.Canvas.Invoke(&rpc.CanvasProviderInvokeActionRequest{
160 SessionID: "s1",
161 ExtensionID: "project:echo",
162 CanvasID: "echo",
163 InstanceID: "echo-1",
164 ActionName: "increment",
165 Input: map[string]any{"amount": float64(1)},
166 })
167 if err != nil {
168 t.Fatalf("unexpected action error: %v", err)
169 }
170 if handler.actionCtx == nil {
171 t.Fatalf("handler.OnAction was not called")
172 }
173 if handler.actionCtx.ActionName != "increment" {
174 t.Fatalf("unexpected action ctx: %+v", handler.actionCtx)
175 }
176 result, ok := actionResp.(map[string]any)
177 if !ok || result["count"] != float64(2) {
178 t.Fatalf("unexpected action result: %#v", actionResp)
179 }
180
181 closeResp, err := session.clientSessionAPIs.Canvas.Close(&rpc.CanvasProviderCloseRequest{
182 SessionID: "s1",
183 ExtensionID: "project:echo",

Callers

nothing calls this directly

Calls 5

newTestCanvasSessionFunction · 0.85
registerCanvasHandlerMethod · 0.80
OpenMethod · 0.65
InvokeMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…