F17:MarkArtifactFetched 与已验证内容复用都在同一事务内经过策略、来源启用、 过滤、superseded 和当前绑定的复核后,自动把 planned 转 pending 并入队唯一 test.upload;确认与作业幂等,失败整笔回滚。356 已卡记录可对同一文件再次保存 当前策略,经同一路径恢复,不做全库补扫或手工补队列。来源页提示改为自动接续。 F14:来源→监控定位清空未结束/动作/阶段/时间筛选;来源目录定位改为一次性请求 并由父消费,revision/sources 重载不再重放旧请求,手工换目录保持。 F13:抽出 readiness.Resolver 作为端点/绑定/凭据唯一来源;worker 上传/轮询/ 校验/移除改用动态客户端,每次调用重读有效配置,不再固化启动 env 客户端。 验证:隔离 PG 的 F17 正负例与恢复用例、前端挂载定位回归、全量 Go/前端测试 及 make verify 17 项通过。未部署、未做 8088 UI 验收。
This commit is contained in:
@@ -2974,6 +2974,7 @@ export default function App() {
|
||||
{workspace.activeTab === 'dashboard' ? (
|
||||
<SourceCatalogBrowser
|
||||
focus={sourceFocus}
|
||||
onFocusApplied={() => setSourceFocus(null)}
|
||||
onViewProcessing={(source, node) => {
|
||||
setMonitorFocus({ source: source.connection_id, q: node.name })
|
||||
setWorkspace((current) => openModule(current, 'tasks'))
|
||||
@@ -2982,6 +2983,7 @@ export default function App() {
|
||||
) : workspace.activeTab === 'tasks' ? (
|
||||
<WeKnoraMonitor
|
||||
focus={monitorFocus}
|
||||
onFocusApplied={() => setMonitorFocus(null)}
|
||||
onLocateSource={(sourceID, parentNodeID) => {
|
||||
setSourceFocus({ connectionID: sourceID, nodeID: parentNodeID })
|
||||
setWorkspace((current) => openModule(current, 'dashboard'))
|
||||
|
||||
@@ -0,0 +1,155 @@
|
||||
// @vitest-environment jsdom
|
||||
import { act } from 'react'
|
||||
import { createRoot } from 'react-dom/client'
|
||||
import type { Root } from 'react-dom/client'
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
import { SourceCatalogBrowser } from './SourceCatalogBrowser'
|
||||
import type { CatalogNode, CatalogSource } from './sourceCatalog'
|
||||
|
||||
// F14:定位是“一次性导航请求”。旧请求不得在目录刷新/来源重载时重放,
|
||||
// 手工换目录后必须留在原地;新的显式请求仍要能定位。
|
||||
const source: CatalogSource = {
|
||||
connection_id: 'conn-atom',
|
||||
source_type: 'dingtalk',
|
||||
name: 'ATOM知识库',
|
||||
root_node_id: 'root-1',
|
||||
folder_count: 2,
|
||||
file_count: 2,
|
||||
observed_at: '2026-11-05T00:00:00Z',
|
||||
snapshot_only: true,
|
||||
snapshot_status: 'ready',
|
||||
last_refresh_duration_ms: 0,
|
||||
}
|
||||
const node = (id: string, name: string, type: 'folder' | 'file', parent: string): CatalogNode => ({
|
||||
node_id: id,
|
||||
parent_node_id: parent,
|
||||
node_type: type,
|
||||
name,
|
||||
direct_child_count: type === 'folder' ? 1 : 0,
|
||||
subtree_file_count: 1,
|
||||
subtree_bytes: 1024,
|
||||
size_bytes: type === 'file' ? 1024 : undefined,
|
||||
visibility: 'internal',
|
||||
imported_count: type === 'file' ? 1 : 0,
|
||||
parsed_count: type === 'file' ? 1 : 0,
|
||||
active_count: 0,
|
||||
failed_count: 0,
|
||||
routable_count: 1,
|
||||
})
|
||||
const page = (parent: string) => {
|
||||
const crumbs =
|
||||
parent === 'root-1'
|
||||
? [{ node_id: 'root-1', name: 'ATOM知识库' }]
|
||||
: [
|
||||
{ node_id: 'root-1', name: 'ATOM知识库' },
|
||||
{ node_id: parent, name: parent === 'folder-1' ? '售后机器出厂问题整改' : '常见问题汇总' },
|
||||
]
|
||||
return {
|
||||
current: node(parent, crumbs[crumbs.length - 1].name, 'folder', parent === 'root-1' ? '' : 'root-1'),
|
||||
breadcrumbs: crumbs,
|
||||
items:
|
||||
parent === 'root-1'
|
||||
? [
|
||||
node('folder-1', '售后机器出厂问题整改', 'folder', 'root-1'),
|
||||
node('folder-2', '常见问题汇总', 'folder', 'root-1'),
|
||||
]
|
||||
: [node(parent === 'folder-1' ? 'file-1' : 'file-2', '人形常见问题.adoc', 'file', parent)],
|
||||
total: 1,
|
||||
limit: 50,
|
||||
offset: 0,
|
||||
}
|
||||
}
|
||||
|
||||
let container: HTMLDivElement
|
||||
let root: Root
|
||||
let requested: string[]
|
||||
const json = (body: unknown) => new Response(JSON.stringify(body), { status: 200 })
|
||||
|
||||
beforeEach(() => {
|
||||
;(globalThis as unknown as { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true
|
||||
container = document.createElement('div')
|
||||
document.body.appendChild(container)
|
||||
root = createRoot(container)
|
||||
requested = []
|
||||
vi.stubGlobal(
|
||||
'fetch',
|
||||
vi.fn(async (input: RequestInfo | URL) => {
|
||||
const url = new URL(String(input), 'http://localhost')
|
||||
if (url.pathname === '/api/v1/source-catalog/sources') return json({ data: [source] })
|
||||
if (url.pathname === '/api/v1/source-catalog/routing-capabilities')
|
||||
return json({ data: { internal_enabled: true, external_enabled: true } })
|
||||
if (url.pathname === '/api/v1/source-catalog/nodes') {
|
||||
const parent = url.searchParams.get('parent_id') || ''
|
||||
requested.push(parent)
|
||||
return json(page(parent))
|
||||
}
|
||||
if (url.pathname === '/api/v1/jobs') return json({ data: [] })
|
||||
if (url.pathname === '/api/v1/source-catalog/route')
|
||||
return json({
|
||||
data: {
|
||||
selected_files: 1,
|
||||
intents_recorded: 1,
|
||||
fetch_queued: 1,
|
||||
planned_publications: 1,
|
||||
blocked_items: 0,
|
||||
unbound_files: 0,
|
||||
},
|
||||
})
|
||||
return new Response('{}', { status: 404 })
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
act(() => root.unmount())
|
||||
container.remove()
|
||||
vi.unstubAllGlobals()
|
||||
})
|
||||
|
||||
const settle = async () => {
|
||||
await act(async () => {
|
||||
await Promise.resolve()
|
||||
await Promise.resolve()
|
||||
})
|
||||
}
|
||||
|
||||
describe('one-shot source location', () => {
|
||||
it('keeps the manually chosen directory when the old request is re-rendered', async () => {
|
||||
const focus = { connectionID: 'conn-atom', nodeID: 'folder-1' }
|
||||
const applied = vi.fn()
|
||||
await act(async () => root.render(<SourceCatalogBrowser focus={focus} onFocusApplied={applied} />))
|
||||
await settle()
|
||||
expect(applied).toHaveBeenCalledTimes(1)
|
||||
expect(requested.at(-1)).toBe('folder-1')
|
||||
|
||||
// 用户手工返回根目录并进入另一个目录(不经过新旧定位请求)。
|
||||
const back = [...container.querySelectorAll('button')].find((b) => b.getAttribute('aria-label') === '返回上一级')
|
||||
await act(async () => back?.click())
|
||||
await settle()
|
||||
const other = [...container.querySelectorAll('button')].find((b) => b.textContent?.includes('常见问题汇总'))
|
||||
await act(async () => other?.click())
|
||||
await settle()
|
||||
expect(requested.at(-1)).toBe('folder-2')
|
||||
|
||||
// 在当前目录保存一次策略:revision 会让 sources 重新加载,旧 focus 不得重放。
|
||||
const checkbox = container.querySelector('input[aria-label="选择人形常见问题.adoc"]') as HTMLInputElement | null
|
||||
await act(async () => checkbox?.click())
|
||||
const route = [...container.querySelectorAll('button')].find((b) => b.textContent === '对内')
|
||||
await act(async () => route?.click())
|
||||
await settle()
|
||||
expect(requested.at(-1)).toBe('folder-2')
|
||||
|
||||
// 同一旧请求对象因父重渲染再次传入(模拟 revision/sources 刷新):不得拽回 folder-1。
|
||||
await act(async () => root.render(<SourceCatalogBrowser focus={focus} onFocusApplied={applied} />))
|
||||
await settle()
|
||||
expect(requested.at(-1)).toBe('folder-2')
|
||||
|
||||
// 新的显式定位请求必须仍然有效。
|
||||
const next = { connectionID: 'conn-atom', nodeID: 'folder-1' }
|
||||
await act(async () => root.render(<SourceCatalogBrowser focus={next} onFocusApplied={applied} />))
|
||||
await settle()
|
||||
expect(requested.at(-1)).toBe('folder-1')
|
||||
expect(applied).toHaveBeenCalledTimes(2)
|
||||
})
|
||||
})
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useContext, useEffect, useState } from 'react'
|
||||
import { useContext, useEffect, useRef, useState } from 'react'
|
||||
import {
|
||||
fetchCatalogNodes,
|
||||
fetchCatalogRoutingCapabilities,
|
||||
@@ -529,9 +529,11 @@ export function SourceCatalogBrowserView({
|
||||
export function SourceCatalogBrowser({
|
||||
focus,
|
||||
onViewProcessing,
|
||||
onFocusApplied,
|
||||
}: {
|
||||
focus?: { connectionID: string; nodeID: string } | null
|
||||
onViewProcessing?: (source: CatalogSource, node: CatalogNode) => void
|
||||
onFocusApplied?: () => void
|
||||
} = {}) {
|
||||
const [sources, setSources] = useState<CatalogSource[]>([])
|
||||
const [selected, setSelected] = useState<CatalogSource | null>(null)
|
||||
@@ -656,16 +658,20 @@ export function SourceCatalogBrowser({
|
||||
return () => controller.abort()
|
||||
}, [selected, parentID, offset, revision])
|
||||
|
||||
// 从解析监控“在来源与目录定位”进入:选中该来源并直接打开文件所在目录。
|
||||
// 从解析监控“在来源与目录定位”进入:这是一次性导航请求。应用后由父消费;
|
||||
// 同时用 ref 防同一请求在 sources 刷新/revision 重载时重放,手工换目录不会被拽回。
|
||||
const appliedFocus = useRef<typeof focus>(null)
|
||||
useEffect(() => {
|
||||
if (!focus || !sources.length) return
|
||||
if (!focus || !sources.length || appliedFocus.current === focus) return
|
||||
const target = sources.find((source) => source.connection_id === focus.connectionID)
|
||||
if (!target) return
|
||||
appliedFocus.current = focus
|
||||
setSelected(target)
|
||||
setParentID(focus.nodeID || target.root_node_id)
|
||||
setOffset(0)
|
||||
setPage(null)
|
||||
closeHistory()
|
||||
onFocusApplied?.()
|
||||
}, [focus, sources])
|
||||
// 有来源正在首次扫描时自动刷新列表:百分比会自己往前走,扫完那一行自动变成正式来源。
|
||||
useEffect(() => {
|
||||
@@ -759,7 +765,7 @@ export function SourceCatalogBrowser({
|
||||
reason: `目录页策略:${scope(policy)}`,
|
||||
})
|
||||
setRoutingMessage(
|
||||
`策略已保存 ${result.selected_files} 份;已记入意图 ${result.intents_recorded} 份;排队从源头取件 ${result.fetch_queued} 份;列入待入库 ${result.planned_publications} 份;标记禁止 ${result.blocked_items} 份;目录外无文件可标注 ${result.unbound_files} 份。到“解析监控 → 待入库”点开始处理即可。`
|
||||
`策略已保存 ${result.selected_files} 份;已记入意图 ${result.intents_recorded} 份;排队从源头取件 ${result.fetch_queued} 份;列入处理 ${result.planned_publications} 份;标记禁止 ${result.blocked_items} 份;目录外无文件可标注 ${result.unbound_files} 份。取件校验完成后会自动上传解析,可在“解析监控”跟踪进度。`
|
||||
)
|
||||
setRevision((value) => value + 1)
|
||||
return true
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
// @vitest-environment jsdom
|
||||
import { act } from 'react'
|
||||
import { createRoot } from 'react-dom/client'
|
||||
import type { Root } from 'react-dom/client'
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
import { WeKnoraMonitor } from './WeKnoraMonitor'
|
||||
|
||||
// F14:来源“查看处理”进入监控时,已完成文件不能被默认 status=active 遮蔽。
|
||||
let container: HTMLDivElement
|
||||
let root: Root
|
||||
const requests: URL[] = []
|
||||
|
||||
beforeEach(() => {
|
||||
;(globalThis as unknown as { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true
|
||||
container = document.createElement('div')
|
||||
document.body.appendChild(container)
|
||||
root = createRoot(container)
|
||||
requests.length = 0
|
||||
const completed = {
|
||||
id: 'tp-parent',
|
||||
title: '已解析文件.pdf',
|
||||
path: '售后/已解析文件.pdf',
|
||||
node_id: 'node-file',
|
||||
parent_node_id: 'node-folder',
|
||||
source_id: 'conn-parent',
|
||||
source_name: 'ATOM',
|
||||
target_scope: 'internal',
|
||||
target_kb: 'kb-parent',
|
||||
action: 'add',
|
||||
stage: 'finished',
|
||||
status: 'completed',
|
||||
detail: '处理完成',
|
||||
updated_at: '2026-11-05T02:00:00Z',
|
||||
retry_kind: '',
|
||||
failure_id: '',
|
||||
retry_count: 0,
|
||||
version_id: 'sv-parent',
|
||||
history: [],
|
||||
}
|
||||
vi.stubGlobal(
|
||||
'fetch',
|
||||
vi.fn(async (input: RequestInfo | URL) => {
|
||||
const url = new URL(String(input), 'http://localhost')
|
||||
if (url.pathname === '/api/v1/monitor/tasks') {
|
||||
requests.push(url)
|
||||
const active = url.searchParams.get('status') === 'active'
|
||||
const items = active ? [] : [completed]
|
||||
return new Response(
|
||||
JSON.stringify({
|
||||
data: {
|
||||
items,
|
||||
total: items.length,
|
||||
limit: 20,
|
||||
offset: 0,
|
||||
sources: [{ id: 'conn-parent', name: 'ATOM' }],
|
||||
targets: [{ id: 'kb-parent', name: '测试库', scope: 'internal' }],
|
||||
bindings: { internal: 'kb-parent', external: '' },
|
||||
retryable: 0,
|
||||
},
|
||||
}),
|
||||
{ status: 200 }
|
||||
)
|
||||
}
|
||||
return new Response('{}', { status: 503 })
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
act(() => root.unmount())
|
||||
container.remove()
|
||||
vi.unstubAllGlobals()
|
||||
})
|
||||
|
||||
describe('monitor focus from source directory', () => {
|
||||
it('shows an already completed imported file without manual filter clearing', async () => {
|
||||
vi.useFakeTimers()
|
||||
const applied = vi.fn()
|
||||
await act(async () =>
|
||||
root.render(<WeKnoraMonitor focus={{ source: 'conn-parent', q: '已解析文件.pdf' }} onFocusApplied={applied} />)
|
||||
)
|
||||
await act(async () => {
|
||||
await vi.advanceTimersByTimeAsync(250)
|
||||
})
|
||||
expect(requests.length).toBeGreaterThan(0)
|
||||
const last = requests[requests.length - 1]
|
||||
expect(last.searchParams.get('source')).toBe('conn-parent')
|
||||
expect(last.searchParams.get('q')).toBe('已解析文件.pdf')
|
||||
expect(last.searchParams.get('status'), 'locator must not retain the default active filter').not.toBe('active')
|
||||
expect(container.querySelector('tbody')?.textContent).toContain('已解析文件.pdf')
|
||||
expect(applied).toHaveBeenCalledTimes(1)
|
||||
vi.useRealTimers()
|
||||
})
|
||||
})
|
||||
@@ -574,9 +574,11 @@ function TaskDetail({
|
||||
export function WeKnoraMonitor({
|
||||
focus,
|
||||
onLocateSource,
|
||||
onFocusApplied,
|
||||
}: {
|
||||
focus?: { source: string; q: string } | null
|
||||
onLocateSource?: (sourceID: string, parentNodeID: string) => void
|
||||
onFocusApplied?: () => void
|
||||
} = {}) {
|
||||
const auth = useOptionalAuth()
|
||||
const canOperate = auth?.identity?.role === 'admin' || auth?.identity?.role === 'engineer'
|
||||
@@ -599,12 +601,14 @@ export function WeKnoraMonitor({
|
||||
setTabs([])
|
||||
return () => setTabs([])
|
||||
}, [setTabs])
|
||||
// 从来源目录“查看处理”进入:一次性套用来源+文件名定位,之后由用户自行改筛选。
|
||||
// 从来源目录“查看处理”进入:定位是一次性请求,必须清掉未结束/动作/阶段/时间等
|
||||
// 会遮蔽已完成文件的筛选;应用后由父消费掉,避免重挂载时旧请求再次覆盖手工筛选。
|
||||
useEffect(() => {
|
||||
if (!focus) return
|
||||
setFilters((current) => ({ ...current, q: focus.q, source: focus.source, target: '', scope: '' }))
|
||||
setFilters({ ...defaultMonitorFilters, q: focus.q, source: focus.source, status: '' })
|
||||
setOffset(0)
|
||||
setSelected([])
|
||||
onFocusApplied?.()
|
||||
}, [focus])
|
||||
useEffect(() => {
|
||||
const c = new AbortController()
|
||||
|
||||
Reference in New Issue
Block a user