(t *testing.T, body io.ReadCloser, requestIDCh chan<- string, resultCh chan<- []sseRecord)
| 3382 | } |
| 3383 | |
| 3384 | func 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 | |
| 3434 | func extractPermissionPayloads(t *testing.T, records []sseRecord) []permissionStreamPayload { |
| 3435 | t.Helper() |
no test coverage detected