Fix explorer back and session usage selection
This commit is contained in:
1 parent
8c88a7e991
commit
14dd520719
10 files changed
+222
-57
No files matched your search
@@ -0,0 +1,90 @@
|
||||
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),
|
||||
setup = "machine",
|
||||
provider = "codex",
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a session without a meter has no usage snapshots`() {
|
||||
assertEquals(
|
||||
emptyList(),
|
||||
usageSnapshotsFor(
|
||||
listOf(snapshot("machine", "claude", null)),
|
||||
setup = "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(
|
||||
setup: String,
|
||||
provider: String,
|
||||
limitId: String?,
|
||||
limitName: String? = null,
|
||||
) =
|
||||
UsageSnapshot(
|
||||
provider = provider,
|
||||
setup = setup,
|
||||
setupName = setup,
|
||||
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,
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user