mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-12-01 13:34:33 +00:00
feat(sessions): show token usage and estimated cost in logs (#557)
* feat(sessions): show token usage and estimated cost in logs * fix(sessions): compact the usage footer * fix(ci): bypass Bun cache for Windows ARM64
This commit is contained in:
@@ -67,7 +67,7 @@ apps/web/e2e/
|
||||
| Owner changes a team member role in the members dialog and permissions update | `tests/team/change-member-role.spec.ts` |
|
||||
| Owner manages resource quotas in settings and resets usage from the dashboard | `tests/team/quotas-settings.spec.ts` |
|
||||
| Owner creates an API token that is shown once, listed by hint, and authenticates API calls | `tests/team/api-tokens.spec.ts` |
|
||||
| Session logs stay within the dialog and scroll through long messages and expanded records on desktop and narrow screens | `tests/team/agent-session-logs.spec.ts` |
|
||||
| Session logs scroll through long messages and expanded records with the usage footer pinned and the token breakdown available on desktop and narrow screens | `tests/team/agent-session-logs.spec.ts` |
|
||||
| Provider cards open the editor by click and keyboard, keep menu actions independent, and show a scrollable model preview on desktop and mobile | `tests/team/provider-model-refresh.spec.ts` |
|
||||
|
||||
### project
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { expect, test } from '../../fixtures'
|
||||
|
||||
test('session logs stay within the dialog and scroll through long messages and expanded records', async ({
|
||||
test('session logs scroll with usage pinned below long messages and expanded records', async ({
|
||||
owner,
|
||||
prisma,
|
||||
}) => {
|
||||
@@ -25,6 +25,13 @@ test('session logs stay within the dialog and scroll through long messages and e
|
||||
type: 'chat',
|
||||
name: 'Scrollable Session Logs',
|
||||
cwd: '/test',
|
||||
accountedUsage: {
|
||||
inputTokens: 12800,
|
||||
outputTokens: 1580,
|
||||
cacheReadTokens: 10000,
|
||||
totalTokens: 24380,
|
||||
cost: 0.014,
|
||||
},
|
||||
},
|
||||
})
|
||||
await prisma.agentSessionCommit.create({
|
||||
@@ -64,6 +71,10 @@ test('session logs stay within the dialog and scroll through long messages and e
|
||||
await expect(dialog.getByText(/^(Entry ID|条目 ID):/)).toHaveCount(0)
|
||||
const viewport = dialog.locator('[data-slot="scroll-area-viewport"]')
|
||||
const heading = dialog.getByRole('heading')
|
||||
const footer = dialog.locator('footer')
|
||||
const breakdown = footer.getByRole('button', { name: /^(Breakdown|明细|상세 내역)$/ })
|
||||
await expect(footer).toContainText('24,380')
|
||||
await expect(footer).toContainText('$0.014')
|
||||
|
||||
for (const size of [
|
||||
{ width: 1280, height: 800 },
|
||||
@@ -97,6 +108,7 @@ test('session logs stay within the dialog and scroll through long messages and e
|
||||
)
|
||||
.toBe(true)
|
||||
const headerTop = (await heading.boundingBox())!.y
|
||||
const footerTop = (await footer.boundingBox())!.y
|
||||
await viewport.evaluate((element) => {
|
||||
element.scrollTop = 0
|
||||
})
|
||||
@@ -110,6 +122,26 @@ test('session logs stay within the dialog and scroll through long messages and e
|
||||
})
|
||||
await expect(record.locator('summary')).toBeInViewport()
|
||||
expect((await heading.boundingBox())!.y).toBeCloseTo(headerTop, 0)
|
||||
expect((await footer.boundingBox())!.y).toBeCloseTo(footerTop, 0)
|
||||
await expect(footer).toBeInViewport()
|
||||
|
||||
await breakdown.click()
|
||||
const popover = page.getByRole('dialog', {
|
||||
name: /Token breakdown|Token 用量明细|토큰 사용량 상세 내역/,
|
||||
})
|
||||
await expect(popover).toBeVisible()
|
||||
for (const count of ['12,800', '1,580', '10,000']) {
|
||||
await expect(popover.getByText(count, { exact: true })).toBeVisible()
|
||||
}
|
||||
await expect
|
||||
.poll(async () => {
|
||||
const bounds = await popover.boundingBox()
|
||||
return bounds ? bounds.y + bounds.height : Infinity
|
||||
})
|
||||
.toBeLessThan(footerTop + 1)
|
||||
await page.keyboard.press('Escape')
|
||||
await expect(popover).toBeHidden()
|
||||
await expect(breakdown).toBeFocused()
|
||||
|
||||
await record.locator('summary').click()
|
||||
await viewport.evaluate((element) => {
|
||||
|
||||
Reference in New Issue
Block a user