Files
hermes-ui/tests/client/tool-trace-visibility.test.ts
toor 1e9ea89d86
Build / build (push) Canceled after 0s
NPM Lockfile Check / npm ci --ignore-scripts (push) Canceled after 0s
Playwright / e2e (push) Canceled after 0s
chore: bootstrap hermes-ui skeleton from 0.6.29 snapshot
Import the client, server, skills, tests, and build scripts as the starting
point for the rebuild, then trim the surfaces this project does not ship:
Electron desktop packaging, the marketing website, and the ESP32 firmware
tree. CI keeps the web build, e2e, lockfile, release, and Docker workflows.

Rename the package and CLI entry points to hermes-ui, drop the prepare hook so
npm ci no longer triggers a build, and drop the removed tsconfig and nodemon
references. Rewrite AGENTS.md, ARCHITECTURE.md, DEVELOPMENT.md, and the READMEs
so the documented package map and hard rules match this repository.

reference_code/ is ignored: it is a read-only snapshot, not an input to the build.
2026-10-16 10:34:35 +08:00

157 lines
5.2 KiB
TypeScript

// @vitest-environment jsdom
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { mount } from '@vue/test-utils'
import { createPinia, setActivePinia } from 'pinia'
import { defineComponent } from 'vue'
vi.mock('vue-i18n', () => ({
useI18n: () => ({
t: (key: string) => key,
}),
}))
vi.mock('@/composables/useTheme', () => ({
useTheme: () => ({ isDark: false }),
}))
import MessageList from '@/components/hermes/chat/MessageList.vue'
import HistoryMessageList from '@/components/hermes/chat/HistoryMessageList.vue'
import { useChatStore, type Message, type Session } from '@/stores/hermes/chat'
import { useToolTraceVisibility } from '@/composables/useToolTraceVisibility'
const MessageItemStub = defineComponent({
name: 'MessageItem',
props: {
message: { type: Object, required: true },
highlight: { type: Boolean, default: false },
},
template: '<div class="stub-message" :data-role="message.role" :data-id="message.id">{{ message.toolName || message.content }}</div>',
})
function makeSession(messages: Message[]): Session {
return {
id: 'session-1',
title: 'Tool trace visibility',
messages,
createdAt: Date.now(),
updatedAt: Date.now(),
}
}
const sampleMessages: Message[] = [
{ id: 'user-1', role: 'user', content: 'inspect repo', timestamp: 1 },
{ id: 'tool-named', role: 'tool', content: '', timestamp: 2, toolName: 'read_file', toolResult: 'ok', toolStatus: 'done' },
{ id: 'tool-internal', role: 'tool', content: '', timestamp: 3, toolResult: 'internal', toolStatus: 'done' },
{ id: 'assistant-1', role: 'assistant', content: 'done', timestamp: 4 },
]
describe('tool trace visibility', () => {
beforeEach(() => {
setActivePinia(createPinia())
localStorage.removeItem('hermes_show_tool_calls')
useToolTraceVisibility().setToolTraceVisible(true)
})
function mountLiveList() {
const chatStore = useChatStore()
chatStore.activeSessionId = 'session-1'
chatStore.activeSession = makeSession(sampleMessages)
chatStore.abortState = { aborting: true, synced: false }
return mount(MessageList, {
global: {
stubs: {
MessageItem: MessageItemStub,
Transition: false,
},
},
})
}
it('shows named transcript and live tool traces by default while keeping unnamed internal tools hidden', () => {
const wrapper = mountLiveList()
expect(wrapper.findAll('.stub-message').map(node => node.attributes('data-id'))).toEqual([
'user-1',
'tool-named',
'assistant-1',
])
expect(wrapper.findAll('.tool-call-name').map(node => node.text())).toContain('read_file')
})
it('applies the same default-visible rule to history sessions', () => {
const wrapper = mount(HistoryMessageList, {
props: { session: makeSession(sampleMessages) },
global: {
stubs: { MessageItem: MessageItemStub },
},
})
expect(wrapper.findAll('.stub-message').map(node => node.attributes('data-id'))).toEqual([
'user-1',
'tool-named',
'assistant-1',
])
})
it('does not fall back to the live chat session while history session data is loading', () => {
const chatStore = useChatStore()
chatStore.activeSessionId = 'session-1'
chatStore.activeSession = makeSession(sampleMessages)
const wrapper = mount(HistoryMessageList, {
global: {
stubs: { MessageItem: MessageItemStub },
},
})
expect(wrapper.findAll('.stub-message')).toHaveLength(0)
})
it('hides named transcript traces when the toggle is off while keeping live tool stream visible', () => {
useToolTraceVisibility().setToolTraceVisible(false)
const liveWrapper = mountLiveList()
expect(liveWrapper.findAll('.stub-message').map(node => node.attributes('data-id'))).toEqual([
'user-1',
'assistant-1',
])
expect(liveWrapper.findAll('.tool-call-name').map(node => node.text())).toContain('read_file')
const historyWrapper = mount(HistoryMessageList, {
props: { session: makeSession(sampleMessages) },
global: {
stubs: { MessageItem: MessageItemStub },
},
})
expect(historyWrapper.findAll('.stub-message').map(node => node.attributes('data-id'))).toEqual([
'user-1',
'assistant-1',
])
})
it('does not treat tool traces before a slash command as current tool calls', () => {
const chatStore = useChatStore()
chatStore.activeSessionId = 'session-1'
chatStore.activeSession = makeSession([
{ id: 'user-1', role: 'user', content: 'check weather', timestamp: 1 },
{ id: 'tool-weather', role: 'tool', content: '', timestamp: 2, toolName: 'weather', toolResult: 'ok', toolStatus: 'done' },
{ id: 'command-1', role: 'command', content: '/moa where next', timestamp: 3 },
])
chatStore.abortState = { aborting: true, synced: false }
const wrapper = mount(MessageList, {
global: {
stubs: {
MessageItem: MessageItemStub,
Transition: false,
},
},
})
expect(wrapper.findAll('.stub-message').map(node => node.attributes('data-id'))).toContain('tool-weather')
expect(wrapper.findAll('.tool-call-name').map(node => node.text())).not.toContain('weather')
})
})