Files
knowledge-governance/web/src/monitorTasks.test.ts
T
姚章浩 1c80b07f2c
build / build (push) Successful in 1m59s
fix(ui): 修复F12-F16入口与追溯缺陷
Dockerfile 运行阶段补齐 dws_dingtalk_scan(F12),并新增 runtime-scripts 门禁
做脚本依赖闭包正负例;就绪探测每次解析当前端点/绑定/凭据并区分 404、未配置、
不可达(F13);路由写入来源路径与父目录,历史空值仅按同连接同 item 的意图读时
补齐(F14);目标筛选显示短 ID 与当前绑定/历史并提供快捷筛选(F15);刷新终态
移除后台运行、展示失败时间/旧快照/脱敏原因/作业 ID 与重试(F16)。

验证:make verify 17 项全过(identity 本地按设计 skipped);一次性 schema 的
Monitor 目录/路由集成用例通过;8088 部署与真实 UI 验收仍由父会话执行。
2026-11-05 10:38:26 +08:00

63 lines
2.8 KiB
TypeScript

import { afterEach, describe, expect, it, vi } from 'vitest'
import { fetchMonitorTasks, isCurrentTarget, targetLabel } from './monitorTasks'
import { healthLabel } from './WeKnoraMonitor'
import type { ServiceHealth } from './monitor'
afterEach(() => vi.unstubAllGlobals())
describe('monitor table contract', () => {
it('rejects malformed facets instead of rendering a broken selector', async () => {
vi.stubGlobal(
'fetch',
vi.fn().mockResolvedValue({
ok: true,
json: async () => ({
data: {
items: [],
total: 0,
limit: 20,
offset: 0,
retryable: 0,
sources: [{ id: 7, name: 'bad' }],
targets: [],
},
}),
})
)
await expect(fetchMonitorTasks({ status: 'active' })).rejects.toThrow('筛选项')
})
it('passes the filter and page to the server without client-side totals', async () => {
const data = { items: [], total: 145, limit: 20, offset: 40, retryable: 12, sources: [], targets: [] }
const request = vi.fn().mockResolvedValue({ ok: true, json: async () => ({ data }) })
vi.stubGlobal('fetch', request)
const result = await fetchMonitorTasks({ status: 'attention', action: 'remove', q: '手册' }, 40)
expect(result.total).toBe(145)
expect(result.retryable).toBe(12)
const url = new URL(request.mock.calls[0][0], 'http://localhost')
expect(url.searchParams.get('offset')).toBe('40')
expect(url.searchParams.get('action')).toBe('remove')
expect(url.searchParams.get('q')).toBe('手册')
})
it('distinguishes unknown, unconfigured, blocked and inapplicable services', () => {
const s = { applicable: true, configured: true, readiness: 'unknown' } as ServiceHealth
expect(healthLabel(s)).toBe('未确认')
expect(healthLabel({ ...s, configured: false })).toBe('未配置')
expect(healthLabel({ ...s, applicable: false })).toBe('不适用')
expect(healthLabel({ ...s, readiness: 'blocked' })).toBe('阻断')
})
})
describe('target identity labels (F15)', () => {
const bindings = { internal: '0c84a098-d3ed-4b82-a165-e6de9691d6a8', external: 'ext-11112222-3333' }
it('distinguishes same-named knowledge bases by short id and binding state', () => {
const current = targetLabel('对内知识库', bindings.internal, 'internal', bindings)
const historical = targetLabel('对内知识库', 'sc-ed1f812c4e5fabe817fc6351104938c4', 'internal', bindings)
expect(current).toContain('0c84a098')
expect(current).toContain('当前绑定')
expect(historical).toContain('sc-ed1f8')
expect(historical).toContain('历史')
expect(current).not.toBe(historical)
})
it('never treats an env/unknown target as the current binding', () => {
expect(isCurrentTarget('1b52c140-2e18-4676-afc5-4c7d8d190a8c', 'internal', bindings)).toBe(false)
})
})