From 41e322c53d7b4b796eb377d0df9c29ecd10ba431 Mon Sep 17 00:00:00 2001 From: Chia Date: Thu, 6 Aug 2026 09:29:41 +1200 Subject: feat: complete commercial control plane, billing, auth, and model catalog - add PostgreSQL control-plane persistence with Redis-degraded hot reload - implement prepaid balance, usage ledger, Stripe top-up and reconciliation - add registration, email verification, password reset, invitations and RBAC - support TOTP, Passkey MFA, device sessions, quotas and rate limits - add tenant billing profiles, audit logs and operational readiness checks - build authenticated admin console, Quickstart, Playground and usage analytics - add public model catalog with pricing, filtering and cost estimation - support OpenAI Responses providers and provider health failover - validate real upstream usage reporting and balance settlement --- internal/controlplane/preferences_test.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 internal/controlplane/preferences_test.go (limited to 'internal/controlplane/preferences_test.go') diff --git a/internal/controlplane/preferences_test.go b/internal/controlplane/preferences_test.go new file mode 100644 index 0000000..88a3d50 --- /dev/null +++ b/internal/controlplane/preferences_test.go @@ -0,0 +1,31 @@ +package controlplane + +import ( + "context" + "testing" +) + +func TestGetTenantPreferencesWithoutTenantUsesConfiguredDefault(t *testing.T) { + result, err := (&Store{}).GetTenantPreferences(context.Background(), "", 12_500_000) + if err != nil { + t.Fatal(err) + } + if !result.LowBalanceEnabled || result.LowBalanceThresholdMicros != 12_500_000 { + t.Fatalf("unexpected defaults: %+v", result) + } +} + +func TestPreferenceValidationRejectsUnsafeValuesBeforeDatabaseAccess(t *testing.T) { + store := &Store{} + if _, err := store.SetDeveloperPreferences(context.Background(), SetDeveloperPreferencesInput{ + TenantID: "tenant", DefaultModel: "same", FallbackModel: "same", + }); err == nil { + t.Fatal("expected identical default and fallback models to fail") + } + threshold := maxLowBalanceThresholdMicros + 1 + if _, err := store.SetBillingPreferences(context.Background(), SetBillingPreferencesInput{ + TenantID: "tenant", LowBalanceThresholdMicros: &threshold, + }, 5_000_000); err == nil { + t.Fatal("expected excessive low balance threshold to fail") + } +} -- cgit v1.2.3