Skip to content

feat(cli): add sorokeep doctor environment/connectivity diagnostics - #662

Merged
AbdulmalikAlayande merged 3 commits into
TegoLabs:mainfrom
Primex-Tech:feat/doctor-diagnostics
Aug 7, 2026
Merged

AbdulmalikAlayande merged 3 commits into
TegoLabs:mainfrom
Primex-Tech:feat/doctor-diagnostics

Conversation

@Primex-Tech

@Primex-Tech Primex-Tech commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor

Replaces the closed #371 with a clean, single-feature diff rebuilt from the latest upstream main.

Summary

Adds a \sorokeep doctor\ command that runs environment and connectivity diagnostics for the local Sorokeep installation (config dir, database, RPC connectivity, alert channels).

Changes

  • \src/commands/doctor.ts: \sorokeep doctor\ command
  • \src/core/doctor.ts: diagnostics core logic
  • \src/cli/program.ts: register the \doctor\ command
  • \ ests/commands/doctor.test.ts, \ ests/core/doctor.test.ts: unit tests

Verification

  • \ sc --noEmit: clean
  • \eslint\ on changed files: 0 errors
  • \�itest run tests/commands/doctor.test.ts tests/core/doctor.test.ts: 5 tests passed

@coderabbitai

coderabbitai Bot commented Aug 3, 2026 •

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@Primex-Tech, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 24 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 7e54ae93-03e2-45a1-aa5d-4c87e8c28ed1

📥 Commits

Reviewing files that changed from the base of the PR and between 8bdf266 and 3765cb2.

📒 Files selected for processing (2)
  • src/core/doctor.ts
  • tests/core/doctor.test.ts
📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Added a doctor CLI command for checking local application health.
    • Reports color-coded PASS, WARN, and FAIL results for runtime, storage, database, alert credentials, and RPC connectivity.
    • Returns a failing exit status when critical diagnostics fail.
  • Bug Fixes

    • Diagnostics continue running and report available results even when individual checks encounter errors.
  • Tests

    • Added coverage for command exit statuses and diagnostic failure and warning scenarios.

Walkthrough

The PR adds a doctor CLI command. It runs Node.js, data-directory, database, alert-credential, and Stellar RPC checks. It prints status results and sets a failing exit code when a check fails.

Changes

Doctor diagnostics

Layer / File(s) Summary
Diagnostic checks
src/core/doctor.ts, tests/core/doctor.test.ts
Adds structured diagnostic results for Node.js, filesystem, database schema, alert credentials, and Stellar RPC reachability. Tests cover RPC failures, missing credentials, and database errors.
CLI command integration
src/commands/doctor.ts, src/cli/program.ts, tests/commands/doctor.test.ts
Registers the doctor command, formats results by status, and sets process.exitCode to 1 only when a diagnostic fails. Tests cover fail, pass, and warning outcomes.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CLI
  participant DoctorCommand
  participant runDiagnostics
  participant Database
  participant StellarRpcClient
  CLI->>DoctorCommand: Invoke doctor
  DoctorCommand->>runDiagnostics: Run checks
  runDiagnostics->>Database: Check schema and alert configuration
  Database-->>runDiagnostics: Return database results
  runDiagnostics->>StellarRpcClient: Check RPC reachability
  StellarRpcClient-->>runDiagnostics: Return RPC result
  runDiagnostics-->>DoctorCommand: Return diagnostic results
  DoctorCommand-->>CLI: Print statuses and set exit code
Loading

Possibly related PRs

Suggested reviewers: abdulmalikalayande

Poem

I checked each path beneath the moon,
And asked the RPC stars to tune.
Green checks hop, yellow warnings glow,
Red failures tell us what to know.
The Doctor’s ready—off we go!

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR covers the required diagnostics, but it does not show a schema_migrations currency comparison required by [#371]. Compare applied migrations with the current migration set and add a stale-schema test.
Out of Scope Changes check ⚠️ Warning The PR edits src/cli/program.ts, while [#371] permits command registration only in src/index.ts. Confirm the correct entry point, then update the issue scope or move registration to the permitted file.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the new Sorokeep doctor diagnostics command.
Description check ✅ Passed The description accurately summarizes the doctor command, diagnostics, registration, tests, and verification.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Primex-Tech

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 3, 2026 •

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@Primex-hub

Copy link
Copy Markdown

Replaces the closed PR #371 with a clean, single-feature diff rebuilt from the latest upstream main.

Summary

Adds a \sorokeep doctor\ command that runs environment and connectivity diagnostics for the local Sorokeep installation (config dir, database, RPC connectivity, alert channels).

Changes

  • \src/commands/doctor.ts: \sorokeep doctor\ command
  • \src/core/doctor.ts: diagnostics core logic
  • \src/cli/program.ts: register the \doctor\ command
  • \ ests/commands/doctor.test.ts, \ ests/core/doctor.test.ts: unit tests

Verification

  • \ sc --noEmit: clean
  • \eslint\ on changed files: 0 errors
  • \�itest run tests/commands/doctor.test.ts tests/core/doctor.test.ts: 5 tests passed

2 similar comments
@Primex-hub

Copy link
Copy Markdown

Replaces the closed PR #371 with a clean, single-feature diff rebuilt from the latest upstream main.

Summary

Adds a \sorokeep doctor\ command that runs environment and connectivity diagnostics for the local Sorokeep installation (config dir, database, RPC connectivity, alert channels).

Changes

  • \src/commands/doctor.ts: \sorokeep doctor\ command
  • \src/core/doctor.ts: diagnostics core logic
  • \src/cli/program.ts: register the \doctor\ command
  • \ ests/commands/doctor.test.ts, \ ests/core/doctor.test.ts: unit tests

Verification

  • \ sc --noEmit: clean
  • \eslint\ on changed files: 0 errors
  • \�itest run tests/commands/doctor.test.ts tests/core/doctor.test.ts: 5 tests passed

@Primex-hub

Copy link
Copy Markdown

Replaces the closed PR #371 with a clean, single-feature diff rebuilt from the latest upstream main.

Summary

Adds a \sorokeep doctor\ command that runs environment and connectivity diagnostics for the local Sorokeep installation (config dir, database, RPC connectivity, alert channels).

Changes

  • \src/commands/doctor.ts: \sorokeep doctor\ command
  • \src/core/doctor.ts: diagnostics core logic
  • \src/cli/program.ts: register the \doctor\ command
  • \ ests/commands/doctor.test.ts, \ ests/core/doctor.test.ts: unit tests

Verification

  • \ sc --noEmit: clean
  • \eslint\ on changed files: 0 errors
  • \�itest run tests/commands/doctor.test.ts tests/core/doctor.test.ts: 5 tests passed

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/core/doctor.ts`:
- Around line 39-42: Update the dataDir validation near fs.accessSync to also
verify that the path is a directory, not merely writable; use the existing
filesystem APIs to inspect dataDir and preserve the current creation and
writable-access checks.
- Around line 57-73: The schema diagnostic around getDatabase() must inspect the
database through a non-migrating connection before migrations run, rather than
using getDatabase(), and validate migration metadata plus required
tables/columns or other expected schema objects instead of only checking
contracts. Preserve the existing pass/fail result structure, and add a
regression test proving an outdated schema is reported as failed.
- Around line 121-123: Update the health-check flow around
StellarRpcClient.checkHealth() to enforce a bounded diagnostic timeout, since
the SDK call cannot reliably accept an AbortSignal. Configure the SDK server
timeout if supported by the client, or wrap the await with a timeout that allows
the existing failure path to report “rpc reachability: FAIL” before returning.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 5e3d3797-6de8-4ce3-82e0-6b0357e015ff

📥 Commits

Reviewing files that changed from the base of the PR and between 833394c and 8bdf266.

📒 Files selected for processing (5)
  • src/cli/program.ts
  • src/commands/doctor.ts
  • src/core/doctor.ts
  • tests/commands/doctor.test.ts
  • tests/core/doctor.test.ts
📜 Review details
⏰ Context from checks skipped due to timeout. (2)
  • GitHub Check: build-and-test (24.x)
  • GitHub Check: build-and-test (22.x)
🔇 Additional comments (4)
tests/core/doctor.test.ts (1)

36-113: LGTM!

src/commands/doctor.ts (1)

5-26: LGTM!

src/cli/program.ts (1)

23-23: LGTM!

Also applies to: 105-105

tests/commands/doctor.test.ts (1)

14-54: LGTM!

Comment thread src/core/doctor.ts
Comment thread src/core/doctor.ts Outdated
Comment thread src/core/doctor.ts Outdated
Comment on lines +121 to +123
try {
const client = new StellarRpcClient("testnet");
await client.checkHealth();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🌐 Web query:

For @stellar/stellar-sdk version 16.2.0, what timeout or AbortSignal API does rpc.Server.getHealth support?

💡 Result:

For @stellar/stellar-sdk version 16.2.0, the rpc.Server.getHealth method does not accept or support an AbortSignal API for timeout control [1][2]. Connection timeouts in the @stellar/stellar-sdk are managed exclusively through the timeout property defined in the Options interface when instantiating the rpc.Server [1][3]. This timeout option is a numeric value representing milliseconds, where a value of 0 indicates no timeout [1][3]. While you can configure this timeout on a per-server basis during initialization, the SDK does not provide a mechanism to pass an AbortSignal to individual method calls like getHealth [1][2]. Additionally, the SDK supports a global timeout configuration via the Config.setTimeout(value) method, which affects all SDK components unless overridden by the per-server setting [4][3].

Citations:


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Locate and inspect relevant files without executing repository code.
printf 'Tracked files matching doctor.ts:\n'
git ls-files | grep -E '(^|/)doctor\.ts$' || true

printf '\ndiff stat:\n'
git diff --stat || true

printf '\npackage manifests mentioning stellar-sdk:\n'
for f in package.json */package.json package-lock.json */package-lock.json pnpm-lock.yaml yarn.lock; do
  [ -f "$f" ] && { echo "--- $f"; grep -n "`@stellar/stellar-sdk`\|stellar-sdk" "$f" || true; }
done

printf '\nurllib? No, read nearby source:\n'
file="$(git ls-files | grep '(^|/)src/core/doctor\.ts$' | head -n 1)"
if [ -n "${file:-}" ]; then
  wc -l "$file"
  sed -n '1,180p' "$file" | cat -n
fi

printf '\nSearch StellarRpcClient usages/definition:\n'
rg -n "class StellarRpcClient|new StellarRpcClient|checkHealth|timeout" . --glob '!node_modules' --glob '!dist' --glob '!build' || true

Repository: AbdulmalikAlayande/sorokeep

Length of output: 676


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf 'Tracked doctor files:\n'
git ls-files | grep -E '(^|/)doctor\.ts$' || true

printf '\npackage manifests mentioning stellar-sdk:\n'
for f in package.json package-lock.json; do
  if [ -f "$f" ]; then
    echo "--- $f"
    grep -n "`@stellar/stellar-sdk`\|stellar-sdk" "$f" || true
  fi
done

printf '\nInspect src/core/doctor.ts:\n'
wc -l src/core/doctor.ts
cat -n src/core/doctor.ts | sed -n '1,180p'

printf '\nInspects src/commands/doctor.ts:\n'
wc -l src/commands/doctor.ts
cat -n src/commands/doctor.ts | sed -n '1,180p'

printf '\nSearch StellarRpcClient and timeout usage:\n'
rg -n "class StellarRpcClient|new StellarRpcClient|StellarRpcClient|checkHealth|\\.timeout|timeout\\s*:" . --glob '!node_modules' --glob '!dist' --glob '!build' --glob '!package-lock.json' || true

Repository: AbdulmalikAlayande/sorokeep

Length of output: 19498


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf 'Inspect src/rpc/client.ts focus:\n'
wc -l src/rpc/client.ts
cat -n src/rpc/client.ts | sed -n '240,320p'

printf '\nInspect tests around StellarRpcClient health/timeout:\n'
cat -n tests/rpc/client.test.ts | sed -n '166,220p'

printf '\nBehavioral probe: parse source for StellerRpcClient constructor/health options:\n'
python3 - <<'PY'
from pathlib import Path
import re

src = Path("src/rpc/client.ts").read_text()
m = re.search(r"class StellarRpcClient[\s\S]*?\n}", src)
body = m.group(0) if m else ""
print(body[-2400:])
PY

Repository: AbdulmalikAlayande/sorokeep

Length of output: 9247


Set a deadline on StellarRpcClient.getHealth().

client.checkHealth() delegates to rpc.Server.getHealth() without a bounded client timeout, and @stellar/stellar-sdk 16.2.0 does not support pass-through AbortSignal cancellation for this call. A stalled DNS lookup or socket can leave sorokeep doctor pending before it can write the rpc reachability: FAIL result. Pass an SDK-configured server timeout or wrap client.checkHealth() with a diagnostic timeout.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/core/doctor.ts` around lines 121 - 123, Update the health-check flow
around StellarRpcClient.checkHealth() to enforce a bounded diagnostic timeout,
since the SDK call cannot reliably accept an AbortSignal. Configure the SDK
server timeout if supported by the client, or wrap the await with a timeout that
allows the existing failure path to report “rpc reachability: FAIL” before
returning.

- validate the data directory is a directory, not merely writable
- inspect the database schema on a read-only non-migrating connection so an
  outdated/missing schema is reported instead of silently repaired
- bound the RPC health check with a timeout so a stalled connection cannot
  hang 'sorokeep doctor'
- add regression tests for outdated schema, uninitialized database,
  non-directory data path, and credential check skip
@Primex-Tech

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 6, 2026 •

Copy link
Copy Markdown
⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@AbdulmalikAlayande
AbdulmalikAlayande merged commit 3765cb2 into TegoLabs:main Aug 7, 2026
5 checks passed
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.

feat(cli): add a 'sorokeep doctor' environment/connectivity diagnostic command

3 participants