78 lines
2.7 KiB
Go
78 lines
2.7 KiB
Go
package growthreport
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestRequestHashIsStableAndScopeSensitive(t *testing.T) {
|
|
t.Parallel()
|
|
a := RequestHash(7, "T-1", false)
|
|
if a != RequestHash(7, "T-1", false) {
|
|
t.Fatal("RequestHash() is not stable")
|
|
}
|
|
if a == RequestHash(7, "T-2", false) || a == RequestHash(7, "T-1", true) {
|
|
t.Fatal("RequestHash() ignored request scope")
|
|
}
|
|
}
|
|
|
|
func TestNextTehranRefreshUsesCalendarBoundary(t *testing.T) {
|
|
t.Parallel()
|
|
now := time.Date(2026, 8, 21, 20, 0, 0, 0, time.UTC)
|
|
next := NextTehranRefresh(now)
|
|
location, _ := time.LoadLocation("Asia/Tehran")
|
|
local := next.In(location)
|
|
if local.Hour() != 0 || local.Minute() != 0 || !next.After(now) {
|
|
t.Fatalf("NextTehranRefresh() = %s", next)
|
|
}
|
|
}
|
|
|
|
func TestTehranTodayUsesClockInsteadOfDatasetWatermark(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
now := time.Date(2026, time.August, 21, 8, 30, 0, 0, time.UTC)
|
|
got := tehranToday(now)
|
|
if got.Format(time.DateOnly) != "2026-08-21" {
|
|
t.Fatalf("tehranToday() = %s", got.Format(time.DateOnly))
|
|
}
|
|
}
|
|
|
|
func TestEstimatedTokenReservationCoversEveryRetryAndTurn(t *testing.T) {
|
|
t.Parallel()
|
|
small := EstimatedTokenReservation([]byte("{}"))
|
|
large := EstimatedTokenReservation(make([]byte, 1000))
|
|
if MaxProviderRequests != 10 || small < MaxProviderRequests*4096 || large <= small || large != 134960 {
|
|
t.Fatalf("reservations small=%d large=%d", small, large)
|
|
}
|
|
}
|
|
|
|
func TestDeterministicOnlyCompletionReflectsCandidateAvailability(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
status, failure := deterministicCompletion(true)
|
|
if status != StatusReady || failure != "" {
|
|
t.Fatalf("deterministicCompletion() = (%q, %q), want (%q, empty)", status, failure, StatusReady)
|
|
}
|
|
status, failure = deterministicCompletion(false)
|
|
if status != StatusPartial || failure != "INSUFFICIENT_EVENT_CANDIDATES" {
|
|
t.Fatalf("deterministicCompletion(false) = (%q, %q), want (%q, INSUFFICIENT_EVENT_CANDIDATES)", status, failure, StatusPartial)
|
|
}
|
|
}
|
|
|
|
func TestServiceFingerprintChangesWithDatasetAndConfiguration(t *testing.T) {
|
|
t.Parallel()
|
|
start := time.Date(2026, 8, 21, 0, 0, 0, 0, time.UTC)
|
|
service := &Service{config: ServiceConfig{Model: "model-a", PromptVersion: "prompt-a", SchemaVersion: "schema-a"}}
|
|
current := service.fingerprint(7, "T-1", "watermark-a", "catalog-a", start)
|
|
if current == service.fingerprint(7, "T-1", "watermark-b", "catalog-a", start) {
|
|
t.Fatal("dataset watermark did not invalidate fingerprint")
|
|
}
|
|
if current == service.fingerprint(7, "T-1", "watermark-a", "catalog-b", start) {
|
|
t.Fatal("catalog version did not invalidate fingerprint")
|
|
}
|
|
service.config.PromptVersion = "prompt-b"
|
|
if current == service.fingerprint(7, "T-1", "watermark-a", "catalog-a", start) {
|
|
t.Fatal("prompt version did not invalidate fingerprint")
|
|
}
|
|
}
|