477af66232
* feat(chat): polish syntax highlighting and tool payload rendering (#94) * [verified] feat(chat): polish syntax highlighting and tool payload rendering * [verified] fix(chat): tighten large tool payload rendering * docs: update data volume path in Docker docs Align documentation with docker-compose.yml change: hermes-web-ui-data -> hermes-web-ui, /app/dist/data -> /root/.hermes-web-ui Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * refactor: bundle server build and restructure service modules - Add build-server.mjs script for standalone server compilation - Add logger service with structured output - Restructure auth, gateway-manager, hermes-cli, hermes services - Update docker-compose volume mount path - Update tsconfig and entry point for bundled server Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * refactor: separate controllers from routes and centralize route registration - Extract business logic from route handlers into controllers/ - Add centralized route registry in routes/index.ts with public/auth/protected layers - Replace global auth whitelist with sequential middleware registration - Extract shared helpers to services/config-helpers.ts - Allow custom provider name to be user-editable in ProviderFormModal - Deduplicate custom providers by poolKey instead of base_url in getAvailable Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: auth bypass via path case, SPA serving, and provider improvements - Fix auth bypass: path case-insensitive check for /api, /v1, /upload - Fix SPA returning 401: skip auth for non-API paths (static files) - Fix profile switch: use local loading state instead of shared store ref - Auto-append /v1 to base_url when fetching models (frontend + backend) - Guard .env writing to built-in providers only - Add builtin field to provider presets, enable base_url input in form - Print auth token to console on startup (pino only writes to file) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Zhicheng Han <43314240+hanzckernel@users.noreply.github.com> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
161 lines
5.0 KiB
TypeScript
161 lines
5.0 KiB
TypeScript
// @vitest-environment jsdom
|
|
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
import { mount } from '@vue/test-utils'
|
|
|
|
vi.mock('vue-i18n', () => ({
|
|
useI18n: () => ({
|
|
t: (key: string) => key,
|
|
}),
|
|
}))
|
|
|
|
import MessageItem from '@/components/hermes/chat/MessageItem.vue'
|
|
import type { Message } from '@/stores/hermes/chat'
|
|
|
|
describe('MessageItem tool details', () => {
|
|
beforeEach(() => {
|
|
Object.defineProperty(navigator, 'clipboard', {
|
|
configurable: true,
|
|
value: {
|
|
writeText: vi.fn().mockResolvedValue(undefined),
|
|
},
|
|
})
|
|
})
|
|
|
|
it('renders highlighted code blocks for tool arguments and tool results', async () => {
|
|
const wrapper = mount(MessageItem, {
|
|
props: {
|
|
message: {
|
|
id: 'tool-1',
|
|
role: 'tool',
|
|
content: '',
|
|
timestamp: Date.now(),
|
|
toolName: 'web_search',
|
|
toolArgs: '{"query":"syntax highlighting"}',
|
|
toolResult: '{"results":[{"title":"Done"}]}',
|
|
toolStatus: 'done',
|
|
} satisfies Message,
|
|
},
|
|
})
|
|
|
|
await wrapper.find('.tool-line').trigger('click')
|
|
|
|
const blocks = wrapper.findAll('.tool-details .hljs-code-block')
|
|
expect(blocks).toHaveLength(2)
|
|
expect(blocks[0].find('.code-lang').text()).toBe('json')
|
|
expect(blocks[1].find('.code-lang').text()).toBe('json')
|
|
})
|
|
|
|
it('copies tool detail code through the delegated click handler', async () => {
|
|
const writeText = vi.mocked(navigator.clipboard.writeText)
|
|
const wrapper = mount(MessageItem, {
|
|
props: {
|
|
message: {
|
|
id: 'tool-copy',
|
|
role: 'tool',
|
|
content: '',
|
|
timestamp: Date.now(),
|
|
toolName: 'web_search',
|
|
toolArgs: '{"query":"syntax highlighting"}',
|
|
toolStatus: 'done',
|
|
} satisfies Message,
|
|
},
|
|
})
|
|
|
|
await wrapper.find('.tool-line').trigger('click')
|
|
|
|
const expected = wrapper.find('.tool-details code.hljs').text()
|
|
await wrapper.find('.tool-details [data-copy-code="true"]').trigger('click')
|
|
|
|
expect(writeText).toHaveBeenCalledWith(expected)
|
|
})
|
|
|
|
it('truncates large tool arguments for display but copies the full formatted payload', async () => {
|
|
const writeText = vi.mocked(navigator.clipboard.writeText)
|
|
const message = {
|
|
content: 'x'.repeat(4000),
|
|
ok: true,
|
|
}
|
|
const wrapper = mount(MessageItem, {
|
|
props: {
|
|
message: {
|
|
id: 'tool-args-large',
|
|
role: 'tool',
|
|
content: '',
|
|
timestamp: Date.now(),
|
|
toolName: 'write_file',
|
|
toolArgs: JSON.stringify(message),
|
|
toolStatus: 'done',
|
|
} satisfies Message,
|
|
},
|
|
})
|
|
|
|
await wrapper.find('.tool-line').trigger('click')
|
|
|
|
const expected = JSON.stringify(message, null, 2)
|
|
const code = wrapper.find('.tool-details code.hljs')
|
|
expect(wrapper.find('.tool-details .code-lang').text()).toBe('json')
|
|
expect(wrapper.html()).toContain('chat.truncated')
|
|
expect(code.findAll('span')).toHaveLength(0)
|
|
|
|
await wrapper.find('.tool-details [data-copy-code="true"]').trigger('click')
|
|
expect(writeText).toHaveBeenCalledWith(expected)
|
|
})
|
|
|
|
it('copies the full large JSON tool result even when the display is truncated', async () => {
|
|
const writeText = vi.mocked(navigator.clipboard.writeText)
|
|
const fullResult = {
|
|
content: 'x'.repeat(4000),
|
|
ok: true,
|
|
}
|
|
const wrapper = mount(MessageItem, {
|
|
props: {
|
|
message: {
|
|
id: 'tool-2',
|
|
role: 'tool',
|
|
content: '',
|
|
timestamp: Date.now(),
|
|
toolName: 'read_file',
|
|
toolResult: JSON.stringify(fullResult),
|
|
toolStatus: 'done',
|
|
} satisfies Message,
|
|
},
|
|
})
|
|
|
|
await wrapper.find('.tool-line').trigger('click')
|
|
|
|
expect(wrapper.find('.tool-details .code-lang').text()).toBe('json')
|
|
expect(wrapper.html()).toContain('chat.truncated')
|
|
expect(wrapper.find('.tool-details code.hljs').findAll('span')).toHaveLength(0)
|
|
|
|
await wrapper.find('.tool-details [data-copy-code="true"]').trigger('click')
|
|
expect(writeText).toHaveBeenCalledWith(JSON.stringify(fullResult, null, 2))
|
|
})
|
|
|
|
it('copies the full large raw tool result even when the display is truncated', async () => {
|
|
const writeText = vi.mocked(navigator.clipboard.writeText)
|
|
const fullResult = 'line\n'.repeat(1200)
|
|
const wrapper = mount(MessageItem, {
|
|
props: {
|
|
message: {
|
|
id: 'tool-raw',
|
|
role: 'tool',
|
|
content: '',
|
|
timestamp: Date.now(),
|
|
toolName: 'read_file',
|
|
toolResult: fullResult,
|
|
toolStatus: 'done',
|
|
} satisfies Message,
|
|
},
|
|
})
|
|
|
|
await wrapper.find('.tool-line').trigger('click')
|
|
|
|
expect(wrapper.find('.tool-details .code-lang').text()).toBe('text')
|
|
expect(wrapper.html()).toContain('chat.truncated')
|
|
expect(wrapper.find('.tool-details code.hljs').findAll('span')).toHaveLength(0)
|
|
|
|
await wrapper.find('.tool-details [data-copy-code="true"]').trigger('click')
|
|
expect(writeText).toHaveBeenCalledWith(fullResult)
|
|
})
|
|
})
|