Skip to content

test(cli): add tests for alerts test command - #281

Merged
AbdulmalikAlayande merged 1 commit into
TegoLabs:mainfrom
Tijesunimi004:feat/alerts-test-command
Jun 30, 2026
Merged

AbdulmalikAlayande merged 1 commit into
TegoLabs:mainfrom
Tijesunimi004:feat/alerts-test-command

Conversation

@Tijesunimi004

Copy link
Copy Markdown
Contributor

Closes #124.

What changed

Added unit tests for the alerts test subcommand in tests/commands/alerts.test.ts.

The implementation (src/commands/alerts.ts) was already present; this PR adds the test coverage required by the issue.

Tests added

  • Dispatcher is called with the correct channel type, target, and threshold_crossed event
  • Event fields are valid (type, timestamp, configuredLedgers, remainingTTL > 0)
  • Success path prints confirmation message
  • Delivery failure exits with code 1 and prints an error
  • Missing config ID exits with code 1 without calling the dispatcher
  • Non-numeric --id exits with code 1 without calling the dispatcher
  • Webhook secret is passed through to the dispatcher
  • Slack channel target is routed correctly

Cover the 'alerts test' subcommand with unit tests:
- dispatcher is invoked with correct channel type, target, and event
- test message delivered to webhook and Slack channels
- webhook secret passed through to dispatcher
- exits with code 1 on delivery failure
- exits with code 1 when config ID is not found or not numeric
Copilot AI review requested due to automatic review settings June 28, 2026 18:36

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Jun 28, 2026 •

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Summary by CodeRabbit

  • Tests
    • Expanded coverage for the alerts test command, including success and failure paths.
    • Verified alert delivery behavior for webhook and Slack configurations, including payload details and logging.
    • Added checks for invalid or missing alert IDs to ensure the command exits cleanly without sending alerts.

Walkthrough

Adds a Vitest mock for deliverSingleAlert and a new describe("alerts test") block in the alerts test file. The suite covers the alerts test --id CLI command: dispatcher call arguments, success/failure logging, process.exit(1) on failure, input validation (missing/non-numeric id), webhook_secret passthrough, and Slack delivery.

alerts test command coverage

Layer / File(s) Summary
Dispatcher mock
tests/commands/alerts.test.ts
Adds a Vitest module mock routing deliverSingleAlert to a local spy, enabling call assertions and return value control across all test cases.
alerts test suite: setup and cases
tests/commands/alerts.test.ts
Introduces describe("alerts test") with beforeEach that resets the mock and inserts a webhook config fixture, then adds cases for correct dispatcher arguments, success logging, failure logging with process.exit(1), unknown id error, non-numeric --id rejection, webhook_secret passthrough, and Slack delivery success.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 Hop hop, the tests now run,
A mock dispatcher, oh what fun!
Webhook secrets passed with care,
Slack and thresholds fill the air.
When delivery fails, exit with one—
The rabbit checks until it's done! 🌟

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the change: added tests for the alerts test command.
Description check ✅ Passed The description accurately describes the added tests and their coverage for the alerts test subcommand.
Linked Issues check ✅ Passed The tests cover the command flow, dispatcher invocation, Slack/webhook routing, and failure cases requested by #124.
Out of Scope Changes check ✅ Passed The changes stay focused on adding tests for the alerts test command and do not introduce unrelated code.
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.

@drips-wave

drips-wave Bot commented Jun 28, 2026

Copy link
Copy Markdown

@Tijesunimi004 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@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: 1

🤖 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 `@tests/commands/alerts.test.ts`:
- Around line 297-298: The timestamp check in the alerts test is not actually
validating the value because `new Date(event.timestamp)` can succeed for invalid
strings. Update the assertion in the test around `event.timestamp` to use a real
parseability/validity check instead, and keep the existing `typeof
event.timestamp` guard so the test verifies the timestamp produced by the alert
event is truly valid.
🪄 Autofix (Beta)

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: 8a0fd8ec-e5e3-4920-9c1c-7e729cea7b05

📥 Commits

Reviewing files that changed from the base of the PR and between 16f8968 and bf0ed4c.

📒 Files selected for processing (1)
  • tests/commands/alerts.test.ts
📜 Review details
🔇 Additional comments (1)
tests/commands/alerts.test.ts (1)

10-15: LGTM!

Also applies to: 250-282, 303-427

Comment on lines +297 to +298
expect(typeof event.timestamp).toBe("string");
expect(() => new Date(event.timestamp)).not.toThrow();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Make the timestamp assertion actually validate the value
new Date(event.timestamp) never throws for malformed strings, so this can pass with an invalid timestamp. Use a parseability check instead.

🤖 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 `@tests/commands/alerts.test.ts` around lines 297 - 298, The timestamp check in
the alerts test is not actually validating the value because `new
Date(event.timestamp)` can succeed for invalid strings. Update the assertion in
the test around `event.timestamp` to use a real parseability/validity check
instead, and keep the existing `typeof event.timestamp` guard so the test
verifies the timestamp produced by the alert event is truly valid.

@gitguardian

gitguardian Bot commented Jun 29, 2026 •

Copy link
Copy Markdown

⚠️ GitGuardian has uncovered 6 secrets following the scan of your pull request.

Please consider investigating the findings and remediating the incidents. Failure to do so may lead to compromising the associated services or software components.

Since your pull request originates from a forked repository, GitGuardian is not able to associate the secrets uncovered with secret incidents on your GitGuardian dashboard.
Skipping this check run and merging your pull request will create secret incidents on your GitGuardian dashboard.

🔎 Detected hardcoded secrets in your pull request
GitGuardian id GitGuardian status Secret Commit Filename
- - Generic High Entropy Secret 3dd17ce tests/core/vault.test.ts View secret
- - Generic High Entropy Secret 3dd17ce tests/core/vault.test.ts View secret
- - Generic High Entropy Secret 3dd17ce tests/core/vault.test.ts View secret
- - Generic High Entropy Secret b59bef4 tests/core/vault.test.ts View secret
- - Generic High Entropy Secret b59bef4 tests/core/vault.test.ts View secret
- - Generic High Entropy Secret b59bef4 tests/core/vault.test.ts View secret
🛠 Guidelines to remediate hardcoded secrets
  1. Understand the implications of revoking this secret by investigating where it is used in your code.
  2. Replace and store your secrets safely. Learn here the best practices.
  3. Revoke and rotate these secrets.
  4. If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.

To avoid such incidents in the future consider


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

@AbdulmalikAlayande
AbdulmalikAlayande merged commit c6f8f3c into TegoLabs:main Jun 30, 2026
3 checks passed
AbdulmalikAlayande pushed a commit that referenced this pull request Aug 2, 2026
Cover the 'alerts test' subcommand with unit tests:
- dispatcher is invoked with correct channel type, target, and event
- test message delivered to webhook and Slack channels
- webhook secret passed through to dispatcher
- exits with code 1 on delivery failure
- exits with code 1 when config ID is not found or not numeric
AbdulmalikAlayande pushed a commit that referenced this pull request Aug 2, 2026
Cover the 'alerts test' subcommand with unit tests:
- dispatcher is invoked with correct channel type, target, and event
- test message delivered to webhook and Slack channels
- webhook secret passed through to dispatcher
- exits with code 1 on delivery failure
- exits with code 1 when config ID is not found or not numeric
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 alert verification test command

3 participants