feat: 知识治理平台(含已验证发布/回滚契约)

全栈知识治理平台首次入库(P1-P10 + 发布链路模拟验证闭环):

- 治理核心:源目录/变更集/人工审核/发布批次/发布执行(fail-closed 闸口)
- 测试通道:WeKnora 测试 KB 上传/轮询/验收;poll 完成时写入
  parser_generation/index_generation,修复 manual/seed 路径发布闸口永久拦截
- 发布适配器 v071(本地 source=测试角色 / 云端 target=生产角色 模拟验证通过):
  * ES 导出/导入 mapping 自适应(.keyword 子字段、可选 tenant_id)
  * OSS locator 支持嵌套 scheme;chunks.seq_id 由目标序列分配
  * bundle 归档同身份重试原子替换;verifier 按 bundle chunk_type 计数
  * 回滚 job payload 支持 prior_execution_id(strict 解码)
- 三通道发布+回滚演练实测:publish 4/4 verified,检索命中,
  rollback 4/4 rolled_back,目标端 PG is_enabled=false、ES is_enabled=false
- 前端 A·Data-console 风格全站统一,120 用例通过
- 门禁:go vet / go test 全包通过,gofmt 干净
This commit is contained in:
2026-09-13 12:02:58 +08:00
committed by 姚章浩
parent ed48c4ceda
commit dcdc8d1ddd
410 changed files with 56661 additions and 1 deletions
+127
View File
@@ -0,0 +1,127 @@
import { renderToStaticMarkup } from 'react-dom/server'
import { describe,expect,it,vi } from 'vitest'
import { SourceCatalogBrowserView } from './SourceCatalogBrowser'
import type { CatalogNode,CatalogNodePage,CatalogSource } from './sourceCatalog'
import type { Job } from './jobs'
const source:CatalogSource={connection_id:'conn-1',source_type:'dingtalk',name:'公司级技术支持知识库',root_node_id:'root-1',folder_count:1080,file_count:3468,observed_at:'2026-09-08T00:00:00Z',snapshot_only:true,snapshot_status:'ready',last_refresh_duration_ms:12000}
const node=(name:string,type:'folder'|'file',id:string)=>({node_id:id,parent_node_id:'root-1',node_type:type,name,direct_child_count:type==='folder'?2:0,subtree_file_count:type==='folder'?10:1,subtree_bytes:1024,size_bytes:type==='file'?1024:undefined,visibility:type==='folder'?'internal' as const:'unknown' as const,imported_count:type==='folder'?8:0,parsed_count:type==='folder'?7:0,active_count:1,failed_count:0,routable_count:type==='file'?1:8})
const page:CatalogNodePage={current:{...node('公司级技术支持知识库','folder','root-1'),parent_node_id:undefined},breadcrumbs:[{node_id:'root-1',name:'公司级技术支持知识库'}],items:[node('01|产品总览与定位','folder','folder-1'),node('根目录说明.pdf','file','file-1')],total:2,limit:50,offset:0}
describe('SourceCatalogBrowserView',()=>{
it('uses a Windows-style path bar instead of a directory tree',()=>{
const html=renderToStaticMarkup(<SourceCatalogBrowserView sources={[source]} selectedSource={source} page={page} loading={false} error={null} onSelectSource={vi.fn()} onOpenFolder={vi.fn()} onNavigateTo={vi.fn()} onBack={vi.fn()} onPageChange={vi.fn()} onRefresh={vi.fn()} />)
expect(html).toContain('aria-label="当前目录路径"')
expect(html).toContain('aria-label="目录面包屑"')
expect(html).toContain('aria-label="返回上一级"')
expect(html).not.toContain('role="tree"')
expect(html).not.toContain('目录树')
})
it('looks like a folder browser and shows only direct children',()=>{
const html=renderToStaticMarkup(<SourceCatalogBrowserView sources={[source]} selectedSource={source} page={page} loading={false} error={null} onSelectSource={vi.fn()} onOpenFolder={vi.fn()} onNavigateTo={vi.fn()} onBack={vi.fn()} onPageChange={vi.fn()} onRefresh={vi.fn()} />)
for(const text of ['各个知识源头的资料总览与标注','公司级技术支持知识库','01|产品总览与定位','文件夹','已解析 7 / 已导入 8','本地只读快照','含所有子目录文件'])expect(html).toContain(text)
expect(html).not.toContain('真实目录')
expect(html).toContain('根目录说明.pdf')
expect(html).not.toContain('显示根目录文件')
expect(html).toContain('aria-label="当前目录路径"')
expect(html).not.toContain('第 1 / 1 页')
expect(html).not.toContain('PP分类 · 不代表完整原始目录')
expect(html).toContain('快照时间')
expect(html).toContain('快照就绪')
expect(html).toContain('上次刷新耗时 12秒')
expect(html).toContain('实时刷新目录')
expect(html).not.toContain('aria-label="处理策略01|产品总览与定位"')
expect(html).not.toContain('递归作用于全部子目录')
})
it('shows current directory, discovered file counts and the estimate marker during refresh',()=>{
const job:Job={id:'job-scan',type:'source.catalog.refresh',payload:{connection_id:'conn-1',stage:'scanning',progress:43,message:'正在扫描目录:已完成 125 个文件夹,待处理 55 个',processed:125,total:180,current_directory:'产品资料/CR系列',scanned_files:2438,estimated_total_files:5662,total_is_estimate:true},state:'running',priority:20,available_at:'2026-09-09T00:00:00Z',attempt:1,max_attempts:3,idempotency_key:'safe',created_at:'2026-09-09T00:00:00Z',updated_at:'2026-09-09T00:00:00Z'}
const html=renderToStaticMarkup(<SourceCatalogBrowserView sources={[source]} selectedSource={source} page={page} loading={false} error={null} refreshJob={job} onSelectSource={vi.fn()} onOpenFolder={vi.fn()} onNavigateTo={vi.fn()} onBack={vi.fn()} onPageChange={vi.fn()} onRefresh={vi.fn()} />)
expect(html).toContain('当前目录:产品资料/CR系列')
expect(html).toContain('已发现 2438 份文件')
expect(html).toContain('(估算)')
})
it('hides the running refresh to a compact pill that expands back on click without blocking browsing',()=>{
const job:Job={id:'job-hide',type:'source.catalog.refresh',payload:{connection_id:'conn-1',stage:'scanning',progress:60,message:'正在扫描目录:已完成 1000 个文件夹',processed:1000,total:1339,current_directory:'产品资料/CR系列',scanned_files:2438},state:'running',priority:20,available_at:'2026-09-09T00:00:00Z',attempt:1,max_attempts:3,idempotency_key:'safe',created_at:'2026-09-09T00:00:00Z',updated_at:'2026-09-09T00:00:00Z'}
const common={sources:[source],selectedSource:source,page,loading:false,error:null,refreshJob:job,onSelectSource:vi.fn(),onOpenFolder:vi.fn(),onNavigateTo:vi.fn(),onBack:vi.fn(),onPageChange:vi.fn(),onRefresh:vi.fn()}
const full=renderToStaticMarkup(<SourceCatalogBrowserView {...common} refreshHidden={false} onToggleRefreshHidden={vi.fn()} />)
expect(full).toContain('隐藏到后台')
expect(full).toContain('实时快照进度')
expect(full).toContain('产品资料/CR系列')
const hidden=renderToStaticMarkup(<SourceCatalogBrowserView {...common} refreshHidden onToggleRefreshHidden={vi.fn()} />)
expect(hidden).not.toContain('实时快照进度')
expect(hidden).toContain('catalog-refresh-pill')
expect(hidden).toContain('60%')
expect(hidden).toContain('公司级技术支持知识库') // pill still names the source
// browsing and annotation stay interactive in hidden mode (only a duplicate refresh is blocked)
expect(hidden).toContain('aria-label="选择01|产品总览与定位"')
expect(hidden).toContain('aria-label="选择根目录说明.pdf"')
expect(hidden).toContain('全选当前页')
expect(hidden).toContain('实时刷新中…')
})
it('announces failure safely and keeps old snapshot usable',()=>{
const job:Job={id:'job-fail',type:'source.catalog.refresh',payload:{connection_id:'conn-1',stage:'failed',progress:0,message:'AList API Token 未配置,请联系管理员更新来源凭据;旧快照仍然保留',processed:0,total:0},state:'failed',priority:20,available_at:'2026-09-09T00:00:00Z',attempt:3,max_attempts:3,idempotency_key:'safe',created_at:'2026-09-09T00:00:00Z',updated_at:'2026-09-09T00:00:00Z'}
const html=renderToStaticMarkup(<SourceCatalogBrowserView sources={[source]} selectedSource={source} page={page} loading={false} error={null} refreshJob={job} onSelectSource={vi.fn()} onOpenFolder={vi.fn()} onNavigateTo={vi.fn()} onBack={vi.fn()} onPageChange={vi.fn()} onRefresh={vi.fn()} />)
expect(html).toContain('实时刷新失败')
expect(html).toContain('刷新失败;旧快照仍然保留,目录浏览与标注不受影响。')
expect(html).toContain('快照就绪')
expect(html).toContain('01|产品总览与定位')
})
it('keeps the progress bar free of directory details when the scanner reports none',()=>{
const job:Job={id:'job-plain',type:'source.catalog.refresh',payload:{connection_id:'conn-1',stage:'building',progress:80,message:'正在校验目录结构',processed:10,total:10},state:'running',priority:20,available_at:'2026-09-09T00:00:00Z',attempt:1,max_attempts:3,idempotency_key:'safe',created_at:'2026-09-09T00:00:00Z',updated_at:'2026-09-09T00:00:00Z'}
const html=renderToStaticMarkup(<SourceCatalogBrowserView sources={[source]} selectedSource={source} page={page} loading={false} error={null} refreshJob={job} onSelectSource={vi.fn()} onOpenFolder={vi.fn()} onNavigateTo={vi.fn()} onBack={vi.fn()} onPageChange={vi.fn()} onRefresh={vi.fn()} />)
expect(html).toContain('正在校验目录结构')
expect(html).not.toContain('刷新明细')
})
it('uses durable background refresh progress and the current stage message',()=>{
const job:Job={id:'job-refresh',type:'source.catalog.refresh',payload:{connection_id:'conn-1',stage:'scanning',progress:50,message:'正在扫描目录:已完成 50 个',processed:50,total:100},state:'running',priority:20,available_at:'2026-09-09T00:00:00Z',attempt:1,max_attempts:3,idempotency_key:'safe',created_at:'2026-09-09T00:00:00Z',updated_at:'2026-09-09T00:00:00Z'}
const html=renderToStaticMarkup(<SourceCatalogBrowserView sources={[source]} selectedSource={source} page={page} loading={false} error={null} refreshJob={job} onSelectSource={vi.fn()} onOpenFolder={vi.fn()} onNavigateTo={vi.fn()} onBack={vi.fn()} onPageChange={vi.fn()} onRefresh={vi.fn()} />)
expect(html).toContain('实时刷新中')
expect(html).toContain('正在扫描目录:已完成 50 个')
expect(html).toContain('value="50"')
})
it('uses clickable breadcrumbs and an explicit back action below the source root',()=>{
const nested={...page,current:{...page.current,node_id:'folder-1',parent_node_id:'root-1',name:'01|产品总览与定位'},breadcrumbs:[...page.breadcrumbs,{node_id:'folder-1',name:'01|产品总览与定位'}]}
const html=renderToStaticMarkup(<SourceCatalogBrowserView sources={[source]} selectedSource={source} page={nested} loading={false} error={null} onSelectSource={vi.fn()} onOpenFolder={vi.fn()} onNavigateTo={vi.fn()} onBack={vi.fn()} onPageChange={vi.fn()} onRefresh={vi.fn()} />)
expect(html).toContain('aria-label="返回上一级"')
expect(html).toContain('公司级技术支持知识库')
expect(html).toContain('01|产品总览与定位')
})
it('shows policy as a read-only table state and offers top-level policy buttons',()=>{
const nested={...page,current:{...page.current,node_id:'folder-1',parent_node_id:'root-1',name:'01|产品总览与定位'},breadcrumbs:[...page.breadcrumbs,{node_id:'folder-1',name:'01|产品总览与定位'}],items:[node('可入队.pdf','file','file-ready'),node('已知目录','folder','folder-known'),{...node('大小未知目录','folder','folder-unknown'),subtree_bytes:0},{...node('只有元数据.pdf','file','file-meta'),size_bytes:undefined,routable_count:0}],total:4}
const html=renderToStaticMarkup(<SourceCatalogBrowserView sources={[source]} selectedSource={source} page={nested} loading={false} error={null} routingCapabilities={{internal_enabled:true,external_enabled:true}} onSelectSource={vi.fn()} onOpenFolder={vi.fn()} onNavigateTo={vi.fn()} onBack={vi.fn()} onPageChange={vi.fn()} onRefresh={vi.fn()} onRoute={vi.fn()} />)
for(const text of ['名称','处理策略','全选当前页','对内','对外','禁止导入','禁止导入只保存期望策略;经“快照差异”确认后才会从测试知识库移除','aria-label="选择可入队.pdf"','大小未提供','已知合计 1.0 KB'])expect(html).toContain(text)
for(const text of ['class="catalog-policy-actions"','class="internal-policy-button"','class="external-policy-button"','class="blocked-policy-button"','class="selected-count"'])expect(html).toContain(text)
for(const text of ['操作人','判断原因','名称与处理策略','当前策略','选择策略','批量处理策略','应用策略','对内 + 对外','<select'])expect(html).not.toContain(text)
expect(html).not.toContain('批量标注对内并入队')
expect(html).not.toContain('已请求移除')
expect(html).not.toContain('新增待确认计划')
expect(html).not.toContain('批量标注对外并入队')
expect(html).not.toContain('递归全选当前目录')
})
it('freezes the S6 batch annotation contract: exactly three policy buttons and current-page selection only',()=>{
const nested={...page,current:{...page.current,node_id:'folder-1'},breadcrumbs:[...page.breadcrumbs,{node_id:'folder-1',name:'01|产品总览与定位'}],items:[node('可入队.pdf','file','file-ready'),node('已知目录','folder','folder-known')],total:2}
const html=renderToStaticMarkup(<SourceCatalogBrowserView sources={[source]} selectedSource={source} page={nested} loading={false} error={null} routingCapabilities={{internal_enabled:true,external_enabled:true}} onSelectSource={vi.fn()} onOpenFolder={vi.fn()} onNavigateTo={vi.fn()} onBack={vi.fn()} onPageChange={vi.fn()} onRefresh={vi.fn()} onRoute={vi.fn()} />)
// exactly three top-level policy buttons: 对内 / 对外 / 禁止导入 (docs/SOURCE_SCOPE_POLICY.md rules 4-6)
expect((html.match(/class="[a-z-]+-policy-button"/g)||[]).length).toBe(3)
// rule 2: only current-page select-all exists
expect(html).toContain('全选当前页')
expect(html).not.toContain('递归全选')
// rule 1: both file and folder rows expose selection checkboxes
expect(html).toContain('aria-label="选择可入队.pdf"')
expect(html).toContain('aria-label="选择已知目录"')
// rules 5-6: no batch entry for historical 对内 + 对外 or for unset state
expect(html).not.toContain('对内 + 对外')
expect(html).not.toContain('批量未选择')
})
it('lets an engineer select a directory without opening it',()=>{
const html=renderToStaticMarkup(<SourceCatalogBrowserView sources={[source]} selectedSource={source} page={page} loading={false} error={null} onSelectSource={vi.fn()} onOpenFolder={vi.fn()} onNavigateTo={vi.fn()} onBack={vi.fn()} onPageChange={vi.fn()} onRefresh={vi.fn()} />)
expect(html).toContain('aria-label="选择01|产品总览与定位"')
})
it('does not claim an empty source loaded when the request failed',()=>{
const html=renderToStaticMarkup(<SourceCatalogBrowserView sources={[]} selectedSource={null} page={null} loading={false} error="加载失败" onSelectSource={vi.fn()} onOpenFolder={vi.fn()} onNavigateTo={vi.fn()} onBack={vi.fn()} onPageChange={vi.fn()} onRefresh={vi.fn()} />)
expect(html).toContain('加载失败')
expect(html).not.toContain('尚无来源目录')
})
})