Skip to content

test(funding): saga idempotency/retry/resume coverage (closes #84 gap)#86

Merged
ldamasio merged 1 commit into
mainfrom
test/funding-idempotency
Jun 3, 2026
Merged

test(funding): saga idempotency/retry/resume coverage (closes #84 gap)#86
ldamasio merged 1 commit into
mainfrom
test/funding-idempotency

Conversation

@ldamasio

@ldamasio ldamasio commented Jun 3, 2026

Copy link
Copy Markdown
Owner

What

Closes the test gap flagged in #84: the funding saga's idempotency / retry / resume behavior is now covered. This is the agreed blocker before FUNDING_ENABLED can be flipped on.

Tests (robsond/src/funding/tests.rs)

pg-backed, using #[sqlx::test(migrations = "../migrations")] + #[ignore = "Requires DATABASE_URL"] (the repo's existing pattern), driving the real FundingService against StubExchange:

Test Asserts
happy_path quote→execute reaches REFRESHED; futures balance + engine capital updated; spot_order_call_count == 1, transfer_call_count == 1
idempotent_convert_no_double_execute re-running execute on a terminal saga does not re-place spot orders or re-transfer (counts unchanged)
resume_after_crash_post_converted injected transfer failure leaves the saga mid-flight; a second execute (worker resume) reaches REFRESHED without re-converting
expired_quote_rejected quote_ttl_secs = 0 → execute fails/FAILED, no spot order placed
dust_skipped sub-dust_usdt balance excluded from quote + conversions

Gating & CI

The module is #[cfg(all(test, feature = "postgres"))], so the no-postgres CI test build is unaffected (these are #[ignore] and don't run in CI — same as the existing pg tests in daemon.rs / robson-store).

Verification (run by me, not the executor)

Against an ephemeral Postgres 16:

DATABASE_URL=…:5433/funding_test cargo test -p robsond --features postgres --lib funding -- --ignored
→ test result: ok. 5 passed; 0 failed

Diff is test-only (funding/tests.rs +332, funding/mod.rs +3); stub.rs unchanged (the *_call_count getters already exist on main).

🤖 Generated with Claude Code

Add pg-backed tests (#[sqlx::test], #[ignore]) for FundingService driving
StubExchange — closes the test gap from #84 before FUNDING_ENABLED can be
flipped:
- happy_path: quote→execute→REFRESHED, futures balance + capital updated,
  spot_order_call_count == 1, transfer_call_count == 1.
- idempotent_convert_no_double_execute: re-running execute on a terminal saga
  does not re-place orders/transfers (counts unchanged).
- resume_after_crash_post_converted: transfer failure leaves saga mid-flight;
  re-execute reaches REFRESHED without re-converting.
- expired_quote_rejected (ttl=0) and dust_skipped.

Gated by cfg(all(test, feature = "postgres")) so the no-postgres CI build is
unaffected. Verified locally: 5 passed against Postgres 16.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@ldamasio ldamasio force-pushed the test/funding-idempotency branch from 948d510 to 29d0092 Compare June 3, 2026 01:09
@ldamasio ldamasio merged commit 37abee2 into main Jun 3, 2026
2 checks passed
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.

1 participant