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.
57 lines
1.2 KiB
Go
57 lines
1.2 KiB
Go
package view
|
|
|
|
import "testing"
|
|
|
|
func TestPadCell(t *testing.T) {
|
|
cases := []struct {
|
|
s string
|
|
width int
|
|
want string
|
|
}{
|
|
{"abc", 5, "abc "},
|
|
{"abc", 3, "abc"},
|
|
{"abcdef", 3, "ab…"},
|
|
{"", 4, " "},
|
|
{"abc", 0, ""},
|
|
{"abc", -1, ""},
|
|
}
|
|
for _, tc := range cases {
|
|
got := padCell(tc.s, tc.width)
|
|
if got != tc.want {
|
|
t.Errorf("padCell(%q, %d) = %q (len %d), want %q (len %d)", tc.s, tc.width, got, len([]rune(got)), tc.want, len([]rune(tc.want)))
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestRenderRow(t *testing.T) {
|
|
got := renderRow([]string{"a", "bb"}, []int{3, 3})
|
|
want := "a " + columnGap + "bb "
|
|
if got != want {
|
|
t.Errorf("renderRow = %q, want %q", got, want)
|
|
}
|
|
}
|
|
|
|
func TestTotalWidth(t *testing.T) {
|
|
cases := []struct {
|
|
widths []int
|
|
want int
|
|
}{
|
|
{[]int{5}, 5},
|
|
{[]int{5, 5}, 5 + len([]rune(columnGap)) + 5},
|
|
{nil, 1},
|
|
}
|
|
for _, tc := range cases {
|
|
got := totalWidth(tc.widths)
|
|
if got != tc.want {
|
|
t.Errorf("totalWidth(%v) = %d, want %d", tc.widths, got, tc.want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestTableEmptyRows(t *testing.T) {
|
|
got := Table([]string{"A", "B"}, nil, []int{3, 3}, 0, -1, nil)
|
|
if got == "" {
|
|
t.Fatal("Table with no rows should still render headers + placeholder")
|
|
}
|
|
}
|