test(chat): add ContextUsageComponentsTest regression tests and clarify context tokens note
This commit is contained in:
1 parent
6fe62f9646
commit
02e14a4ab4
4 files changed
+111
-3
No files matched your search
+108
@@ -0,0 +1,108 @@
|
||||
package com.m57.hermescontrol.ui.chat.components
|
||||
|
||||
import androidx.compose.ui.test.assertIsDisplayed
|
||||
import androidx.compose.ui.test.junit4.createComposeRule
|
||||
import androidx.compose.ui.test.onNodeWithText
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import androidx.test.filters.MediumTest
|
||||
import com.m57.hermescontrol.theme.HermesControlTheme
|
||||
import com.m57.hermescontrol.ui.chat.ContextBreakdown
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
/**
|
||||
* Regression coverage for backend-reported context occupancy.
|
||||
*
|
||||
* Cumulative REST input-token accounting must never masquerade as the live
|
||||
* context-window numerator when the backend has not reported context_used.
|
||||
*/
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
@MediumTest
|
||||
class ContextUsageComponentsTest {
|
||||
@get:Rule
|
||||
val composeTestRule = createComposeRule()
|
||||
|
||||
@Test
|
||||
fun chip_missingBackendOccupancy_doesNotShowFakeZeroPercent() {
|
||||
composeTestRule.setContent {
|
||||
HermesControlTheme {
|
||||
ContextUsageChip(
|
||||
usedTokens = null,
|
||||
fullTokens = 128_000L,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
composeTestRule
|
||||
.onNodeWithText("— / 128k context")
|
||||
.assertIsDisplayed()
|
||||
|
||||
composeTestRule
|
||||
.onNodeWithText("0%")
|
||||
.assertDoesNotExist()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun chip_backendOccupancyAvailable_showsDeterminateUsage() {
|
||||
composeTestRule.setContent {
|
||||
HermesControlTheme {
|
||||
ContextUsageChip(
|
||||
usedTokens = 64_000L,
|
||||
fullTokens = 128_000L,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
composeTestRule
|
||||
.onNodeWithText("64k / 128k context")
|
||||
.assertIsDisplayed()
|
||||
|
||||
composeTestRule
|
||||
.onNodeWithText("50%")
|
||||
.assertIsDisplayed()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun detailSheet_missingBackendOccupancy_doesNotUseCumulativeInputTokensAsNumerator() {
|
||||
composeTestRule.setContent {
|
||||
HermesControlTheme {
|
||||
ContextDetailSheet(
|
||||
breakdown =
|
||||
ContextBreakdown(
|
||||
inputTokens = 12_300L,
|
||||
outputTokens = 2_000L,
|
||||
cacheReadTokens = 500L,
|
||||
cacheWriteTokens = 250L,
|
||||
reasoningTokens = 100L,
|
||||
messageCount = 4,
|
||||
),
|
||||
usedTokens = null,
|
||||
fullTokens = 128_000L,
|
||||
onDismiss = {},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// The live numerator is unavailable, even though cumulative REST
|
||||
// input-token accounting exists below in the detail breakdown.
|
||||
composeTestRule
|
||||
.onNodeWithText("—")
|
||||
.assertIsDisplayed()
|
||||
|
||||
composeTestRule
|
||||
.onNodeWithText("Context window usage unavailable")
|
||||
.assertIsDisplayed()
|
||||
|
||||
// Cumulative accounting is still preserved as informational detail.
|
||||
composeTestRule
|
||||
.onNodeWithText("12.3k")
|
||||
.assertIsDisplayed()
|
||||
|
||||
// Most important regression guard: null occupancy is not rendered as
|
||||
// a determinate zero-percent context state.
|
||||
composeTestRule
|
||||
.onNodeWithText("0% of context window used")
|
||||
.assertDoesNotExist()
|
||||
}
|
||||
}
|
||||
@@ -1308,7 +1308,7 @@
|
||||
<string name="context_completion_output">الإكمال (المخرجات)</string>
|
||||
<string name="context_compressed">مضغوط ×%1$s</string>
|
||||
<string name="context_prompt_input">المطالبة (المدخلات)</string>
|
||||
<string name="context_tokens_note">تعكس رموز المطالبة إجمالي السياق المستخدم في هذه الجلسة حتى الآن.</string>
|
||||
<string name="context_tokens_note">أعداد الرموز أدناه تراكمية للجلسة ولا تمثل الاستخدام الحالي لنافذة السياق.</string>
|
||||
<string name="context_window">نافذة السياق</string>
|
||||
<string name="context_window_usage_unavailable">استخدام نافذة السياق غير متوفر</string>
|
||||
<string name="gif_play">تشغيل GIF</string>
|
||||
|
||||
@@ -1275,7 +1275,7 @@
|
||||
<string name="context_completion_output">补全(输出)</string>
|
||||
<string name="context_compressed">已压缩 ×%1$s</string>
|
||||
<string name="context_prompt_input">提示词(输入)</string>
|
||||
<string name="context_tokens_note">提示词 token 反映此会话迄今使用的总上下文。</string>
|
||||
<string name="context_tokens_note">下方 token 数为会话累计用量,不代表当前上下文窗口占用。</string>
|
||||
<string name="context_window">上下文窗口</string>
|
||||
<string name="context_window_usage_unavailable">上下文窗口使用量不可用</string>
|
||||
<string name="gif_play">播放 GIF</string>
|
||||
|
||||
@@ -1435,7 +1435,7 @@
|
||||
<string name="context_completion_output">Completion (output)</string>
|
||||
<string name="context_compressed">compressed ×%1$s</string>
|
||||
<string name="context_prompt_input">Prompt (input)</string>
|
||||
<string name="context_tokens_note">Prompt tokens reflect total context used by this session so far.</string>
|
||||
<string name="context_tokens_note">Token counts below are cumulative session accounting and do not represent current context-window occupancy.</string>
|
||||
<string name="context_window">Context window</string>
|
||||
<string name="context_window_usage_unavailable">Context window usage unavailable</string>
|
||||
<string name="gif_play">Play GIF</string>
|
||||
|
||||
Reference in new issue
Block a user