feat(#3474): add code-coverage module for scorecard#3476
feat(#3474): add code-coverage module for scorecard#3476fullsend-ai-coder[bot] wants to merge 1 commit into
Conversation
Create a new scorecard-backend-module-code-coverage that integrates with the Backstage Community code-coverage plugin to provide 8 metrics: line/branch percentage, available, covered, and missed counts. The module fetches data from the code-coverage-backend API using the Backstage discovery service and maps the aggregate line and branch fields to individual MetricProviders. Entities are filtered by the backstage.io/code-coverage annotation. Percentage metrics include default thresholds (>80 success, 50-80 warning, <50 error). Includes: - CodeCoverageClient for API communication - Type definitions for the code-coverage API response - 8 MetricProvider implementations via factory pattern - Unit tests for client, providers, and factory (28 tests) - Example entity with code-coverage annotation - Backend app integration Closes #3474
Missing ChangesetsThe following package(s) are changed by this PR but do not have a changeset:
See CONTRIBUTING.md for more information about how to add changesets. Changed Packages
|
|
|
|
🤖 Finished Review · ✅ Success · Started 1:30 PM UTC · Completed 1:42 PM UTC |
ReviewFindingsMedium
Low
Info
|
| if (!response.ok) { | ||
| throw new Error( | ||
| `Code coverage API error: ${response.status} ${response.statusText} for ${url}`, | ||
| ); |
There was a problem hiding this comment.
[medium] Missing service-to-service authentication
The client uses bare fetch() without Backstage service-to-service authentication tokens. The code-coverage API is an internal Backstage plugin discovered via DiscoveryService.
Suggested fix: Inject AuthService (from coreServices.auth) into the client. Before each fetch, call auth.getPluginRequestToken() and pass the token as a Bearer header.
| type: this.getMetricType(), | ||
| history: true, | ||
| }; | ||
| } |
There was a problem hiding this comment.
[low] edge-case
The calculateMetric method accesses report.aggregate[mapping.section][mapping.field] without null checks.
| }); | ||
| }); | ||
|
|
||
| describe('getCatalogFilter', () => { |
There was a problem hiding this comment.
[low] missing-test
No test case for calculateMetric when the API returns a report with missing or null aggregate section data.
| it('should call the correct URL and return the report', async () => { | ||
| jest.spyOn(global, 'fetch').mockResolvedValueOnce({ | ||
| ok: true, | ||
| json: async () => sampleReport, |
There was a problem hiding this comment.
[low] test-inadequate
The error-case test does not verify the URL is included in the error message due to substring matching.
| * Creates a single code-coverage metric provider for the given metric ID. | ||
| */ | ||
| export function createCodeCoverageMetricProvider( | ||
| discovery: DiscoveryService, |
There was a problem hiding this comment.
[info] logic-error
Creates a new CodeCoverageClient instance for each of the 8 metric providers, causing 8x API calls per entity.
| if (!response.ok) { | ||
| throw new Error( | ||
| `Code coverage API error: ${response.status} ${response.statusText} for ${url}`, | ||
| ); |
There was a problem hiding this comment.
[info] data-exposure
Error message includes the full internal URL. Consistent with existing patterns.
| ); | ||
| } | ||
| return response.json() as Promise<CodeCoverageReport>; | ||
| } |
There was a problem hiding this comment.
[info] No response body validation
JSON response cast directly to CodeCoverageReport without runtime validation. Consistent with other modules.



Create a new scorecard-backend-module-code-coverage that integrates with the Backstage Community code-coverage plugin to provide 8 metrics: line/branch percentage, available, covered, and missed counts.
The module fetches data from the code-coverage-backend API using the Backstage discovery service and maps the aggregate line and branch fields to individual MetricProviders.
Entities are filtered by the backstage.io/code-coverage annotation. Percentage metrics include default thresholds (>80 success, 50-80 warning, <50 error).
Includes:
Closes #3474
Post-script verification
agent/3474-code-coverage-module)7ccaff17753df64c7ab288cdcba34cee5a657254..HEAD)