feat(release): 文档发布会带上知识库 wiki 快照并支持撤权剥离

发布通道原来只有三条:PostgreSQL 关系行、Elasticsearch 分片、OSS 对象。
WeKnora 的 wiki 图谱是 wiki_pages 一张纯 PG 表(in_links/out_links 存 slug),
所以它不在任何通道里——撤权后生产 wiki 会一直留着已撤权文档的页面与引用。

本次新增第 5 条通道:库级 wiki 快照,挂在现有文档发布包里,检索与 wiki
同一个 release 单元(同一次执行、同一次校验、同一次回滚):

- 导出:ExportWiki 按 knowledge_base_id 全量读 wiki_pages/wiki_folders;
  收敛门禁(库内无解析中/合成中文档)不满足直接失败并给中文原因;
  未启用 wiki 且无 wiki 行的库不参与同步(生产 wiki 保持原样)。
- 撤权:item.Action == "delete" 时在导出端剥离该文档的 wiki 贡献
  (source_refs/chunk_refs 去条目、无引用页面整页不带、摘死链、清 parent_slug、
  无页面引用的空文件夹及其祖先一并去掉),使“源端仍在只停止发布”和
  “源端删除”两种情况收敛到同一结果。
- 导入:库级 replace-by-kb(同一事务内 DELETE by kb 后灌入快照,文件夹先于页面),
  新增 ReplaceWiki 供撤权路径使用(文档行只 disable,wiki 整体替换)。
- 校验:VerifyWiki 用生产 WeKnora wiki API 比对页面 slug 集合,撤权时额外断言
  生产 wiki 不再引用被撤权文档。

驱动与验收:新增 cmd/release-channel-e2e(复用发布 worker 真实代码路径,
支持 publish/withdraw/rollback),scripts/wiki_e2e_test5.sh、
scripts/wiki_e2e_newkb.sh 两套端到端脚本;证据见
docs/WIKI_CO_TRANSPORT_ACCEPTANCE.md。
This commit is contained in:
姚章浩
2026-09-16 16:20:28 +08:00
parent 1d6ba6dc2e
commit ea6e56b304
16 changed files with 1702 additions and 8 deletions
+19
View File
@@ -257,6 +257,25 @@ func (c *Client) ListChunks(ctx context.Context, knowledgeID string, page, pageS
return response.Data, response.Total, nil
}
// ListWikiPages lists the wiki pages of a knowledge base. Used by release
// verification to confirm the production wiki matches the released snapshot.
func (c *Client) ListWikiPages(ctx context.Context, knowledgeBaseID string, page, pageSize int) ([]WikiPageSummary, int64, error) {
if !validPathSegment(knowledgeBaseID) || !validPage(page, pageSize) {
return nil, 0, errors.New("invalid wiki page list request")
}
query := url.Values{}
query.Set("page", fmt.Sprint(page))
query.Set("page_size", fmt.Sprint(pageSize))
var response wikiPageListResponse
if err := c.doJSONQuery(ctx, http.MethodGet, "/api/v1/knowledgebase/"+knowledgeBaseID+"/wiki/pages", query, nil, &response); err != nil {
return nil, 0, err
}
if response.Total < 0 {
return nil, 0, errors.New("WeKnora returned an unsuccessful wiki page list")
}
return response.Pages, response.Total, nil
}
func (c *Client) SearchKnowledge(ctx context.Context, request SearchRequest) ([]SearchResult, error) {
if strings.TrimSpace(request.Query) == "" || len(request.KnowledgeIDs) == 0 {
return nil, errors.New("search query and knowledge IDs are required")
+24
View File
@@ -88,3 +88,27 @@ type searchResponse struct {
Success bool `json:"success"`
Data []SearchResult `json:"data"`
}
// WikiPageSummary is the wiki page projection the release verifier needs:
// the page identity (slug) plus the source document references that back it.
// WeKnora's wiki page list endpoint returns the full page objects; only these
// fields are consulted during verification.
type WikiPageSummary struct {
Slug string `json:"slug"`
Title string `json:"title"`
PageType string `json:"page_type"`
Status string `json:"status"`
SourceRefs []string `json:"source_refs"`
ChunkRefs []string `json:"chunk_refs"`
Version int `json:"version"`
}
// wikiPageListResponse mirrors types.WikiPageListResponse in WeKnora v0.7.1.
// The wiki endpoints return the payload unwrapped (no {success,data} envelope).
type wikiPageListResponse struct {
Pages []WikiPageSummary `json:"pages"`
Total int64 `json:"total"`
Page int `json:"page"`
PageSize int `json:"page_size"`
TotalPages int `json:"total_pages"`
}