Skip to content

test: delete e2e merchant accounts after each run - #344

Merged
cbetta merged 3 commits into
mainfrom
test/e2e-delete-merchant-accounts
Nov 4, 2026
Merged

cbetta merged 3 commits into
mainfrom
test/e2e-delete-merchant-accounts

Conversation

@cbetta

@cbetta cbetta commented Nov 4, 2026 •

Copy link
Copy Markdown
Member
Reviewer check This PR
Auth / permissions No
Data access widened No
New secret, env var or key No
CI, deploy or infra No
Dependencies added or bumped No
Copilot Pending
Security review Pending

Every e2e run left its merchant accounts behind on api.sandbox.e2e.gr4vy.app now that it is no longer reset. This deletes them with core-api's new DELETE /merchant-accounts/{id} (gr4vy/core-api#9999, TA-19741). It isn't in the public spec, so the call is a raw request signed with the existing PRIVATE_KEY. A failed delete is logged and never fails the run (204 and 404 both count as done).

// Harness.java
public static synchronized void trackMerchantAccount(String id, String privateKey) {
    if (createdMerchantAccounts.isEmpty()) {
        Runtime.getRuntime().addShutdownHook(new Thread(Harness::deleteCreatedMerchantAccounts));
    }
    createdMerchantAccounts.put(id, privateKey);
}

Each CI shard is its own JVM, so the hook runs once per shard. The shared merchant is tracked when it is created, and MerchantAccountsTest.create tracks its extra account.

Cleanup is armed before the create call, so an account whose create response is lost still gets deleted (a never-created id just returns 404).

Verified: ./gradlew compileTestJava (JDK 21) passes. Not yet run live against e2e.

🤖 Generated with Claude Code

cbetta and others added 2 commits November 4, 2026 15:02
Calls core-api's DELETE /merchant-accounts/{id} (gr4vy/core-api#9999)
directly, since it is not in the public spec. Failures are logged and
never fail the run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A create whose response is lost still leaves the account on the server;
deleting an id that was never created returns 404, which cleanup already
treats as done.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copilot AI 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.

🟡 Changes recommended

Active moderate and critical findings remain in Harness.java: the sandbox URL is duplicated rather than derived from the SDK template, and cleanup can delete an account this run did not create after a definitive create rejection.

2 open issues
What changed in this PR

Adds shutdown-time cleanup for merchant accounts created by E2E tests, preventing sandbox account accumulation through a signed raw DELETE request.

Changes:

  • Tracks shared and test-specific merchant accounts before creation.
  • Registers a JVM shutdown hook to delete tracked accounts.
  • Treats successful and already-missing accounts as completed while logging other failures.

Review findings:

  • Moderate (4 votes): Derive the cleanup host from Gr4vy.SERVERS and SERVER_ID instead of duplicating the sandbox URL.
  • Critical (1 vote): Avoid deleting an account when creation was definitively rejected; retain pre-create tracking only for ambiguous failures or verify ownership before deletion.

This pull request requires changes.

File Summary
src/​test/​java/​com/​gr4vy/​sdk/​util/​Harness.java Tracks merchant accounts and deletes them during JVM shutdown.
src/​test/​java/​com/​gr4vy/​sdk/​backoffice/​MerchantAccountsTest.java Registers the additional merchant account created by the test for cleanup.

Review effort: Lite

@cbetta
cbetta marked this pull request as ready for review November 4, 2026 16:03
Reuses Checkout.API_BASE_URL so the delete call can't drift from the host
the SDK client targets.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copilot AI 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.

🔵 Needs a closer look

Live E2E verification is still needed to confirm the undocumented DELETE endpoint’s authorization, status behavior, and shutdown-hook cleanup reliability.

No open issues 🎉

2 resolved since last review

Review effort: Lite

@cbetta
cbetta merged commit 1e6a0be into main Nov 4, 2026
11 checks passed
@cbetta
cbetta deleted the test/e2e-delete-merchant-accounts branch November 4, 2026 16:35
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