(input, options = {})
| 649 | result: { decision }, |
| 650 | }; |
| 651 | } |
| 652 | return { |
| 653 | id: msg.id, |
| 654 | result: decision, |
| 655 | }; |
| 656 | } |
| 657 | |
| 658 | function verifyAppServerCapture(input, options = {}) { |
| 659 | let messages; |
| 660 | const checks = []; |
| 661 | const add = (id, pass, detail) => checks.push({ id, pass: Boolean(pass), detail }); |
| 662 | |
| 663 | try { |
| 664 | messages = parseAppServerMessages(input); |
| 665 | add('jsonl-readable', true, `${messages.length} message(s)`); |
| 666 | } catch (err) { |
| 667 | add('jsonl-readable', false, err.message); |
| 668 | return { |
| 669 | pass: false, |
| 670 | checks, |
| 671 | summary: summarizeAppServerEvents([]), |
| 672 | }; |
| 673 | } |
| 674 | |
| 675 | const initializeId = Number(options.initializeId || 1); |
| 676 | const threadStartId = Number(options.threadStartId || 2); |
| 677 | const turnStartId = Number(options.turnStartId || 3); |
| 678 | const requireThread = options.requireThread !== false; |
| 679 | const requireTurn = Boolean(options.requireTurn); |
| 680 | const requireTurnCompleted = Boolean(options.requireTurnCompleted); |
| 681 | const requireApproval = Boolean(options.requireApproval); |
| 682 | const initializeResponse = messages.find((msg) => msg.id === initializeId && msg.result); |
| 683 | add( |
| 684 | 'initialize-response', |
| 685 | initializeResponse && (initializeResponse.result.userAgent || initializeResponse.result.platformFamily), |
| 686 | initializeResponse ? 'initialize result received' : `missing response id ${initializeId}`, |
| 687 | ); |
| 688 | |
| 689 | if (requireThread) { |
| 690 | const threadResponse = messages.find((msg) => msg.id === threadStartId && msg.result?.thread?.id); |
| 691 | const threadNotification = messages.find((msg) => msg.method === 'thread/started'); |
| 692 | add( |
| 693 | 'thread-start-response', |
| 694 | threadResponse, |
| 695 | threadResponse ? threadResponse.result.thread.id : `missing response id ${threadStartId}`, |
| 696 | ); |
| 697 | add( |
| 698 | 'thread-started-notification', |
| 699 | threadNotification, |
| 700 | threadNotification ? threadNotification.params?.thread?.id : 'missing thread/started notification', |
| 701 | ); |
| 702 | } |
| 703 | |
| 704 | if (requireTurn) { |
| 705 | const turnResponse = messages.find((msg) => msg.id === turnStartId && !msg.error); |
| 706 | const turnStarted = messages.find((msg) => msg.method === 'turn/started'); |
| 707 | add( |
| 708 | 'turn-start-response', |
no test coverage detected