Skip to content

test(aml): add regression suite for AMLRuleRepository error paths and boundary contracts - #1239

Open
eteonninob-arch wants to merge 1 commit into
RevoraOrg:masterfrom
eteonninob-arch:test/aml-rule-repository-regression-suite
Open

eteonninob-arch wants to merge 1 commit into
RevoraOrg:masterfrom
eteonninob-arch:test/aml-rule-repository-regression-suite

Conversation

@eteonninob-arch

@eteonninob-arch eteonninob-arch commented Sep 29, 2026 •

Copy link
Copy Markdown

Closes #955

Title

test(aml): add regression suite for AMLRuleRepository error paths and boundary contracts

Description

This PR implements a comprehensive regression suite for AMLRuleRepository to cover explicit failure and boundary paths and prevent silent behavior or contract regressions.

Evidence Covered

  • src/aml/amlRuleRepository.ts:130: throw new Error(\Rule ${ruleId} not found`);`
  • src/aml/amlRuleRepository.ts:236: throw new Error(\Version ${JSON.stringify(version)} not found for rule ${ruleId}`);`

Changes Made

  • Expanded src/aml/amlRuleRepository.test.ts with deterministic unit and regression tests.
  • Replaced untyped mock structures with strongly-typed mock query execution and lifecycle verification (BEGIN, COMMIT, ROLLBACK, client release tracking).
  • Preserved existing public API and database contracts without breaking changes.

Exercised Cases

  1. Rule Update Failure & Boundary Paths (amlRuleRepository.ts:130):

    • Non-existent rule ID throws Error("Rule nonexistent not found").
    • Empty string rule ID ("") throws Error("Rule not found").
    • Whitespace rule ID (" ") throws Error("Rule not found").
    • Special character rule ID ("rule/404#special!") throws Error("Rule rule/404#special! not found").
    • UUID formatted non-existent ID throws Error("Rule <uuid> not found").
    • Confirmed transaction ROLLBACK is executed and database connection is released without committing.
    • Database failure during UPDATE query rolls back transaction and releases client.
  2. Rollback Failure & Boundary Paths (amlRuleRepository.ts:236):

    • Target version not in version history throws Error("Version {\"major\":99,\"minor\":99,\"patch\":99} not found for rule rule_1").
    • Boundary version { major: 0, minor: 0, patch: 0 } not in history throws exact contract error.
    • Negative version components { major: 0, minor: -1, patch: 0 } throw exact contract error.
    • Non-existent rule ID during rollback throws Error("Version ... not found for rule nonexistent").
    • Empty string and whitespace rule IDs throw exact contract error.
    • Special character rule IDs throw exact contract error.
    • Confirmed transaction ROLLBACK is executed and database connection is released without committing.
    • Database failure during rollback query execution rolls back transaction and releases client.
  3. Neighboring Normal Paths:

    • Creation creates version 1.0.0, records history, commits, and releases client.
    • Creation database failure executes ROLLBACK and releases client.
    • Update config bumps minor version and resets patch (1.0.0 -> 1.1.0).
    • Update metadata / enabled bumps patch version (1.0.0 -> 1.0.1).
    • Rollback to previous version (1.0.0) increments patch (1.0.1), restores historical config and enabled state, and logs audit reason Rollback to version {\"major\":1,\"minor\":0,\"patch\":0}.
    • Rollback to version with non-zero patch (1.2.3 -> 1.2.4).
    • JSON string vs parsed object handling for version and config fields.

Validation

  • Focused Suite: npx jest src/aml/amlRuleRepository.test.ts (36/36 passed, 100% branch and line coverage)
  • Surrounding Suite: npx jest src/aml/ (9 suites, 223/223 passed)
  • TypeScript: npx tsc --noEmit passed with 0 errors
  • Lint: npx eslint src/aml/amlRuleRepository.test.ts passed with 0 errors / 0 warnings

@drips-wave

drips-wave Bot commented Sep 29, 2026

Copy link
Copy Markdown

@eteonninob-arch 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

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.

Add regression coverage for AMLRuleRepository failure handling

1 participant