Six services, independently built then integrated: - services/wal (C): crash-safe write-ahead log, CRC32-checksummed frames, torn-write recovery via truncate-to-last-valid-frame. - services/ledger-core (Rust): double-entry ledger over the C WAL via FFI, reserve-floor enforcement BEFORE any WAL write, idempotent ApplyEntry, full LedgerCore gRPC service. - services/gateway (Go): Airwallex Issuing/Global-Accounts client (mock mode default, live mode ready), the actual rationing math (reserve floor, 60% bridge cap, 24h velocity cap, partial-over-decline). - services/agent (Go): deterministic hard-rule policy envelope computed BEFORE any LLM call; Claude only decides within that pre-approved envelope; every decision audit-logged even when the LLM call fails. - services/tui (Go, Bubble Tea) + services/cli (Go, cobra): the only UI — no web frontend, per explicit direction. Integration found and fixed three real bugs, not just compile errors: - proto regen collision shadowing checked-in pkg/pb packages - ledger-core/gateway address-variable mismatch (stack would never actually connect on default config) - the big one: MarkDepositReceived never credited the ledger, so every tenant's balance was permanently stuck at 0 and bridge-funding could only ever decline — the core agentic-rationing feature could never produce a real grant. Fixed at the ledger level with idempotent mark-and-credit in one WAL frame, covered by 3 new tests. End-to-end verified live, reproducibly: seed -> simulate a late deposit -> agent grants a partial bridge with a computed rationale -> second grant correctly declines once the 24h velocity cap engages. Verified independently by the orchestrator too: 'make build' and 'make test' both clean (Rust: 29 tests; Go: all packages; C: WAL test suite). Airwallex sandbox credentials still pending organizer approval — tracked as an owner blocker in docs/AIRWALLEX-SETUP.md, not a code gap.
73 lines
2.3 KiB
Go
73 lines
2.3 KiB
Go
package depositsim
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
var fixedNow = time.Date(2026, time.October, 19, 12, 0, 0, 0, time.UTC)
|
|
|
|
func TestResolve_OnTime_DefaultsToFutureExpectedAt(t *testing.T) {
|
|
got := Resolve(Options{Now: fixedNow, Late: false})
|
|
|
|
if got.MarkLate {
|
|
t.Errorf("on-time deposit must not set MarkLate")
|
|
}
|
|
wantUnix := fixedNow.Add(DefaultExpectedIn).Unix()
|
|
if got.ExpectedAtUnix != wantUnix {
|
|
t.Errorf("ExpectedAtUnix = %d, want %d (now + DefaultExpectedIn)", got.ExpectedAtUnix, wantUnix)
|
|
}
|
|
if got.ExpectedAtUnix <= fixedNow.Unix() {
|
|
t.Errorf("on-time deposit's expected_at_unix %d must be after now %d", got.ExpectedAtUnix, fixedNow.Unix())
|
|
}
|
|
}
|
|
|
|
func TestResolve_Late_BackdatesExpectedAtAndSetsMarkLate(t *testing.T) {
|
|
got := Resolve(Options{Now: fixedNow, Late: true})
|
|
|
|
if !got.MarkLate {
|
|
t.Errorf("--late deposit must set MarkLate")
|
|
}
|
|
wantUnix := fixedNow.Add(-DefaultLateBy).Unix()
|
|
if got.ExpectedAtUnix != wantUnix {
|
|
t.Errorf("ExpectedAtUnix = %d, want %d (now - DefaultLateBy)", got.ExpectedAtUnix, wantUnix)
|
|
}
|
|
if got.ExpectedAtUnix >= fixedNow.Unix() {
|
|
t.Errorf("late deposit's expected_at_unix %d must be before now %d so it is already overdue", got.ExpectedAtUnix, fixedNow.Unix())
|
|
}
|
|
}
|
|
|
|
func TestResolve_HonorsCustomExpectedIn(t *testing.T) {
|
|
custom := 6 * time.Hour
|
|
got := Resolve(Options{Now: fixedNow, Late: false, ExpectedIn: custom})
|
|
|
|
want := fixedNow.Add(custom).Unix()
|
|
if got.ExpectedAtUnix != want {
|
|
t.Errorf("ExpectedAtUnix = %d, want %d", got.ExpectedAtUnix, want)
|
|
}
|
|
}
|
|
|
|
func TestResolve_HonorsCustomLateBy(t *testing.T) {
|
|
custom := 72 * time.Hour
|
|
got := Resolve(Options{Now: fixedNow, Late: true, LateBy: custom})
|
|
|
|
want := fixedNow.Add(-custom).Unix()
|
|
if got.ExpectedAtUnix != want {
|
|
t.Errorf("ExpectedAtUnix = %d, want %d", got.ExpectedAtUnix, want)
|
|
}
|
|
}
|
|
|
|
func TestResolve_NonPositiveDurationsFallBackToDefaults(t *testing.T) {
|
|
got := Resolve(Options{Now: fixedNow, Late: false, ExpectedIn: -time.Hour})
|
|
want := fixedNow.Add(DefaultExpectedIn).Unix()
|
|
if got.ExpectedAtUnix != want {
|
|
t.Errorf("ExpectedAtUnix = %d, want default-based %d", got.ExpectedAtUnix, want)
|
|
}
|
|
|
|
gotLate := Resolve(Options{Now: fixedNow, Late: true, LateBy: 0})
|
|
wantLate := fixedNow.Add(-DefaultLateBy).Unix()
|
|
if gotLate.ExpectedAtUnix != wantLate {
|
|
t.Errorf("ExpectedAtUnix = %d, want default-based %d", gotLate.ExpectedAtUnix, wantLate)
|
|
}
|
|
}
|