mirror of
https://github.com/EKKOLearnAI/hermes-web-ui.git
synced 2026-05-25 21:40:13 +00:00
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>
94 lines
2.9 KiB
TypeScript
94 lines
2.9 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 MarkdownRenderer from '@/components/hermes/chat/MarkdownRenderer.vue'
|
|
|
|
describe('MarkdownRenderer', () => {
|
|
beforeEach(() => {
|
|
Object.defineProperty(navigator, 'clipboard', {
|
|
configurable: true,
|
|
value: {
|
|
writeText: vi.fn().mockResolvedValue(undefined),
|
|
},
|
|
})
|
|
})
|
|
|
|
it('highlights vue fenced blocks instead of rendering them as plain text', () => {
|
|
const wrapper = mount(MarkdownRenderer, {
|
|
props: {
|
|
content: '```vue\n<template><div>Hello</div></template>\n```',
|
|
},
|
|
})
|
|
|
|
expect(wrapper.find('.code-lang').text()).toBe('vue')
|
|
expect(wrapper.find('code.hljs').html()).toContain('hljs-tag')
|
|
})
|
|
|
|
it('keeps shell-session fences on the shell grammar', () => {
|
|
const wrapper = mount(MarkdownRenderer, {
|
|
props: {
|
|
content: '```shell\n$ ls\nfoo.txt\n```',
|
|
},
|
|
})
|
|
|
|
expect(wrapper.find('.code-lang').text()).toBe('shell')
|
|
expect(wrapper.find('code.hljs').html()).toContain('hljs-meta')
|
|
})
|
|
|
|
it('still highlights long supported code fences', () => {
|
|
const wrapper = mount(MarkdownRenderer, {
|
|
props: {
|
|
content: `\`\`\`json\n${JSON.stringify({ content: 'x'.repeat(2500), ok: true })}\n\`\`\``,
|
|
},
|
|
})
|
|
|
|
expect(wrapper.find('.code-lang').text()).toBe('json')
|
|
expect(wrapper.find('code.hljs').html()).toMatch(/hljs-(attr|string|punctuation)/)
|
|
})
|
|
|
|
it('falls back to plain escaped text when a fence language is unsupported', () => {
|
|
const wrapper = mount(MarkdownRenderer, {
|
|
props: {
|
|
content: '```foobar\n{"answer":42,"ok":true}\n```',
|
|
},
|
|
})
|
|
|
|
expect(wrapper.find('.code-lang').text()).toBe('foobar')
|
|
expect(wrapper.find('code.hljs').findAll('span')).toHaveLength(0)
|
|
expect(wrapper.find('code.hljs').text()).toContain('{"answer":42,"ok":true}')
|
|
})
|
|
|
|
it('keeps unlabeled code fences as plain text instead of guessing a grammar', () => {
|
|
const wrapper = mount(MarkdownRenderer, {
|
|
props: {
|
|
content: '```\nINFO Starting server\nConnected to 127.0.0.1\nDone\n```',
|
|
},
|
|
})
|
|
|
|
expect(wrapper.find('.code-lang').text()).toBe('text')
|
|
expect(wrapper.find('code.hljs').findAll('span')).toHaveLength(0)
|
|
expect(wrapper.find('code.hljs').text()).toContain('INFO Starting server')
|
|
})
|
|
|
|
it('copies code through the delegated click handler', async () => {
|
|
const writeText = vi.mocked(navigator.clipboard.writeText)
|
|
const wrapper = mount(MarkdownRenderer, {
|
|
props: {
|
|
content: '```ts\nconst answer = 42\n```',
|
|
},
|
|
})
|
|
|
|
const expected = wrapper.find('code.hljs').element.textContent ?? ''
|
|
await wrapper.find('[data-copy-code="true"]').trigger('click')
|
|
|
|
expect(writeText).toHaveBeenCalledWith(expected)
|
|
})
|
|
})
|