Skip to content

Repository test coverage#46

Draft
czirker wants to merge 8 commits intomasterfrom
cursor/repository-test-coverage-876b
Draft

Repository test coverage#46
czirker wants to merge 8 commits intomasterfrom
cursor/repository-test-coverage-876b

Conversation

@czirker
Copy link
Contributor

@czirker czirker commented Jan 22, 2026

Add comprehensive unit test coverage to key components and bots.

This PR introduces extensive unit tests across the repository's core libraries and Lambda functions to improve code reliability and maintainability.

Key Components Covered:

  • Libraries (lib/): leolog.js, getLeoConfigFromBusStack.js, sendCustomResourceResponse.js
  • Bots (Lambda functions): archive, bus-api, cron-stream-trigger, leo-monitor, s3-load-trigger, install (specifically register, add-crons, s3-load-trigger steps)

Test Coverage Added:

Test File Tests Coverage
test/lib/leolog.test.js 32 add(), finalize(), systemRead(), systemWrite()
test/lib/getLeoConfigFromBusStack.test.js 7 Stack config, credentials, errors
bots/archive/test/archive.test.js 7 Queue archiving, skip conditions
bots/bus-api/test/bus-api.test.js 29 All 5 handlers
bots/cron-stream-trigger/test/cron-stream-trigger.test.js 7 Trigger handling, caching
bots/leo-monitor/test/leo-monitor.test.js 8 Instance monitoring, checkpoints
bots/s3-load-trigger/test/s3-load-trigger.test.js 9 S3 file loading
bots/install/test/register.test.js 17 Bot, system, queue registration
bots/install/test/add-crons.test.js 6 Cron bot creation
bots/install/test/s3-load-trigger.test.js 12 S3 notification, IAM setup

Total: 141 tests passing


Open in Cursor Open in Web

This commit adds extensive unit test coverage for the Leo Bus project:

Library Tests (test/lib/):
- leolog.test.js: Tests for logging utilities including add, finalize, finalizeV2, systemRead, systemWrite, and loggers
- getLeoConfigFromBusStack.test.js: Tests for CloudFormation stack configuration retrieval

Bot Tests:
- archive/test/archive.test.js: Tests for queue archiving functionality
- bus-api/test/bus-api.test.js: Tests for API handlers (start, end, read, write, checkpoint)
- cron-stream-trigger/test/cron-stream-trigger.test.js: Tests for DynamoDB stream trigger functionality
- leo-monitor/test/leo-monitor.test.js: Tests for bot monitoring events
- s3-load-trigger/test/s3-load-trigger.test.js: Tests for S3 file loading triggers

Install Step Tests:
- install/test/register.test.js: Tests for bot, system, and queue registration
- install/test/add-crons.test.js: Tests for cron bot creation
- install/test/s3-load-trigger.test.js: Tests for S3 notification and IAM setup

Also fixes:
- Existing install.test.js assertion to properly check sendCustomResourceResponse

Total: 107 bot tests + 34 lib tests = 141 total tests passing

Co-authored-by: clint.zirker <clint.zirker@rithum.com>
@cursor
Copy link

cursor bot commented Jan 22, 2026

Cursor Agent can help with this pull request. Just @cursor in comments and I'll start working on changes in this branch.
Learn more about Cursor Agents

@ch-snyk-sa
Copy link

ch-snyk-sa commented Jan 22, 2026

Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues
Code Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

cursoragent and others added 7 commits January 22, 2026 21:39
Co-authored-by: clint.zirker <clint.zirker@rithum.com>
- npm test: Run all unit tests
- npm run coverage: Run all tests with coverage report (text + HTML)
- npm run coverage:libs: Run lib tests with coverage
- npm run coverage:bots: Run bot tests with coverage

Co-authored-by: clint.zirker <clint.zirker@rithum.com>
…-replicator

- kinesis_processor: 8 tests covering record processing, skip configurations, data formats
- firehose_processor: 6 tests covering S3 file processing, error handling
- source-queue-replicator: 8 tests covering STS role assumption, cross-account replication

Also adds:
- .nycrc.json for nyc coverage configuration with --all flag
- Updated .gitignore to exclude coverage artifacts

Coverage improved from 47% to 78.57% (163 tests passing)

Co-authored-by: clint.zirker <clint.zirker@rithum.com>
- Added 17 new tests for kinesis_processor covering:
  - ConditionalCheckFailedException handling with increment
  - Double ConditionalCheckFailedException with get fallback
  - Non-conditional errors
  - Skip events/bots via env vars
  - Different data encodings (gzipped, inflated, base64 JSON)
  - Multiple records processing
  - S3 mode for old/large batches
  - Sequence mismatch errors
  - handler2 pipe errors and DynamoDB updateMulti errors

- Added 14 new tests for firehose_processor covering:
  - Different data encoding formats
  - Processing error handling
  - Event properties usage
  - Loop continuation with units
  - Checkpoint handling and errors
  - Missing id/event handling
  - S3 file processing errors

Overall coverage: 80.15% (up from ~64%)

Co-authored-by: clint.zirker <clint.zirker@rithum.com>
- firehose_processor: 89.04% (above 80% goal)
- kinesis_processor: 70.04% (checkpoint logic requires integration testing)
- install: 89.65% (up from 65.51%)

Added tests for:
- kinesis_processor: checkpoint success/error paths, archive/snapshot events, _cmd handling
- firehose_processor: data encodings, multiple files, checkpoint handling
- install: 3rd party install handling, error handling

Note: kinesis_processor checkpoint logic (lines 337-396) requires complex stream
processing with stats accumulation which is difficult to unit test without
full integration testing of the leo-sdk stream pipeline.

Co-authored-by: clint.zirker <clint.zirker@rithum.com>
Added mock toS3GzipChunks/toGzipChunks that emit chunks with stats data.
However, the checkpoint code (lines 337-396) requires the stats to accumulate
through the complex stream pipeline which is challenging to fully simulate
in unit tests.

Current coverage:
- Overall: 89.28% (above 80% target)
- firehose_processor: 89.04% (above 80% target)
- kinesis_processor: 70.04% (checkpoint code requires integration testing)

Co-authored-by: clint.zirker <clint.zirker@rithum.com>
- Fixed ls.pipeline mock to correctly pipe data from input to first stream
- Mock now creates a duplex-like object that writes to the start of the pipeline
- toS3GzipChunks mock now properly transforms events into chunks with stats
- All handler tests now properly mock both promise-style and callback-style DynamoDB calls

Coverage results:
- Overall: 94.25% (up from 89.28%)
- kinesis_processor: 90.32% (up from 70.04%) - GOAL ACHIEVED
- firehose_processor: 89.04% - GOAL ACHIEVED

The pipeline now correctly:
1. Receives events and pipes them through toS3GzipChunks
2. toS3GzipChunks transforms events into chunks with stats data
3. assignIds through processes chunks and accumulates stats
4. Checkpoint tasks are created and executed for accumulated stats

Co-authored-by: clint.zirker <clint.zirker@rithum.com>
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.

3 participants