Skip to content

CLI-289 Coverage experiment: sonar ping command covered by integration tests#173

Draft
kirill-knize-sonarsource wants to merge 1 commit intomasterfrom
task/kk/coverage-investigation
Draft

CLI-289 Coverage experiment: sonar ping command covered by integration tests#173
kirill-knize-sonarsource wants to merge 1 commit intomasterfrom
task/kk/coverage-investigation

Conversation

@kirill-knize-sonarsource
Copy link
Copy Markdown
Member

No description provided.

@kirill-knize-sonarsource kirill-knize-sonarsource marked this pull request as draft April 13, 2026 09:13
@sonar-review-alpha
Copy link
Copy Markdown
Contributor

sonar-review-alpha bot commented Apr 13, 2026

Summary

This PR adds a new sonar ping command that checks connectivity to the configured SonarQube server. The command fetches and displays the server's status (UP/DOWN) and version information, with support for both human-readable text and JSON output formats. The feature is fully covered by integration tests, which validate authentication requirements, text output formatting, and JSON serialization.

What reviewers should know

Files to review:

  1. Start with src/cli/commands/ping/index.ts — the command implementation is straightforward; it creates a SonarQubeClient, calls getSystemStatus(), and formats output based on the --json flag.
  2. Check src/cli/command-tree.ts — only a small addition registering the ping command with authenticatedAction (requires valid auth).
  3. Review integration tests in tests/integration/specs/ping/ping.test.ts — three scenarios: missing auth, text output, and JSON output.

Note on test coverage: This PR is labeled a "coverage experiment" and includes integration tests only. The command has no unit tests — validation happens through the full integration test harness with a fake SonarQube server.


  • Generate Walkthrough
  • Generate Diagram

🗣️ Give feedback

@hashicorp-vault-sonar-prod hashicorp-vault-sonar-prod bot changed the title Coverage experiment: sonar ping command covered by integration tests CLI-289 Coverage experiment: sonar ping command covered by integration tests Apr 13, 2026
@hashicorp-vault-sonar-prod
Copy link
Copy Markdown

hashicorp-vault-sonar-prod bot commented Apr 13, 2026

CLI-289

@sonarqubecloud
Copy link
Copy Markdown

Copy link
Copy Markdown
Contributor

@sonar-review-alpha sonar-review-alpha bot left a comment

Choose a reason for hiding this comment

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

Clean implementation overall, but there's one real bug: the ping command will fail or produce misleading output for SonarQube Cloud users.

🗣️ Give feedback

Comment on lines +30 to +31
const client = new SonarQubeClient(auth.serverUrl, auth.token);
const status = await client.getSystemStatus();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Bug: getSystemStatus() calls /api/system/status, which is a SonarQube Server endpoint. The login.ts command explicitly guards against calling it on cloud connections (else if (!isCloud)) for the same reason.

ResolvedAuth already carries auth.connectionType: 'cloud' | 'on-premise', so the fix is straightforward — either reject cloud connections with a clear error, or query a cloud-appropriate endpoint instead.

Suggested change
const client = new SonarQubeClient(auth.serverUrl, auth.token);
const status = await client.getSystemStatus();
if (auth.connectionType === 'cloud') {
throw new CommandFailedError(
'sonar ping is not supported for SonarQube Cloud connections.',
);
}
const client = new SonarQubeClient(auth.serverUrl, auth.token);
const status = await client.getSystemStatus();
  • Mark as noise

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant