checkpoint before checking out feature/account-managed-gateway
This commit is contained in:
@@ -48,6 +48,33 @@ class CreditServiceTest : FunSpec({
|
||||
) shouldBeExactly 4
|
||||
}
|
||||
|
||||
test("smaller production unit bills each started interval") {
|
||||
val productionAsr = asrRate(now).copy(asrMillisDenominator = 3_000)
|
||||
CreditCostCalculator.calculate(
|
||||
productionAsr,
|
||||
UsageMeasurement.Asr(durationMillis = 1),
|
||||
) shouldBeExactly 1
|
||||
CreditCostCalculator.calculate(
|
||||
productionAsr,
|
||||
UsageMeasurement.Asr(durationMillis = 3_000),
|
||||
) shouldBeExactly 1
|
||||
CreditCostCalculator.calculate(
|
||||
productionAsr,
|
||||
UsageMeasurement.Asr(durationMillis = 3_001),
|
||||
) shouldBeExactly 2
|
||||
|
||||
val productionLlm = llmRate(now).copy(
|
||||
inputCreditsNumerator = 1,
|
||||
inputTokensDenominator = 1_000,
|
||||
outputCreditsNumerator = 1,
|
||||
outputTokensDenominator = 400,
|
||||
)
|
||||
CreditCostCalculator.calculate(
|
||||
productionLlm,
|
||||
UsageMeasurement.Llm(inputTokens = 1_001, outputTokens = 401),
|
||||
) shouldBeExactly 4
|
||||
}
|
||||
|
||||
test("cost calculation avoids intermediate overflow and rejects an unrepresentable result") {
|
||||
CreditCostCalculator.calculate(
|
||||
asrRate(now).copy(
|
||||
@@ -602,6 +629,43 @@ class CreditServiceTest : FunSpec({
|
||||
} shouldBe true
|
||||
}
|
||||
|
||||
test("account summary reports settled usage separately from remaining credits") {
|
||||
val store = storeWithRates(now)
|
||||
val service = service(store, now)
|
||||
val userId = UUID.randomUUID()
|
||||
service.grantSignupTrial(userId, 100, "summary-signup-key")
|
||||
val reservation = service.reserve(
|
||||
userId,
|
||||
"asr-provider",
|
||||
"asr-model",
|
||||
UsageMeasurement.Asr(1_000),
|
||||
managedCall = false,
|
||||
idempotencyKey = "summary-reserve-key",
|
||||
)
|
||||
val reservedSummary = service.getAccountSummary(userId)
|
||||
|
||||
reservedSummary.account.balance shouldBeExactly 90
|
||||
reservedSummary.lifetimeUsed shouldBeExactly 0
|
||||
|
||||
service.settle(
|
||||
userId,
|
||||
reservation.id,
|
||||
UsageMeasurement.Asr(500),
|
||||
"summary-settle-key",
|
||||
)
|
||||
|
||||
val summary = service.getAccountSummary(userId)
|
||||
|
||||
summary.account.balance shouldBeExactly 95
|
||||
summary.lifetimeUsed shouldBeExactly 5
|
||||
|
||||
service.refund(userId, reservation.id, "summary-refund-key")
|
||||
val refundedSummary = service.getAccountSummary(userId)
|
||||
|
||||
refundedSummary.account.balance shouldBeExactly 100
|
||||
refundedSummary.lifetimeUsed shouldBeExactly 0
|
||||
}
|
||||
|
||||
test("release and refund restore only the corresponding debit") {
|
||||
val store = storeWithRates(now)
|
||||
val service = service(store, now)
|
||||
|
||||
Reference in New Issue
Block a user