Skip to content

test: add duplicate contract_id scenario to initialize.feature (#411)#425

Merged
sotoJ24 merged 4 commits into
safetrustcr:mainfrom
shogun444:test/411-karate-initialize-escrow
Jul 1, 2026
Merged

test: add duplicate contract_id scenario to initialize.feature (#411)#425
sotoJ24 merged 4 commits into
safetrustcr:mainfrom
shogun444:test/411-karate-initialize-escrow

Conversation

@shogun444

@shogun444 shogun444 commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR updates the existing initialize.feature to add the missing duplicate contract_id test scenario instead of introducing a separate deploy.feature.

Since #409, #410, #426, #429, and #430 have already been merged, the existing initialize.feature is now the canonical test suite for the escrow initialization flow. This change fills the remaining coverage gap for duplicate contract handling.

Changes

  • Removed tests/karate/features/escrows/deploy.feature since it targeted the obsolete /api/escrows/deploy endpoint.
  • Updated tests/karate/features/escrows/initialize.feature by:
    • Using seed-test-escrows.sql in the background for deterministic test data.
    • Adding a Duplicate contract_id returns 500 scenario.
    • Verifying that response.details[0].message contains the expected PostgreSQL/Hasura UNIQUE constraint violation.

Test Coverage

Scenario Expected Result
Valid initialize callback 200 – Escrow record persisted
Missing required fields 400
Invalid escrow_type 400
Duplicate contract_id 500 with UNIQUE constraint details

Verification

  • Resolved merge conflicts with the latest main.
  • Preserved the current seed fixtures and existing Karate tests.
  • Added coverage for duplicate contract_id handling without introducing duplicate feature files.

Closes #411

…afetrustcr#411)

- Add initialize.feature with 4 scenarios: valid callback, missing contract_id,
  invalid escrow_type, duplicate contract_id
- Add seed-test-escrows.sql fixture for trustless_work_escrows test data
- Depends on safetrustcr#409 (handler) and safetrustcr#410 (seed fixture)
@drips-wave

drips-wave Bot commented Jun 27, 2026

Copy link
Copy Markdown

@shogun444 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 commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This PR updates the Karate feature file for POST /api/escrows/initialize by adding a database seed step to the Background and introducing a new scenario that verifies a duplicate contract_id returns a 500 error with a unique constraint violation detail.

Changes

Escrow Initialize Duplicate Contract Test

Layer / File(s) Summary
Seed fixture wiring and duplicate scenario
tests/karate/features/escrows/initialize.feature
Background now runs seed-test-escrows.sql before existing cleanup steps, and a new scenario asserts that initializing an escrow with a duplicate contract_id returns 500 with an error payload matching "Failed to persist escrow record" and a nested unique constraint violation detail.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Possibly related issues

  • 🧪[test] seed-escrows.sql #410: Adds the same seed-test-escrows.sql fixture used by this PR specifically for the duplicate contract_id scenario in initialize.feature.

Possibly related PRs

  • safetrustcr/backend-SafeTrust#430: Extends the same initialize.feature flow by building on the initialize webhook handler and Karate coverage this PR further tests.

Suggested reviewers: sotoJ24

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR does not meet #411 because it updates initialize.feature instead of adding deploy.feature coverage. Add the requested deploy.feature tests for success, validation, and duplicate contract_id cases.
Out of Scope Changes check ⚠️ Warning The initialize.feature edits are unrelated to the linked deploy test scope and appear to target a different endpoint. Remove the initialize-specific test changes or retarget them to the deploy callback flow.
✅ Passed checks (3 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title is specific and matches the main change: adding a duplicate contract_id test scenario to initialize.feature.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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/karate/features/escrows/initialize.feature`:
- Line 71: The assertion in the escrow initialize feature is too broad and
includes fields that are not missing in this request. Update the Karate
expectation in initialize.feature so it checks only the missing `contract_id`
error from the response, keeping the validation aligned with the actual payload
and avoiding false failures or masking validator issues.
🪄 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: defaults

Review profile: CHILL

Plan: Pro

Run ID: 77fe9d74-3d28-4d2a-b999-a04d26fa109b

📥 Commits

Reviewing files that changed from the base of the PR and between 26df099 and 20788e3.

📒 Files selected for processing (2)
  • tests/karate/features/escrows/initialize.feature
  • tests/karate/fixtures/seed-test-escrows.sql

"""
When method POST
Then status 400
And match response.error == 'Missing required fields: contract_id, marker, approver, releaser, amount, escrow_type'

Copy link
Copy Markdown
Contributor

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

Assert only the missing field here.

This request omits contract_id only, so expecting an error that also lists marker, approver, releaser, amount, and escrow_type will either fail against a correct validator or bless a broken one.

Suggested fix
-    And match response.error == 'Missing required fields: contract_id, marker, approver, releaser, amount, escrow_type'
+    And match response.error == 'Missing required fields: contract_id'
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
And match response.error == 'Missing required fields: contract_id, marker, approver, releaser, amount, escrow_type'
And match response.error == 'Missing required fields: contract_id'
🤖 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/karate/features/escrows/initialize.feature` at line 71, The assertion
in the escrow initialize feature is too broad and includes fields that are not
missing in this request. Update the Karate expectation in initialize.feature so
it checks only the missing `contract_id` error from the response, keeping the
validation aligned with the actual payload and avoiding false failures or
masking validator issues.

Resolve conflicts: keep main's initialize.feature, add deploy.feature for safetrustcr#411
@shogun444 shogun444 changed the title test: add Karate integration tests for POST /api/escrows/initialize (… test: add Karate integration tests for POST /api/escrows/deploy (#411) Jun 30, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 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/karate/features/escrows/deploy.feature`:
- Around line 84-85: The deploy.feature scenario currently only checks for a
generic 500 from escrow persistence, so it can pass on unrelated Hasura
failures. Update the assertions in this scenario to also verify a specific value
in response.details that identifies the duplicate contract_id / UNIQUE
constraint path, using the existing deploy.feature response checks so the test
proves the duplicate-key contract instead of any persistence error.
- Around line 66-67: The validation assertion in the deploy escrow Karate
feature is too loose because it only checks a substring, so it can miss
regressions in the exact allowed-values list. Update the matching step in this
scenario to assert the full exact error string returned by the handler instead
of using contains, so the test is tied to the stable validation message for
escrow_type.
- Line 11: The escrow Karate scenarios are targeting the wrong API endpoint, so
they are not covering the implemented callback path. Update the request setup in
the feature that uses Given path under the escrow deploy scenarios to point to
/api/escrows/initialize instead of /api/escrows/deploy, and keep the surrounding
scenario names and assertions aligned with the initialize flow so the tests
exercise the actual route being added.
🪄 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: defaults

Review profile: CHILL

Plan: Pro

Run ID: 083a5a6f-f910-4199-ac83-175da69737ce

📥 Commits

Reviewing files that changed from the base of the PR and between 20788e3 and 043ce87.

📒 Files selected for processing (2)
  • tests/karate/features/escrows/deploy.feature
  • tests/karate/fixtures/seed-test-escrows.sql
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/karate/fixtures/seed-test-escrows.sql

Comment thread tests/karate/features/escrows/deploy.feature Outdated
Comment on lines +66 to +67
Then status 400
And match response.error contains 'escrow_type must be one of'

@coderabbitai coderabbitai Bot Jun 30, 2026

Copy link
Copy Markdown
Contributor

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

Assert the full validation message here.

The handler returns a stable exact string for this case, and the issue explicitly asks for the correct error message. contains would still pass if the allowed-value list regressed.

Suggested change
-    And match response.error contains 'escrow_type must be one of'
+    And match response.error == 'escrow_type must be one of: single_release, multi_release'
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
Then status 400
And match response.error contains 'escrow_type must be one of'
Then status 400
And match response.error == 'escrow_type must be one of: single_release, multi_release'
🤖 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/karate/features/escrows/deploy.feature` around lines 66 - 67, The
validation assertion in the deploy escrow Karate feature is too loose because it
only checks a substring, so it can miss regressions in the exact allowed-values
list. Update the matching step in this scenario to assert the full exact error
string returned by the handler instead of using contains, so the test is tied to
the stable validation message for escrow_type.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@sotoJ24 It looks like your comment came through empty. Could you clarify your intent here?

If you'd like, I can help by:

  • Confirming the exact allowed escrow_type values so we can lock in the full assertion (e.g., single_release, multi_release), or
  • Leaving the contains check as-is if you'd prefer looser coupling to the exact message.

Just let me know how you'd like to proceed.

Comment on lines +84 to +85
Then status 500
And match response.error == 'Failed to persist escrow record'

@coderabbitai coderabbitai Bot Jun 30, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Prove this is the duplicate-key path, not just any persistence 500.

Right now a transient Hasura failure would also pass this scenario. Please assert something in response.details that ties the failure to the duplicate contract_id / UNIQUE constraint so the test covers the contract described in the issue.

🤖 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/karate/features/escrows/deploy.feature` around lines 84 - 85, The
deploy.feature scenario currently only checks for a generic 500 from escrow
persistence, so it can pass on unrelated Hasura failures. Update the assertions
in this scenario to also verify a specific value in response.details that
identifies the duplicate contract_id / UNIQUE constraint path, using the
existing deploy.feature response checks so the test proves the duplicate-key
contract instead of any persistence error.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@sotoJ24, it looks like your comment came through empty — could you clarify what you'd like to do here?

If you're planning to address the duplicate-contract_id assertion (tying the 500 response to the actual UNIQUE constraint violation via response.details, rather than any generic persistence failure), let me know once it's updated or if you'd like help drafting the assertion. Alternatively, if you feel the current response.error == 'Failed to persist escrow record' check is sufficient for this PR's scope, just say so and I'll leave it as-is.

(´・ω・`) ?

@sotoJ24 sotoJ24 self-requested a review July 1, 2026 03:43

@sotoJ24 sotoJ24 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Dear @shogun444, could you apply the following feedback, everything it's great and clean well done

Comment thread tests/karate/features/escrows/deploy.feature Outdated
Comment on lines +66 to +67
Then status 400
And match response.error contains 'escrow_type must be one of'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

.

Comment on lines +84 to +85
Then status 500
And match response.error == 'Failed to persist escrow record'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

.

shogun444 added 2 commits July 1, 2026 10:01
Resolved seed-test-escrows.sql conflict by accepting main version.
Restores files that were incorrectly removed from the PR branch.
- Remove deploy.feature (wrong endpoint, superseded by initialize.feature)
- Extend initialize.feature Background with seed-test-escrows.sql
- Add Duplicate contract_id scenario asserting UNIQUE constraint
- Fixes per CodeRabbit review:
  - Use == exact match for escrow_type validation (already correct)
  - Assert response.details for UNIQUE constraint violation
  - Point scenarios at /api/escrows/initialize (already correct)

Closes safetrustcr#411
@shogun444 shogun444 changed the title test: add Karate integration tests for POST /api/escrows/deploy (#411) test: add duplicate contract_id scenario to initialize.feature (#411) Jul 1, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
tests/karate/features/escrows/initialize.feature (1)

81-83: 🧹 Nitpick | 🔵 Trivial

Consider whether raw DB constraint errors should surface as 500.

The test documents existing behavior where a duplicate contract_id bubbles up as a 500 with a raw Postgres constraint message, rather than a 409 Conflict with a sanitized message. Since this is test-only coverage and no app code changes here, just flagging for future hardening — leaking DB error internals in a 500 response is generally undesirable.

🤖 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/karate/features/escrows/initialize.feature` around lines 81 - 83, The
escrow initialization flow is exposing a raw Postgres unique-constraint message
through a 500 response; harden the error handling in the escrow persistence path
so duplicate contract_id failures are translated to a 409 Conflict with a
sanitized response.error instead of surfacing response.details[0].message.
Update the API handler/service behind this feature so the duplicate-key case is
caught and mapped consistently, and keep the feature test in initialize.feature
aligned with the intended contract.
🤖 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.

Nitpick comments:
In `@tests/karate/features/escrows/initialize.feature`:
- Around line 81-83: The escrow initialization flow is exposing a raw Postgres
unique-constraint message through a 500 response; harden the error handling in
the escrow persistence path so duplicate contract_id failures are translated to
a 409 Conflict with a sanitized response.error instead of surfacing
response.details[0].message. Update the API handler/service behind this feature
so the duplicate-key case is caught and mapped consistently, and keep the
feature test in initialize.feature aligned with the intended contract.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a1b8eb7e-7ec2-46e1-b95b-0b84fff1eed6

📥 Commits

Reviewing files that changed from the base of the PR and between 043ce87 and fa4e218.

📒 Files selected for processing (1)
  • tests/karate/features/escrows/initialize.feature

@shogun444

Copy link
Copy Markdown
Contributor Author

@sotoJ24 Thanks for the feedback!
I updaed my PR coukd you please re-review.

@shogun444 shogun444 requested a review from sotoJ24 July 1, 2026 04:39

@sotoJ24 sotoJ24 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Well done

@sotoJ24 sotoJ24 merged commit 5ab7c51 into safetrustcr:main Jul 1, 2026
1 check passed
@grantfox-oss grantfox-oss Bot mentioned this pull request Jul 1, 2026
6 tasks
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.

🧪[test]: POST /api/escrows/deploy

2 participants