MCPcopy Index your code
hub / github.com/github/copilot-sdk / serveInMemoryRuntime

Function serveInMemoryRuntime

go/client_test.go:1582–1638  ·  view source on GitHub ↗
(t *testing.T, stdinR *io.PipeReader, stdoutW *io.PipeWriter, requests *requestRecorder, done chan<- struct{})

Source from the content-addressed store, hash-verified

1580}
1581
1582func serveInMemoryRuntime(t *testing.T, stdinR *io.PipeReader, stdoutW *io.PipeWriter, requests *requestRecorder, done chan<- struct{}) {
1583 t.Helper()
1584 defer close(done)
1585
1586 serverAssignedSessions := 0
1587 for {
1588 frame, err := readTestJSONRPCFrame(stdinR)
1589 if err != nil {
1590 return
1591 }
1592
1593 var request struct {
1594 ID json.RawMessage `json:"id"`
1595 Method string `json:"method"`
1596 Params map[string]any `json:"params"`
1597 }
1598 if err := json.Unmarshal(frame, &request); err != nil {
1599 t.Errorf("failed to unmarshal JSON-RPC request: %v", err)
1600 return
1601 }
1602 requests.append(recordedRequest{Method: request.Method, Params: request.Params})
1603
1604 var result map[string]any
1605 switch request.Method {
1606 case "session.create", "session.resume":
1607 sessionID, _ := request.Params["sessionId"].(string)
1608 if sessionID == "" {
1609 serverAssignedSessions++
1610 sessionID = fmt.Sprintf("server-assigned-session-%d", serverAssignedSessions)
1611 }
1612 result = map[string]any{"sessionId": sessionID, "workspacePath": nil}
1613 case "session.eventLog.registerInterest":
1614 result = map[string]any{"id": "interest-1"}
1615 case "session.options.update":
1616 result = map[string]any{"success": true}
1617 case "session.skills.reload", "session.destroy":
1618 result = map[string]any{}
1619 default:
1620 t.Errorf("unexpected JSON-RPC method %s", request.Method)
1621 return
1622 }
1623
1624 response := map[string]any{
1625 "jsonrpc": "2.0",
1626 "id": json.RawMessage(request.ID),
1627 "result": result,
1628 }
1629 data, err := json.Marshal(response)
1630 if err != nil {
1631 t.Errorf("failed to marshal JSON-RPC response: %v", err)
1632 return
1633 }
1634 if _, err := fmt.Fprintf(stdoutW, "Content-Length: %d\r\n\r\n%s", len(data), data); err != nil {
1635 return
1636 }
1637 }
1638}
1639

Callers 1

newInMemoryClientFunction · 0.85

Calls 4

readTestJSONRPCFrameFunction · 0.85
appendMethod · 0.80
MarshalMethod · 0.80
closeFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…