Files
knowledge-governance/scripts/accept_catalog_route_canary.py
T
zheromiku dcdc8d1ddd 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 干净
2026-09-30 10:54:06 +08:00

24 lines
2.8 KiB
Python

"""Route one verified PP public canary to the local external WeKnora KB."""
import argparse,json,pathlib,time,urllib.parse,urllib.request
GOV='http://127.0.0.1:8088';WEKNORA='http://127.0.0.1:8080/api/v1';KBS={'internal':'1b52c140-2e18-4676-afc5-4c7d8d190a8c','external':'fd7db6aa-763a-46f1-84d2-ecc7c952a5ea'};TITLE='dobot_xtrainer-软件版本区别'
def gov(path):
with urllib.request.urlopen(GOV+path,timeout=20) as response:return json.load(response)
def nodes(connection,parent):return gov('/api/v1/source-catalog/nodes?'+urllib.parse.urlencode({'connection_id':connection,'parent_id':parent,'limit':100,'offset':0}))['items']
def weknora(path):
key=pathlib.Path(__file__).resolve().parents[1].joinpath('secrets/test_weknora_api_key').read_text().strip();request=urllib.request.Request(WEKNORA+path,headers={'X-API-Key':key,'Accept':'application/json'});return json.load(urllib.request.urlopen(request,timeout=20))
def main():
parser=argparse.ArgumentParser();parser.add_argument('--visibility',choices=('internal','external'),default='external');args=parser.parse_args();kb=KBS[args.visibility]
pp=next(item for item in gov('/api/v1/source-catalog/sources')['data'] if item['source_type']=='pp');top=next(item for item in nodes(pp['connection_id'],pp['root_node_id']) if item['name']=='具身产品');folder=next(item for item in nodes(pp['connection_id'],top['node_id']) if item['name']=='Dobot X-Trainer');file=next(item for item in nodes(pp['connection_id'],folder['node_id']) if item['name']==TITLE)
assert file['routable_count']==1
payload={'connection_id':pp['connection_id'],'node_ids':[file['node_id']],'visibility':args.visibility,'operator_ref':'routing-canary','reason':'验证标注后进入本地解析队列'};request=urllib.request.Request(GOV+'/api/v1/source-catalog/route',data=json.dumps(payload,ensure_ascii=False).encode(),method='POST',headers={'Content-Type':'application/json','Accept':'application/json'})
with urllib.request.urlopen(request,timeout=20) as response:result=json.load(response)['data']
assert result['selected_files']==1 and result['unbound_files']==0 and result['hash_unknown_files']==0
deadline=time.monotonic()+180;matched=None
while time.monotonic()<deadline:
response=weknora('/knowledge-bases/'+kb+'/knowledge?page=1&page_size=100');items=response.get('data') or [];matched=next((item for item in items if item.get('title') in (TITLE,TITLE+'.txt')),None)
if matched and matched.get('parse_status') in ('completed','failed'):break
time.sleep(2)
if not matched or matched.get('parse_status')!='completed':raise SystemExit('routing canary did not complete')
print(json.dumps({'title':matched['title'],'route_result':result,'knowledge_id':matched['id'],'parse_status':matched['parse_status'],'target':'local-'+args.visibility},ensure_ascii=False))
if __name__=='__main__':main()