Skip to content

scorecard example for backend tests#3414

Draft
teknaS47 wants to merge 3 commits into
redhat-developer:mainfrom
teknaS47:ssaikia/RHIDP-14185-startTestBackend-spike
Draft

scorecard example for backend tests#3414
teknaS47 wants to merge 3 commits into
redhat-developer:mainfrom
teknaS47:ssaikia/RHIDP-14185-startTestBackend-spike

Conversation

@teknaS47

@teknaS47 teknaS47 commented Jun 16, 2026

Copy link
Copy Markdown
Member

Hey, I just made a Pull Request!

RHIDP-14185

✔️ Checklist

  • A changeset describing the change and affected packages. (more info)
  • Added or Updated documentation
  • Tests for new functionality and regression tests for bug fixes
  • Screenshots attached (for UI changes)

@github-actions

Copy link
Copy Markdown
Contributor

This pull request adds a new top-level directory under workspaces/. Please follow Submitting a Pull Request for a New Workspace in CONTRIBUTING.md.

@fullsend-ai-review

fullsend-ai-review Bot commented Jun 16, 2026

Copy link
Copy Markdown

🤖 Finished Review · ✅ Success · Started 10:27 AM UTC · Completed 10:35 AM UTC
Commit: e9efe2e · View workflow run →

@codecov

codecov Bot commented Jun 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 50.30%. Comparing base (2903d71) to head (1416b45).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3414      +/-   ##
==========================================
+ Coverage   50.28%   50.30%   +0.02%     
==========================================
  Files        2260     2260              
  Lines       85603    85603              
  Branches    24211    24203       -8     
==========================================
+ Hits        43044    43064      +20     
+ Misses      42058    42038      -20     
  Partials      501      501              
Flag Coverage Δ *Carryforward flag
adoption-insights 83.70% <ø> (ø) Carriedforward from 2903d71
ai-integrations 67.95% <ø> (ø) Carriedforward from 2903d71
app-defaults 69.79% <ø> (ø) Carriedforward from 2903d71
augment 46.39% <ø> (ø) Carriedforward from 2903d71
boost 74.64% <ø> (ø) Carriedforward from 2903d71
bulk-import 72.46% <ø> (ø) Carriedforward from 2903d71
cost-management 14.10% <ø> (ø) Carriedforward from 2903d71
dcm 61.79% <ø> (ø) Carriedforward from 2903d71
extensions 61.53% <ø> (ø) Carriedforward from 2903d71
global-floating-action-button 71.18% <ø> (ø) Carriedforward from 2903d71
global-header 59.71% <ø> (ø) Carriedforward from 2903d71
homepage 49.84% <ø> (ø) Carriedforward from 2903d71
install-dynamic-plugins 56.23% <ø> (ø) Carriedforward from 2903d71
konflux 91.49% <ø> (ø) Carriedforward from 2903d71
lightspeed 68.57% <ø> (ø) Carriedforward from 2903d71
mcp-integrations 85.46% <ø> (ø) Carriedforward from 2903d71
orchestrator 37.79% <ø> (ø) Carriedforward from 2903d71
quickstart 63.76% <ø> (ø) Carriedforward from 2903d71
sandbox 79.56% <ø> (ø) Carriedforward from 2903d71
scorecard 84.58% <ø> (+0.61%) ⬆️
theme 61.26% <ø> (ø) Carriedforward from 2903d71
translations 7.25% <ø> (ø) Carriedforward from 2903d71
x2a 13.78% <ø> (ø) Carriedforward from 2903d71

*This pull request uses carry forward flags. Click here to find out more.


Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2903d71...1416b45. Read the comment docs.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@fullsend-ai-review

fullsend-ai-review Bot commented Jun 16, 2026

Copy link
Copy Markdown

Review

Findings

Low

  • [test-inadequate] workspaces/scorecard/plugins/scorecard-backend/src/plugin.api.test.ts:195 — The entity-level metric tests ('returns metrics for an existing entity' and 'filters entity metrics by metricIds') only assert that the response is an empty array. Because no scheduler has run and no metric values have been written to the in-memory database, these tests exercise the route plumbing and permission checks but never verify that actual metric results are returned correctly. An implementation that unconditionally returned [] for any existing entity would pass.

  • [naming-convention] workspaces/scorecard/plugins/scorecard-backend/src/plugin.api.test.ts:126 — The test file uses res for supertest responses whereas the existing router.test.ts uses response or result.
    Remediation: Rename res to response or result.

  • [api-shape-pattern] workspaces/scorecard/plugins/scorecard-backend/src/plugin.api.test.ts:128 — Uses inline type annotations (m: { id: string }) => m.id instead of importing the domain Metric type as done in router.test.ts.
    Remediation: Import Metric from @red-hat-developer-hub/backstage-plugin-scorecard-common and use (m: Metric) => m.id.

Info

  • [test-inadequate] workspaces/scorecard/plugins/scorecard-backend/src/plugin.api.test.ts:265 — The KPI-config describe block does not pass any entities to startScorecardBackend, so the catalog mock has zero entities. Currently only metadata tests exist so nothing breaks, but future contributors adding data-path tests in this block may not realize the catalog is empty.

  • [label-inconsistency] workspaces/scorecard/plugins/scorecard-backend/src/plugin.api.test.ts — The PR carries both do-not-merge/work-in-progress and ready-for-merge labels simultaneously, which are contradictory. None of the PR checklist items are checked.

  • [code-organization] workspaces/scorecard/plugins/scorecard-backend/src/plugin.api.test.ts:16 — Blank line between the license header and first import. Other test files in this directory have no blank line there.

  • [code-organization] workspaces/scorecard/plugins/scorecard-backend/src/plugin.api.test.ts — This is the first test in the scorecard-backend package to use startTestBackend for integration-style testing. Other API-level tests use the unit-test pattern of manually constructing dependencies and calling createRouter directly. Worth being intentional about when each style should be used.

Previous run

Review

Findings

Low

  • [test-integrity] workspaces/scorecard/plugins/scorecard-backend/src/plugin.integration.test.ts:65 — The afterAll hook calls server.close() without awaiting or handling its callback. http.Server.close() does not return a promise, so connections may still be draining when Jest proceeds. This can cause "open handle" warnings or flaky teardown. The same pattern appears at line 155. Note: other test files in this repo using startTestBackend do not call server.close() at all, so the risk is minimal in this context.

  • [test-adequacy] workspaces/scorecard/plugins/scorecard-backend/src/plugin.integration.test.ts:139 — The KPI config test defines type: 'statusGrouped' and asserts aggregationType: 'statusGrouped', but this is also the default value (see mappers.ts:55 and AggregationService.ts:66). The assertion passes regardless of whether the config-driven path or the fallback is taken. Testing with a non-default type (e.g., 'average') would provide stronger assurance that config values flow through correctly. Not a bug — a coverage gap.

Info

  • [sub-agent-failure] The style-conventions sub-agent did not return findings: model claude-sonnet-4-5@20250929 not available on deployment.

  • [sub-agent-failure] The intent-coherence sub-agent did not return findings: model claude-sonnet-4-5@20250929 not available on deployment.

const BASE_CONFIG = {
backend: {
database: {
client: 'better-sqlite3',

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[low] test-integrity

The afterAll hook calls server.close() without awaiting or handling its callback. http.Server.close() does not return a promise, so connections may still be draining when Jest proceeds. This can cause open handle warnings or flaky teardown. The same pattern appears at line 155.

'/api/scorecard/metrics?metricIds=sonar.quality&datasource=github',
);

expect(res.status).toBe(400);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[low] test-adequacy

The KPI config test defines type statusGrouped and asserts aggregationType statusGrouped, but this is also the default value. The assertion passes regardless of whether the config-driven path or the fallback is taken. Testing with a non-default type would provide stronger assurance.

@fullsend-ai-review fullsend-ai-review Bot added the ready-for-merge All reviewers approved — ready to merge label Jun 16, 2026

@christoph-jerolimov christoph-jerolimov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome @teknaS47 👍

Small things:

Comment thread workspaces/scorecard/plugins/scorecard-backend/package.json Outdated
@sonarqubecloud

Copy link
Copy Markdown

@fullsend-ai-review

fullsend-ai-review Bot commented Jun 22, 2026

Copy link
Copy Markdown

🤖 Finished Review · ✅ Success · Started 2:28 PM UTC · Completed 2:40 PM UTC
Commit: 2903d71 · View workflow run →

const res = await request(server).get(
'/api/scorecard/aggregations/non.existent/metadata',
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[low] test-inadequate

The entity-level metric tests only assert that the response is an empty array. These tests exercise route plumbing but never verify that actual metric results are returned correctly.

it('returns all registered metrics', async () => {
const res = await request(server).get('/api/scorecard/metrics');

expect(res.status).toBe(200);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[low] naming-convention

The test file uses res for supertest responses whereas existing router.test.ts uses response or result.

Suggested fix: Rename res to response or result.


expect(res.status).toBe(200);
expect(res.body.metrics).toHaveLength(3);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[low] api-shape-pattern

Uses inline type annotations (m: { id: string }) => m.id instead of importing the domain Metric type as done in router.test.ts.

Suggested fix: Import Metric from @red-hat-developer-hub/backstage-plugin-scorecard-common and use (m: Metric) => m.id.


expect(res.status).toBe(401);
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[info] test-inadequate

The KPI-config describe block does not pass any entities to startScorecardBackend. Currently only metadata tests exist so nothing breaks.

* See the License for the specific language governing permissions and
* limitations under the License.
*/

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[info] code-organization

Blank line between the license header and first import. Other test files have no blank line there.

@fullsend-ai-review fullsend-ai-review Bot added ready-for-merge All reviewers approved — ready to merge and removed ready-for-merge All reviewers approved — ready to merge labels Jun 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants