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.
50 lines
1.4 KiB
Go
50 lines
1.4 KiB
Go
package view
|
|
|
|
import "testing"
|
|
|
|
func TestVisibleWindow(t *testing.T) {
|
|
cases := []struct {
|
|
name string
|
|
total, cursor, height int
|
|
wantStart, wantEnd int
|
|
}{
|
|
{"fits entirely", 3, 0, 10, 0, 3},
|
|
{"zero total", 0, 0, 10, 0, 0},
|
|
{"zero height", 5, 0, 0, 0, 0},
|
|
{"cursor at top", 20, 0, 5, 0, 5},
|
|
{"cursor in middle", 20, 10, 5, 8, 13},
|
|
{"cursor near end clamps window", 20, 19, 5, 15, 20},
|
|
{"cursor beyond total clamps", 20, 50, 5, 15, 20},
|
|
{"negative cursor clamps to 0", 20, -5, 5, 0, 5},
|
|
}
|
|
for _, tc := range cases {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
start, end := visibleWindow(tc.total, tc.cursor, tc.height)
|
|
if start != tc.wantStart || end != tc.wantEnd {
|
|
t.Errorf("visibleWindow(%d, %d, %d) = (%d, %d), want (%d, %d)",
|
|
tc.total, tc.cursor, tc.height, start, end, tc.wantStart, tc.wantEnd)
|
|
}
|
|
if end-start > tc.height && tc.height > 0 {
|
|
t.Errorf("window size %d exceeds height %d", end-start, tc.height)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestActivityEmpty(t *testing.T) {
|
|
got := Activity(nil, 0, 10)
|
|
if got == "" {
|
|
t.Fatal("Activity with no rows should render a waiting placeholder")
|
|
}
|
|
}
|
|
|
|
func TestActivityRendersRows(t *testing.T) {
|
|
rows := []ActivityRow{
|
|
{ID: "1", TenantName: "Acme", Kind: "deposit", Summary: "received $100", AtUnix: 1609459200},
|
|
}
|
|
got := Activity(rows, 0, 10)
|
|
if got == "" {
|
|
t.Fatal("expected non-empty render")
|
|
}
|
|
}
|