mirror of
https://github.com/EKKOLearnAI/hermes-web-ui.git
synced 2026-07-10 02:30:15 +00:00
acced4fd25
把三块技能相关改动 + PR #1288 的两条 review 修复合并到一次推送。 PR #1288 review 修复 - 将系统 `unzip` 二进制替换为纯 Node 的 `adm-zip` 包,导入 zip 在 Windows 与精简 Linux 镜像(无 unzip)上也能正常工作。 - 删除接口加上 category:路由改为 `DELETE /api/hermes/skills/:category/:skill`,server 端使用 `findSkillDirInRoot(skillsDir, category, name)` 定位,与 `list` / `listFiles` / `readFile_` 一致。同名不同 category 的 local skill 不会再误删。 外部技能目录管理 - 新增 SkillExternalDirsModal,可在界面上编辑 `config.skills.external_dirs`:增删行、支持 `~` 与 `$VAR`、对当前 无法解析的路径置灰提示。 - 新增 server 接口 `GET/PUT /api/hermes/skills/external-dirs`,按原样 读写配置(trim、去空、去重、限制长度、拒绝控制字符)。 - skills 列表响应里加上 `paths.externalRaw`,UI 可以同时展示用户写的 原始路径和解析后的绝对路径。 - i18n:所有 locale 增加 `skills.externalDirs.*` 与 `skills.path.*`。 侧栏按 sourcePath 分组 - 移除 SkillsView 顶部的本地 + 外部路径条;多个外部目录时太杂,并且 无法直接看出每个 skill 来自哪个目录。 - 选中"外部目录"筛选时,列表改为先按外部目录(用户写的 `~/...` 原始 形式)分组,再按 category 分组。其他筛选保持扁平 category 列表。 - server 在列表响应里给每个外部 skill 附加 `sourcePath`(原始形式), 供 UI 分组使用。 测试 - 新增 SkillList 用例:「按 sourcePath 分组」、「非外部筛选回退扁平 列表」。 - 修复已存在的 SkillList 测试缺少 `useDialog` / `deleteSkillApi` mock 的问题。
142 lines
4.3 KiB
TypeScript
142 lines
4.3 KiB
TypeScript
// @vitest-environment jsdom
|
|
import { describe, expect, it, vi } from 'vitest'
|
|
import { mount } from '@vue/test-utils'
|
|
import { defineComponent } from 'vue'
|
|
import SkillList from '@/components/hermes/skills/SkillList.vue'
|
|
|
|
vi.mock('vue-i18n', () => ({
|
|
useI18n: () => ({ t: (key: string) => key }),
|
|
}))
|
|
|
|
vi.mock('@/api/hermes/skills', () => ({
|
|
toggleSkill: vi.fn(),
|
|
deleteSkillApi: vi.fn(),
|
|
}))
|
|
|
|
vi.mock('naive-ui', () => ({
|
|
NSwitch: defineComponent({
|
|
name: 'NSwitch',
|
|
props: ['value', 'loading'],
|
|
emits: ['update:value', 'click'],
|
|
template: '<button type="button" @click="$emit(\'click\')"></button>',
|
|
}),
|
|
useMessage: () => ({ error: vi.fn(), success: vi.fn(), info: vi.fn() }),
|
|
useDialog: () => ({ warning: vi.fn() }),
|
|
}))
|
|
|
|
describe('SkillList', () => {
|
|
it('supports filtering skills from external sources', () => {
|
|
const wrapper = mount(SkillList, {
|
|
props: {
|
|
categories: [
|
|
{
|
|
name: 'tools',
|
|
description: '',
|
|
skills: [
|
|
{ name: 'local-skill', description: 'Local skill', enabled: true, source: 'local' },
|
|
{ name: 'external-skill', description: 'External skill', enabled: true, source: 'external' },
|
|
],
|
|
},
|
|
],
|
|
archived: [],
|
|
selectedSkill: null,
|
|
searchQuery: '',
|
|
sourceFilter: 'external',
|
|
},
|
|
})
|
|
|
|
expect(wrapper.text()).toContain('external-skill')
|
|
expect(wrapper.text()).not.toContain('local-skill')
|
|
expect(wrapper.get('.source-dot').classes()).toContain('dot-external')
|
|
expect(wrapper.get('.source-dot').attributes('title')).toBe('skills.source.external')
|
|
})
|
|
|
|
it('groups external skills by source path then category when external filter is active', () => {
|
|
const wrapper = mount(SkillList, {
|
|
props: {
|
|
categories: [
|
|
{
|
|
name: 'tools',
|
|
description: '',
|
|
skills: [
|
|
{
|
|
name: 'a-skill',
|
|
description: '',
|
|
enabled: true,
|
|
source: 'external',
|
|
sourcePath: '~/path-a/skills',
|
|
},
|
|
{
|
|
name: 'b-skill',
|
|
description: '',
|
|
enabled: true,
|
|
source: 'external',
|
|
sourcePath: '~/path-b/skills',
|
|
},
|
|
],
|
|
},
|
|
{
|
|
name: 'misc',
|
|
description: '',
|
|
skills: [
|
|
{
|
|
name: 'c-skill',
|
|
description: '',
|
|
enabled: true,
|
|
source: 'external',
|
|
sourcePath: '~/path-a/skills',
|
|
},
|
|
],
|
|
},
|
|
],
|
|
archived: [],
|
|
selectedSkill: null,
|
|
searchQuery: '',
|
|
sourceFilter: 'external',
|
|
},
|
|
})
|
|
|
|
// Outer headers are the path groups
|
|
const pathHeaders = wrapper.findAll('.path-header-text').map(el => el.text())
|
|
expect(pathHeaders).toEqual(['~/path-a/skills', '~/path-b/skills'])
|
|
|
|
// Inner headers are the categories under each path
|
|
const groups = wrapper.findAll('.skill-path-group')
|
|
expect(groups).toHaveLength(2)
|
|
const aGroupCats = groups[0].findAll('.category-header.sub .category-name').map(el => el.text())
|
|
expect(aGroupCats).toEqual(['tools', 'misc'])
|
|
const bGroupCats = groups[1].findAll('.category-header.sub .category-name').map(el => el.text())
|
|
expect(bGroupCats).toEqual(['tools'])
|
|
|
|
// a-skill and c-skill belong to path-a group; b-skill belongs to path-b
|
|
expect(groups[0].text()).toContain('a-skill')
|
|
expect(groups[0].text()).toContain('c-skill')
|
|
expect(groups[0].text()).not.toContain('b-skill')
|
|
expect(groups[1].text()).toContain('b-skill')
|
|
})
|
|
|
|
it('falls back to flat category list for non-external filters', () => {
|
|
const wrapper = mount(SkillList, {
|
|
props: {
|
|
categories: [
|
|
{
|
|
name: 'tools',
|
|
description: '',
|
|
skills: [
|
|
{ name: 'local-skill', description: '', enabled: true, source: 'local' },
|
|
],
|
|
},
|
|
],
|
|
archived: [],
|
|
selectedSkill: null,
|
|
searchQuery: '',
|
|
sourceFilter: null,
|
|
},
|
|
})
|
|
|
|
expect(wrapper.find('.path-header-text').exists()).toBe(false)
|
|
expect(wrapper.text()).toContain('tools')
|
|
expect(wrapper.text()).toContain('local-skill')
|
|
})
|
|
})
|