Issue: Build Trustless Work End-to-End Test Suite
Depends on: Existing webhook sync (src/webhooks/webhooks.service.ts) and escrow write helper (src/internal-trustless/escrow-write.helper.ts)
Task Description
Develop an end-to-end test suite covering the integration between Thalos and Trustless Work (TW), validating that Agreements stay synchronized across their lifecycle under both success and failure scenarios. This must build on the existing Jest + supertest setup, not introduce a new framework.
Background / Current State
Verified against main: synchronization is driven by inbound webhooks (POST handled in webhooks.service.ts), which map TW events to agreement status changes:
escrow.funded → funded
escrow.released → completed
escrow.disputed / dispute.created → disputed
contract.completed → completed
contract.cancelled → cancelled
- milestone updates → milestone sync
Resilience today is a per-request withRetry() helper, not a persistent retry queue. Tests must target this actual mechanism.
Deliverable
End-to-end *.spec.ts tests covering the Trustless Work integration, runnable via the existing jest / test:integration scripts.
Requirements
Validate:
- Agreement creation → escrow write via
escrow-write.helper.ts (deployer/single-release, deployer/multi-release).
- Contract linking (
PATCH /agreements/:id/link-contract) and by-contract lookup.
- Status synchronization via webhook events (
escrow.funded, escrow.released, escrow.disputed, contract.completed, contract.cancelled).
- Milestone synchronization (
agreement.milestone_updated / escrow.milestone_updated).
- HMAC signature verification in
verifySignature() (valid + invalid signatures).
withRetry() behavior on transient failures (succeeds after N attempts; surfaces error after exhaustion).
- Idempotency (a duplicate webhook event does not double-apply a status change).
- Activity logging entries produced by synced transitions.
Validation System
- Each webhook event drives the final agreement to the expected status.
- Invalid HMAC signatures are rejected; valid ones pass.
- A transient-failure simulation recovers via
withRetry() and a persistent failure surfaces the error.
- Replaying the same event twice leaves the status unchanged after the first apply.
Technical Requirements
- Mock external TW calls (
relayToTrustless) and Supabase — do not hit live services.
- Simulate network/provider failures to exercise
withRetry().
- Validate synchronization integrity (final agreement status matches the event).
- Executable in CI via
pnpm test (respect testRegex: .*\.spec\.ts$).
Additional Notes
The original issue referenced a "retry queue" — there is no persistent queue in main, only in-request retry. Scope tests to the real webhook + withRetry design; if a durable queue is later added, extend the suite then.
Testing (required)
Proof of Completion (required)
Issue: Build Trustless Work End-to-End Test Suite
Depends on: Existing webhook sync (
src/webhooks/webhooks.service.ts) and escrow write helper (src/internal-trustless/escrow-write.helper.ts)Task Description
Develop an end-to-end test suite covering the integration between Thalos and Trustless Work (TW), validating that Agreements stay synchronized across their lifecycle under both success and failure scenarios. This must build on the existing Jest + supertest setup, not introduce a new framework.
Background / Current State
Verified against
main: synchronization is driven by inbound webhooks (POSThandled inwebhooks.service.ts), which map TW events to agreement status changes:escrow.funded → fundedescrow.released → completedescrow.disputed/dispute.created → disputedcontract.completed → completedcontract.cancelled → cancelledResilience today is a per-request
withRetry()helper, not a persistent retry queue. Tests must target this actual mechanism.Deliverable
End-to-end
*.spec.tstests covering the Trustless Work integration, runnable via the existingjest/test:integrationscripts.Requirements
Validate:
escrow-write.helper.ts(deployer/single-release,deployer/multi-release).PATCH /agreements/:id/link-contract) andby-contractlookup.escrow.funded,escrow.released,escrow.disputed,contract.completed,contract.cancelled).agreement.milestone_updated/escrow.milestone_updated).verifySignature()(valid + invalid signatures).withRetry()behavior on transient failures (succeeds after N attempts; surfaces error after exhaustion).Validation System
withRetry()and a persistent failure surfaces the error.Technical Requirements
relayToTrustless) and Supabase — do not hit live services.withRetry().pnpm test(respecttestRegex: .*\.spec\.ts$).Additional Notes
The original issue referenced a "retry queue" — there is no persistent queue in
main, only in-request retry. Scope tests to the real webhook +withRetrydesign; if a durable queue is later added, extend the suite then.Testing (required)
Proof of Completion (required)
pnpm testoutput showing the TW integration specs.