feat: orchestrate deterministic growth report generation

This commit is contained in:
2026-08-21 00:26:01 +03:30
parent 6df21d4fd0
commit 027dffb59e
11 changed files with 997 additions and 156 deletions

View File

@@ -0,0 +1,29 @@
package growthreport
import (
"context"
"errors"
"testing"
"time"
)
func TestCoordinatorFallsBackToBoundedProcessCounters(t *testing.T) {
t.Parallel()
coordinator := NewCoordinator(nil, CoordinatorConfig{CreatePerMinute: 2, UncachedPerDay: 1, DailyRequests: 1, DailyTokens: 1600, MaxConcurrent: 1})
now := time.Date(2026, 8, 21, 0, 0, 0, 0, time.UTC)
if err := coordinator.AllowCreate(context.Background(), 7, now); err != nil {
t.Fatal(err)
}
if err := coordinator.AllowCreate(context.Background(), 7, now); err != nil {
t.Fatal(err)
}
if err := coordinator.AllowCreate(context.Background(), 7, now); !errors.Is(err, ErrRateLimited) {
t.Fatalf("third request error=%v", err)
}
if err := coordinator.ReserveBudget(context.Background(), 1600, now); err != nil {
t.Fatal(err)
}
if err := coordinator.ReserveBudget(context.Background(), 1, now); !errors.Is(err, ErrBudgetExhausted) {
t.Fatalf("second budget error=%v", err)
}
}