caelum0x 2b686594a3 feat: Ration phase 1 — full polyglot build for Airwallex Starter Kit 5
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.
2026-10-19 03:04:13 +03:00

71 lines
2.2 KiB
Go

package demoseed
import "testing"
func TestTenants_ReturnsThreeDistinctTenants(t *testing.T) {
tenants := Tenants()
if len(tenants) != 3 {
t.Fatalf("want 3 demo tenants, got %d", len(tenants))
}
seenNames := make(map[string]bool, len(tenants))
for _, tenant := range tenants {
if tenant.Name == "" {
t.Errorf("tenant has empty name: %+v", tenant)
}
if len(tenant.Currency) != 3 {
t.Errorf("tenant %q currency %q is not a 3-letter ISO 4217 code", tenant.Name, tenant.Currency)
}
if tenant.ReserveFloorMinorUnits <= 0 {
t.Errorf("tenant %q reserve floor must be positive, got %d", tenant.Name, tenant.ReserveFloorMinorUnits)
}
if seenNames[tenant.Name] {
t.Errorf("duplicate tenant name %q", tenant.Name)
}
seenNames[tenant.Name] = true
}
}
func TestTenants_OpeningCapitalExceedsReserveFloor(t *testing.T) {
// The whole point of OpeningCapitalMinorUnits: a freshly seeded
// tenant must start with real headroom (available balance above its
// reserve floor), or the agent's bridge envelope can only ever
// decline, no matter what late-deposit scenario a judge runs next.
for _, tenant := range Tenants() {
if tenant.OpeningCapitalMinorUnits <= tenant.ReserveFloorMinorUnits {
t.Errorf(
"tenant %q: opening capital %d must exceed reserve floor %d, or it starts with zero headroom",
tenant.Name, tenant.OpeningCapitalMinorUnits, tenant.ReserveFloorMinorUnits,
)
}
}
}
func TestTenants_SpanSmallMediumLarge(t *testing.T) {
tenants := Tenants()
for i := 1; i < len(tenants); i++ {
if tenants[i].ReserveFloorMinorUnits <= tenants[i-1].ReserveFloorMinorUnits {
t.Fatalf(
"expected strictly increasing reserve floors (small -> medium -> large), got %d then %d",
tenants[i-1].ReserveFloorMinorUnits, tenants[i].ReserveFloorMinorUnits,
)
}
}
}
func TestTenants_IsDeterministic(t *testing.T) {
first := Tenants()
second := Tenants()
if len(first) != len(second) {
t.Fatalf("Tenants() returned different lengths across calls: %d vs %d", len(first), len(second))
}
for i := range first {
if first[i] != second[i] {
t.Errorf("Tenants() is not deterministic at index %d: %+v vs %+v", i, first[i], second[i])
}
}
}