(payload: unknown)
| 617 | |
| 618 | /** Eine rohe `check_index_coverage`-Antwort lesen. */ |
| 619 | export function readCoverageAnswer(payload: unknown): CoverageAnswer { |
| 620 | const raw = isRecord(payload) ? payload : {}; |
| 621 | const meta = isRecord(raw['metadata']) ? raw['metadata'] : {}; |
| 622 | |
| 623 | const paths: CoveragePathAnswer[] = []; |
| 624 | for (const entry of coverageArray(raw['paths'])) { |
| 625 | if (!isRecord(entry)) { |
| 626 | continue; |
| 627 | } |
| 628 | paths.push({ |
| 629 | requestedPath: coverageString(entry['requested_path']), |
| 630 | path: normalizeCoveragePath(coverageString(entry['path'])), |
| 631 | status: coverageString(entry['status']), |
| 632 | freshness: coverageString(entry['freshness']), |
| 633 | recommendedAction: coverageString(entry['recommended_action']), |
| 634 | coverage: readCoverageRows(entry['coverage']), |
| 635 | }); |
| 636 | } |
| 637 | |
| 638 | const scopes: CoverageScope[] = []; |
| 639 | const rawScopes = coverageArray(raw['scopes']); |
| 640 | for (const entry of rawScopes) { |
| 641 | if (!isRecord(entry)) { |
| 642 | continue; |
| 643 | } |
| 644 | const scope: CoverageScope = { |
| 645 | requestedScope: coverageString(entry['requested_scope']), |
| 646 | scope: coverageString(entry['scope']), |
| 647 | status: coverageString(entry['status']), |
| 648 | total: asNumber(entry['total']), |
| 649 | // Production reports continuation on the response envelope. A |
| 650 | // scope's `truncated` also remains true on its final partial page, |
| 651 | // so that flag cannot determine whether another page is needed. |
| 652 | hasMore: typeof entry['has_more'] === 'boolean' ? entry['has_more'] |
| 653 | : rawScopes.length === 1 && raw['has_more'] === true, |
| 654 | entries: readCoverageRows(entry['entries']), |
| 655 | }; |
| 656 | if (entry['next_offset'] !== undefined) { |
| 657 | scope.nextOffset = asNumber(entry['next_offset']); |
| 658 | } else if (rawScopes.length === 1 && raw['next_offset'] !== undefined) { |
| 659 | scope.nextOffset = asNumber(raw['next_offset']); |
| 660 | } |
| 661 | scopes.push(scope); |
| 662 | } |
| 663 | |
| 664 | return { |
| 665 | project: coverageString(raw['project']), |
| 666 | metadata: { |
| 667 | generation: coverageString(meta['generation']), |
| 668 | indexMode: coverageString(meta['index_mode']), |
| 669 | recordedAt: coverageString(meta['recorded_at']), |
| 670 | recordingStatus: coverageString(meta['recording_status']), |
| 671 | ignoredFilesStored: asNumber(meta['ignored_files_stored']), |
| 672 | ignoredFilesTotal: asNumber(meta['ignored_files_total']), |
| 673 | hashRecordsComplete: meta['hash_records_complete'] === true, |
| 674 | coverageVersion: asNumber(meta['coverage_version']), |
| 675 | generationMatches: meta['generation_matches'] === true, |
| 676 | }, |
no test coverage detected