Skip to content

chore: improve tests for better coverage and increase reliability#27

Merged
endalk200 merged 1 commit intomainfrom
chore-improve-tests
Feb 7, 2026
Merged

chore: improve tests for better coverage and increase reliability#27
endalk200 merged 1 commit intomainfrom
chore-improve-tests

Conversation

@endalk200
Copy link
Owner

@endalk200 endalk200 commented Feb 7, 2026

Greptile Overview

Greptile Summary

Enhanced test suite with 408 lines of new tests across 6 packages to improve coverage and reliability. Key improvements include proper environment variable cleanup with try-finally blocks, error handler resilience testing, payload extraction validation, observer immutability verification, and edge case handling for signature verification and stats tracking.

Key Test Additions

  • Environment variable isolation: Added proper cleanup in packages/core/src/index.test.ts:765-792 using try-finally to prevent test pollution (addresses previous review comment about env leakage)
  • Error handler resilience: Tests verify that exceptions in onError and onVerificationFailed handlers don't break the webhook processing flow
  • Payload extraction: Validates that getPayload() correctly extracts nested payloads and merges nonce values for idempotency
  • Observer immutability: Ensures adapter functions (toExpress, toGCPFunction, toNextJS) don't mutate the original webhook instance
  • Schema validation: Added tests for GitHub installation events and Ragie partition limit events
  • Edge cases: Base64 signature length mismatch, unknown event type stats tracking, missing event type in envelope, and accidental sha256= prefix in secrets

Confidence Score: 5/5

  • This PR is safe to merge with no concerns
  • All changes are test-only additions that improve coverage and reliability. The new tests properly handle cleanup, test edge cases, and verify correct behavior. Notably, the environment variable cleanup issue from the previous review has been addressed with proper try-finally blocks. No production code changes mean zero risk to existing functionality.
  • No files require special attention

Important Files Changed

Filename Overview
packages/core/src/index.test.ts Added comprehensive tests for payload extraction, error handler resilience, environment variable cleanup, base64 signature verification, and stats tracking for unknown event types
packages/github/src/index.test.ts Added schema validation tests for installation events and test for secret normalization with sha256= prefix handling
packages/nextjs/src/index.test.ts Improved secret verification test to properly assert verify() call, and added test to verify observer option doesn't mutate original webhook
packages/ragie/src/index.test.ts Added schema validation for partition limit exceeded events, nonce verification in payload extraction, and test for missing event type handling

Sequence Diagram

sequenceDiagram
    participant Test as Test Suite
    participant Webhook as Webhook Builder
    participant Provider as Provider
    participant Handler as Event Handler
    participant Observer as Observer/Stats
    
    Note over Test,Observer: Environment Variable Cleanup Tests
    Test->>Test: Store previous env vars
    Test->>Webhook: process() without secret
    Webhook->>Provider: verify() with WEBHOOK_SECRET
    Provider-->>Webhook: verification result
    Test->>Test: Restore env vars in finally block
    
    Note over Test,Observer: Error Handler Resilience Tests
    Test->>Webhook: process() with failing onError
    Webhook->>Handler: execute handler (throws error)
    Handler-->>Webhook: error thrown
    Webhook->>Observer: call onError (throws)
    Observer-->>Webhook: error ignored
    Webhook-->>Test: return 500 status
    
    Note over Test,Observer: Payload Extraction Tests
    Test->>Webhook: process() with envelope structure
    Webhook->>Provider: getPayload(body)
    Provider->>Provider: Extract payload and nonce
    Provider-->>Webhook: merged payload with nonce
    Webhook->>Handler: execute with extracted payload
    Handler-->>Test: verify nonce present
    
    Note over Test,Observer: Observer Immutability Tests
    Test->>Webhook: create original webhook
    Test->>Webhook: toAdapter(webhook, {observer})
    Webhook->>Webhook: clone with observer
    Test->>Webhook: process() on original
    Test->>Webhook: process() on adapter
    Test-->>Test: verify original unchanged
Loading

@vercel
Copy link

vercel bot commented Feb 7, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
better-webhook-docs Ready Ready Preview, Comment Feb 7, 2026 5:34pm

@coderabbitai
Copy link

coderabbitai bot commented Feb 7, 2026

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Walkthrough

This pull request adds and extends tests across multiple packages: core (payload extraction, error handling, secret-resolution fallbacks, HMAC verification including base64 paths, webhook stats, and observer behavior), express/gcp-functions/nextjs (verifying observers do not mutate original webhook instances), github (adds installation and installation_repositories event schemas and tests, plus signature verification cases), and ragie (adds partition_limit_exceeded event type/schema and related tests). No public API declarations are removed; a few new types/schemas are exported in github and ragie.

Possibly related PRs

  • endalk200/better-webhook — PR 21: Introduces provider verification modes and enforces verification in provider/webhook creation; closely related to the added tests for secret resolution, HMAC verification, and verification-failed handling.
  • endalk200/better-webhook — PR 14: Implements event-definition refactors (defineEvent/WebhookEvent and moving schemas), which align with the test changes that exercise event schemas and event-driven handler behavior.
🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main objective of the PR: improving test coverage and reliability across multiple packages through enhanced test suites.
Description check ✅ Passed The description clearly explains the PR's purpose, scope (test-only changes across 6 packages), and provides detailed analysis including a sequence diagram and file-by-file breakdown.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch chore-improve-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 and usage tips.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Improves test coverage and reliability across packages by adding new schema validation tests, strengthening adapter behavior assertions, and expanding webhook verification/edge-case scenarios.

Changes:

  • Added schema validation tests for new/previously untested event types (Ragie partition limit, GitHub installation events).
  • Improved adapter tests (Next.js/GCP Functions/Express) to ensure observer usage doesn’t mutate the original webhook.
  • Expanded core webhook tests for payload extraction, error-handler robustness, secret resolution, and HMAC verification edge cases.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
packages/ragie/src/index.test.ts Adds schema coverage for partition limit events and a missing-eventType webhook edge case.
packages/nextjs/src/index.test.ts Strengthens option passing assertion and adds immutability coverage when observer is used.
packages/github/src/index.test.ts Adds installation-related schema tests and expands signature/secret handling coverage.
packages/gcp-functions/src/index.test.ts Adds immutability coverage when observer is used.
packages/express/src/index.test.ts Adds immutability coverage when observer is used.
packages/core/src/index.test.ts Adds payload extraction tests, resilience to observer callback failures, secret fallback coverage, and more HMAC/stats edge cases.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

6 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@endalk200
Copy link
Owner Author

@greptile-ai review

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@endalk200 endalk200 force-pushed the chore-improve-tests branch from 5bf19ed to b3a0f5f Compare February 7, 2026 17:33
@endalk200 endalk200 merged commit ccdaddd into main Feb 7, 2026
6 of 7 checks passed
@endalk200 endalk200 deleted the chore-improve-tests branch February 24, 2026 16:12
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.

2 participants