Skip to content

Conversation

@jusdino
Copy link
Collaborator

@jusdino jusdino commented Aug 6, 2025

Description List

  • Update transaction history lambda to check compact config and exit gracefully if not live
  • Update transaction reporting lambda to exit gracefully if compact is not live instead of raising an exception
  • Re-enable alarm for transaction history step function, now that it should exit gracefully in all cases

Testing List

  • Code review

Closes #766

Summary by CodeRabbit

  • Bug Fixes

    • Improved transaction processing and reporting to exit early with a clear status message if a compact or its jurisdictions are not live, instead of raising errors.
    • Enhanced filtering of transaction errors to cover multiple error states consistently.
  • Tests

    • Added and updated tests to verify early exit behavior when compact configuration or jurisdictions are missing, ensuring no downstream processing or notifications occur in these cases.
    • Enhanced test setup for consistent compact and jurisdiction configuration handling.
  • Chores

    • Updated environment variables and permissions for transaction processing to support new configuration checks.
    • Adjusted alarm setup to immediately notify on failures without suppression.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 6, 2025

Walkthrough

The code introduces early exit logic to transaction processing and reporting functions, ensuring they only operate for compacts that are live with valid configuration and jurisdictions. Tests are updated and expanded to cover these early exit scenarios. Infrastructure is adjusted to grant necessary permissions and update alarm notification behavior.

Changes

Cohort / File(s) Change Summary
Transaction Processing Early Exit
backend/compact-connect/lambdas/python/purchases/handlers/transaction_history.py
Adds checks for compact and jurisdiction configuration; exits early if compact is not live, skipping transaction processing.
Transaction Reporting Early Exit
backend/compact-connect/lambdas/python/purchases/handlers/transaction_reporting.py
Moves configuration retrieval earlier; adds early exit if compact or jurisdictions are missing, replacing exception with warning and return.
Transaction Processing Tests
backend/compact-connect/lambdas/python/purchases/tests/function/test_handlers/test_transaction_history.py
Adds helper for compact/jurisdiction config setup, updates tests to use it, and adds tests for early exit when compact or jurisdictions are missing.
Transaction Reporting Tests
backend/compact-connect/lambdas/python/purchases/tests/function/test_handlers/test_transaction_reporting.py
Removes exception expectation, adds/updates tests to check for early exit and no email sending when compact or jurisdictions are missing.
Infrastructure Permissions and Alarms
backend/compact-connect/stacks/transaction_monitoring_stack/transaction_history_processing_workflow.py
Adds environment variable and permissions for compact config table, and updates CloudWatch alarm to immediately notify via SNS.
AuthorizeNet Transaction Error States Enum
backend/compact-connect/lambdas/python/purchases/purchase_client.py
Introduces AuthorizeNetTransactionErrorStates enum for transaction error states; replaces hardcoded strings with enum references in transaction filtering logic.

Sequence Diagram(s)

sequenceDiagram
    participant StepFunction
    participant LambdaHandler
    participant ConfigClient
    participant Logger

    StepFunction->>LambdaHandler: Invoke with event
    LambdaHandler->>ConfigClient: Get compact & jurisdiction configs
    ConfigClient-->>LambdaHandler: Return configs
    alt Compact or jurisdictions missing
        LambdaHandler->>Logger: Log warning
        LambdaHandler-->>StepFunction: Return early (status: COMPLETE)
    else Configs present
        LambdaHandler->>LambdaHandler: Continue transaction/report processing
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15-20 minutes

Assessment against linked issues

Objective Addressed Explanation
Only generate weekly/monthly reports for compacts that are registered as active/live (#766)
Do not process transactions for inactive or unregistered compacts (#766)
Ensure tests cover early exit for inactive compacts (#766)

Assessment against linked issues: Out-of-scope changes

Code Change Explanation
Update to CloudWatch alarm creation logic (backend/compact-connect/stacks/transaction_monitoring_stack/transaction_history_processing_workflow.py) Modifies alarm notification logic, which is not directly related to the objective of skipping processing/reporting for inactive compacts.
Introduction of AuthorizeNetTransactionErrorStates enum and related changes (backend/compact-connect/lambdas/python/purchases/purchase_client.py) Adds enum for transaction error states and replaces string literals; unrelated to compact live status checks or report generation logic.

Possibly related PRs

  • Feat/purchase email #733: Related to privilege purchase event publishing and notification, connected to purchase processing and reporting workflows.

Suggested reviewers

  • jlkravitz

Poem

In the warren where compacts dwell,
Only the live ones ring the bell.
Inactive bunnies, now we skip,
No more false alarms on this trip!
With tests and checks, our code is tight,
The carrot’s earned—everything’s right! 🥕

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Collaborator

@landonshumway-ia landonshumway-ia left a comment

Choose a reason for hiding this comment

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

The code changes look good. Since we are currently in this space, I found from our testing with the OT authorize.net account that there is another transactionStatus value, generalError, that did not show up in the sandbox environment which we will want to account for. I've marked the place in the reporting where these will need to be filtered, and we will also need to add a check for this status type in the conditional here:

if str(tx.transactionStatus) == 'settlementError':

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
backend/compact-connect/lambdas/python/purchases/purchase_client.py (1)

799-799: Verify the intentional broadening of error detection logic.

The change from str(tx.transactionStatus) == 'settlementError' to str(tx.transactionStatus) in AuthorizeNetTransactionErrorStates expands error detection to include both 'settlementError' and 'generalError' states. This broadens the scope of transactions flagged as having errors.

Consider updating the variable name settlement_error_transaction_ids to reflect that it now includes general errors too, perhaps error_transaction_ids or failed_transaction_ids.

-        settlement_error_transaction_ids = []
+        error_transaction_ids = []

And update the corresponding references in the method.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between da57569 and f3cf354.

📒 Files selected for processing (3)
  • backend/compact-connect/lambdas/python/purchases/handlers/transaction_reporting.py (3 hunks)
  • backend/compact-connect/lambdas/python/purchases/purchase_client.py (4 hunks)
  • backend/compact-connect/lambdas/python/purchases/tests/function/test_handlers/test_transaction_reporting.py (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • backend/compact-connect/lambdas/python/purchases/handlers/transaction_reporting.py
  • backend/compact-connect/lambdas/python/purchases/tests/function/test_handlers/test_transaction_reporting.py
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: landonshumway-ia
PR: csg-org/CompactConnect#848
File: backend/compact-connect/lambdas/python/provider-data-v1/handlers/registration.py:111-117
Timestamp: 2025-06-17T19:05:36.255Z
Learning: In CompactConnect PR #848, the user landonshumway-ia decided to leave timezone handling code in _should_allow_reregistration function as-is after testing in sandbox environment confirmed it works correctly. The user's reasoning was that reregistration is an edge case, the code has been tested and verified, and AWS is unlikely to change behavior that would break many clients. This represents a pragmatic engineering decision based on testing and risk assessment.
Learnt from: landonshumway-ia
PR: csg-org/CompactConnect#882
File: backend/compact-connect/lambdas/python/migration/compact_configured_states_871/main.py:127-130
Timestamp: 2025-06-26T16:42:00.781Z
Learning: In the compact_configured_states_871 migration, existing jurisdiction configurations that have licenseeRegistrationEnabled: true are migrated with isLive: true for backwards compatibility. This prevents breaking existing live functionality since those states are already operational. The migration preserves the current live state of jurisdictions to maintain service continuity, while new states added after migration can start with isLive: false and be controlled by compact admins.
Learnt from: landonshumway-ia
PR: csg-org/CompactConnect#882
File: backend/compact-connect/lambdas/python/common/cc_common/data_model/compact_configuration_client.py:287-359
Timestamp: 2025-07-08T18:40:24.408Z
Learning: In the CompactConnect codebase, landonshumway-ia prefers to avoid extraneous unit tests when existing test coverage is already sufficient to catch bugs. For the get_privilege_purchase_options method's live-jurisdiction filtering logic, the existing tests in the purchases test suite provide adequate coverage without needing additional edge case tests.
Learnt from: landonshumway-ia
PR: csg-org/CompactConnect#852
File: backend/compact-connect/stacks/persistent_stack/__init__.py:545-549
Timestamp: 2025-06-09T22:03:03.232Z
Learning: In the CompactConnect codebase, production active_compact_member_jurisdictions configurations are very stable and unlikely to be removed. The vast majority of configuration errors in get_list_of_active_jurisdictions_for_compact_environment() will occur when developers are deploying sandbox environments, so error messages that primarily reference sandbox configuration are appropriate for the typical use case.
Learnt from: landonshumway-ia
PR: csg-org/CompactConnect#769
File: backend/compact-connect/lambdas/python/provider-data-v1/tests/function/test_handlers/test_encumbrance.py:138-147
Timestamp: 2025-04-29T02:52:40.532Z
Learning: In CompactConnect tests, hardcoded values (like license type abbreviations 'slp') in test queries are sometimes used intentionally rather than using dynamic lookups. This is a deliberate design decision to make tests fail if default test data changes, requiring developers to consciously update related tests.
Learnt from: landonshumway-ia
PR: csg-org/CompactConnect#824
File: backend/compact-connect/tests/smoke/encumbrance_smoke_tests.py:461-640
Timestamp: 2025-06-04T17:38:22.392Z
Learning: For smoke tests in backend/compact-connect/tests/smoke/, prioritize linear narrative readability over reducing complexity metrics. These tests are designed to be run manually by developers for verification, and should be readable from top to bottom like a story, allowing developers to follow the complete workflow without jumping between helper methods.
Learnt from: landonshumway-ia
PR: csg-org/CompactConnect#848
File: backend/compact-connect/lambdas/python/migration/provider_user_pool_migration_551/main.py:35-39
Timestamp: 2025-06-10T03:16:16.896Z
Learning: In the provider user pool migration (provider_user_pool_migration_551), the FilterExpression intentionally only checks for the existence of compactConnectRegisteredEmailAddress. The migration should only remove currentHomeJurisdiction if compactConnectRegisteredEmailAddress is also present, targeting records that went through the old registration process. Records with only currentHomeJurisdiction but no compactConnectRegisteredEmailAddress should be left untouched.
Learnt from: landonshumway-ia
PR: csg-org/CompactConnect#952
File: backend/compact-connect/lambdas/python/migration/license_update_effective_date_931/main.py:0-0
Timestamp: 2025-07-29T02:35:59.401Z
Learning: For temporary migration scripts in CompactConnect that process pre-vetted database records and have been verified in development environments, extensive validation for data format may be unnecessary overhead. The user landonshumway-ia indicated that migration scripts can rely on data integrity when the records have been vetted and the script has been tested.
🔇 Additional comments (2)
backend/compact-connect/lambdas/python/purchases/purchase_client.py (2)

1-7: LGTM! Good enum design for standardizing error states.

The addition of AuthorizeNetTransactionErrorStates enum follows best practices by using StrEnum for string-based error states and centralizing previously hardcoded values. This improves type safety and maintainability.

Also applies to: 42-45


621-621: LGTM! Clean enum usage for settlement error checking.

The replacement of the hardcoded string 'settlementError' with AuthorizeNetTransactionErrorStates.SettlementError maintains identical behavior while improving type safety and maintainability.

Copy link
Collaborator

@landonshumway-ia landonshumway-ia left a comment

Choose a reason for hiding this comment

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

Thanks for adding that 👍

@landonshumway-ia
Copy link
Collaborator

@jlkravitz This is ready for your review. Thanks

Copy link
Collaborator

@jlkravitz jlkravitz left a comment

Choose a reason for hiding this comment

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

one small question but otherwise looks good!

Copy link
Collaborator

@jlkravitz jlkravitz left a comment

Choose a reason for hiding this comment

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

@isabeleliassen good to merge!

@isabeleliassen
Copy link
Collaborator

@jlkravitz let me know when that conversation is resolved!

@jlkravitz
Copy link
Collaborator

@isabeleliassen sorry-done!

@isabeleliassen isabeleliassen merged commit 670b656 into csg-org:development Aug 13, 2025
3 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Sep 8, 2025
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.

Bug - do not create weekly reports for inactive compacts

4 participants