feat: add durable Kuknos settlement coordination

This commit is contained in:
Navid
2026-09-15 13:59:13 +03:30
parent d5c9b338a4
commit 12c478cf3a
34 changed files with 1846 additions and 122 deletions
@@ -0,0 +1,41 @@
package postgres
import (
"context"
"testing"
"time"
)
func TestReconcileConfirmationEvidenceCommitsDurableIssueStats(t *testing.T) {
tx := &fakeTx{rows: []Row{
fakeRow{values: []any{int64(1)}},
fakeRow{values: []any{int64(2)}},
}}
repository := NewSettlementRepository(&fakeDatabase{tx: tx})
stats, err := repository.ReconcileConfirmationEvidence(context.Background(), 10*time.Minute)
if err != nil {
t.Fatal(err)
}
if stats.Detected != 1 || stats.Resolved != 1 || stats.Open != 2 {
t.Fatalf("unexpected reconciliation stats: %+v", stats)
}
if !tx.committed || tx.execCount != 1 {
t.Fatalf("unexpected transaction state: %+v", tx)
}
}
func TestReconcileConfirmationEvidenceRollsBackResolutionFailure(t *testing.T) {
tx := &fakeTx{
rows: []Row{fakeRow{values: []any{int64(1)}}},
execErrAt: 1,
}
repository := NewSettlementRepository(&fakeDatabase{tx: tx})
if _, err := repository.ReconcileConfirmationEvidence(context.Background(), time.Minute); err == nil {
t.Fatal("expected resolution error")
}
if !tx.rolledBack || tx.committed {
t.Fatalf("failed reconciliation was not rolled back: %+v", tx)
}
}