MCPcopy Create free account
hub / github.com/compozy/agh / streamPermissionPrompt

Function streamPermissionPrompt

internal/api/httpapi/httpapi_integration_test.go:3384–3432  ·  view source on GitHub ↗
(t *testing.T, body io.ReadCloser, requestIDCh chan<- string, resultCh chan<- []sseRecord)

Source from the content-addressed store, hash-verified

3382}
3383
3384func streamPermissionPrompt(t *testing.T, body io.ReadCloser, requestIDCh chan<- string, resultCh chan<- []sseRecord) {
3385 t.Helper()
3386 defer func() {
3387 _ = body.Close()
3388 }()
3389
3390 scanner := bufio.NewScanner(body)
3391 records := make([]sseRecord, 0, 8)
3392 current := sseRecord{}
3393 requestIDSent := false
3394
3395 for scanner.Scan() {
3396 line := scanner.Text()
3397 if line == "" {
3398 if current.Event != "" || current.ID != "" || len(current.Data) > 0 {
3399 records = append(records, current)
3400 if !requestIDSent {
3401 if payload, ok := extractPermissionPayloadFromRecord(
3402 current,
3403 ); ok && payload.Decision == "" &&
3404 payload.RequestID != "" {
3405 requestIDCh <- payload.RequestID
3406 requestIDSent = true
3407 }
3408 }
3409 }
3410 current = sseRecord{}
3411 continue
3412 }
3413 switch {
3414 case strings.HasPrefix(line, "id: "):
3415 current.ID = strings.TrimPrefix(line, "id: ")
3416 case strings.HasPrefix(line, "event: "):
3417 current.Event = strings.TrimPrefix(line, "event: ")
3418 case strings.HasPrefix(line, "data: "):
3419 current.Data = append(current.Data, []byte(strings.TrimPrefix(line, "data: "))...)
3420 }
3421 }
3422 if current.Event != "" || current.ID != "" || len(current.Data) > 0 {
3423 records = append(records, current)
3424 }
3425 if !requestIDSent {
3426 requestIDCh <- ""
3427 }
3428 if err := scanner.Err(); err != nil {
3429 t.Fatalf("scan prompt SSE error = %v", err)
3430 }
3431 resultCh <- records
3432}
3433
3434func extractPermissionPayloads(t *testing.T, records []sseRecord) []permissionStreamPayload {
3435 t.Helper()

Calls 5

appendFunction · 0.85
CloseMethod · 0.65
ScanMethod · 0.65
ErrMethod · 0.45

Tested by

no test coverage detected