91 lines
2.7 KiB
Kotlin
91 lines
2.7 KiB
Kotlin
package com.example.aiapp
|
|
|
|
import kotlin.test.Test
|
|
import kotlin.test.assertEquals
|
|
|
|
class SessionUsageTest {
|
|
@Test
|
|
fun `usage snapshots stay with the session's machine and provider`() {
|
|
val claude = snapshot("machine", "claude", null)
|
|
val codex = snapshot("machine", "codex", "codex")
|
|
val reserve = snapshot("machine", "codex", "gpt-reserve")
|
|
val elsewhere = snapshot("other", "codex", "codex")
|
|
|
|
assertEquals(
|
|
listOf(codex, reserve),
|
|
usageSnapshotsFor(
|
|
listOf(claude, codex, reserve, elsewhere),
|
|
machine = "machine",
|
|
provider = "codex",
|
|
),
|
|
)
|
|
}
|
|
|
|
@Test
|
|
fun `a session without a meter has no usage snapshots`() {
|
|
assertEquals(
|
|
emptyList(),
|
|
usageSnapshotsFor(
|
|
listOf(snapshot("machine", "claude", null)),
|
|
machine = "machine",
|
|
provider = null,
|
|
),
|
|
)
|
|
}
|
|
|
|
@Test
|
|
fun `the model selects its named pool and other models use the generic pool`() {
|
|
val generic = snapshot("machine", "codex", "codex")
|
|
val spark =
|
|
snapshot(
|
|
"machine",
|
|
"codex",
|
|
"codex_bengalfox",
|
|
limitName = "GPT-5.3-Codex-Spark",
|
|
)
|
|
val reserve =
|
|
snapshot("machine", "codex", "base_model_inference", limitName = "gpt-reserve")
|
|
val pools = listOf(generic, spark, reserve)
|
|
|
|
assertEquals(spark, usagePoolFor(pools, "gpt-5.3-codex-spark"))
|
|
assertEquals(reserve, usagePoolFor(pools, "gpt-5.6-luna"))
|
|
assertEquals(generic, usagePoolFor(pools, "gpt-6-astra"))
|
|
}
|
|
|
|
@Test
|
|
fun `the bar uses the shortest reported cycle`() {
|
|
val weekly = window("Weekly", 10_080)
|
|
val hourly = window("5-hour window", 300)
|
|
|
|
assertEquals(hourly, shortestUsageWindow(listOf(weekly, hourly)))
|
|
assertEquals(null, shortestUsageWindow(listOf(window("unknown", null))))
|
|
}
|
|
|
|
private fun snapshot(
|
|
machine: String,
|
|
provider: String,
|
|
limitId: String?,
|
|
limitName: String? = null,
|
|
) =
|
|
UsageSnapshot(
|
|
provider = provider,
|
|
machine = machine,
|
|
machineName = machine,
|
|
limitId = limitId,
|
|
limitName = limitName,
|
|
state = "ok",
|
|
detail = null,
|
|
windows = emptyList(),
|
|
)
|
|
|
|
private fun window(label: String, durationMinutes: Long?) =
|
|
UsageWindow(
|
|
kind = "test",
|
|
label = label,
|
|
percent = 12.0,
|
|
durationMinutes = durationMinutes,
|
|
resetsAt = null,
|
|
active = false,
|
|
)
|
|
}
|