feat(library): 云测试发布目标接入的角色分离、快照搬运与图谱门禁

为什么改:发布执行链是"与目标同机"假设写死的(本机 docker.sock、本机 drain.json、
本机 Redis/PG),把目标换成云测试不能只改展示 URL;直接搬整套 worker 又会抢走
本机封存/QA/周报队列并按本机配置写错目标。所以先把"谁消费哪段队列"变成显式角色,
再补齐跨主机搬运与目标侧门禁。

角色(LIBRARY_WORKER_ROLE=full/release-executor/capture)不只影响 handler 列表,
还决定是否拥有 DDL(release-executor 只读校验迁移版本,落后即拒绝启动)、
收拾哪些 library_jobs.kind、是否跑 release 接管扫描、是否起 scheduler/QA/周报/探测。
capture 保留本机原有全部业务;release-executor 只挂 sync/restore/recover/baseline。

快照跨主机:新增内容寻址的 bundle(版本清单先落、blob 按 sha256 命名、清单最后
Link 作提交点),pack/unpack 幂等且拒绝覆盖与同名不同内容;执行器使用前仍逐 blob
重算 sha256,因此传输不可变有两道证据。

目标侧门禁:目标知识库 graph_enabled=true 时拒绝发布(发布只写 PG/ES/OSS,不写
Neo4j;未知也拒绝),只读检测、不改目标配置、不做图谱迁移。

云端入口:新增 drain 感知的 ingress 闸门(建连超时与读超时分离,半关闭单向传播,
SIGTERM 排空后写 drain.json 并 exit 0/2)、compose 叠加片段(app 不再发布端口、
frontend 与 adapter 的入口收敛到闸门、指向真实网络 weknora-test-v071-network)、
执行器启动脚本与治理 PG 反向隧道脚本(默认 unix socket,不占 TCP)。

验证:deploy/cloud-test/test_gate.py 13 项全 PASS(含 12 秒静默流、半关闭、2MiB 完整、
排空 exit 0/active_at_close=1、排空超时 exit 2、上游不可达不挂住);go test 相关包全绿;
scripts/ci_checks.py 16 项全部 success(EXIT=0,1241 用例通过/0 失败/191 已声明可选集成跳过);
云测试只读预检 17 项 / 6 FAIL,FAIL 项即当前部署缺口(无闸门、app 仍发布端口、
adapter 与 frontend 仍直连 app、云端归档根未建),未部署、未改云端任何状态。
This commit is contained in:
姚章浩
2026-10-30 18:37:38 +08:00
parent a7d643635a
commit e6472b0ec6
24 changed files with 2409 additions and 117 deletions
+56 -1
View File
@@ -60,6 +60,8 @@ type options struct {
job string
dryRun bool
snapshot string
// bundle 是快照跨主机包路径(snapshot-pack 输出 / snapshot-unpack 输入)。
bundle string
// releasedDeadLetters 是治理平台审计过的精确解除指纹(逗号分隔)。它只让这些
// 确切的行不再阻断;实时行必须逐字节命中,否则照旧拒绝。
releasedDeadLetters string
@@ -100,6 +102,10 @@ func main() {
runErr = runRecover(ctx, opts)
case "dead-letters":
runErr = runDeadLetters(ctx, opts)
case "snapshot-pack":
runErr = runSnapshotPack(opts)
case "snapshot-unpack":
runErr = runSnapshotUnpack(opts)
default:
usage()
os.Exit(2)
@@ -111,7 +117,7 @@ func main() {
}
func usage() {
fmt.Fprint(os.Stderr, `libraryctl <status|preflight|capture|list|verify|recover|dead-letters> [flags]
fmt.Fprint(os.Stderr, `libraryctl <status|preflight|capture|list|verify|recover|dead-letters|snapshot-pack|snapshot-unpack> [flags]
status probe the real source and print what is configured / blocked
preflight read the source, run settlement + candidate validation (no writes, no stop)
@@ -121,6 +127,9 @@ func usage() {
recover restore writers from an interrupted freeze journal
dead-letters print the source's live dead letters (read-only) with a digest the
governance platform binds a precise release to
snapshot-pack export one sealed snapshot into a single verifiable bundle file
snapshot-unpack verify a bundle and install it into this archive (content-addressed,
version manifest is the commit point; repeated import is idempotent)
Flags (defaults target the local WKNFull test stack):
-source-app WKNFull-app container whose env describes the source
@@ -177,6 +186,7 @@ func parseFlags(command string, args []string) (options, []string, error) {
set.BoolVar(&opts.dryRun, "dry-run", false, "export and validate without archiving or stopping")
set.StringVar(&opts.snapshot, "snapshot", "", "snapshot id for verify")
set.StringVar(&opts.releasedDeadLetters, "released-dead-letters", "", "audited dead-letter fingerprints (comma separated)")
set.StringVar(&opts.bundle, "bundle", "", "snapshot bundle path (snapshot-pack / snapshot-unpack)")
if err := set.Parse(args); err != nil {
return opts, nil, err
}
@@ -1151,3 +1161,48 @@ func runDeadLetters(ctx context.Context, opts options) error {
printJSON(map[string]any{"observation": json.RawMessage(payload), "observation_digest": digest})
return nil
}
// runSnapshotPack 导出一份已封存版本,供另一台主机(发布执行器所在机)导入。
// 只读本机归档:不碰来源、不碰目标、不改任何版本。
func runSnapshotPack(opts options) error {
if opts.snapshot == "" || opts.bundle == "" {
return errors.New("snapshot-pack 需要 -snapshot <id> 与 -bundle <path>")
}
archive, err := openArchive(opts)
if err != nil {
return err
}
defer archive.Close()
info, err := archive.Pack(opts.snapshot, opts.bundle)
if err != nil {
return err
}
printJSON(info)
return nil
}
// runSnapshotUnpack 校验并装入快照包。装入是内容寻址 + 版本清单提交:
// 校验不通过就什么都不留下,重复导入是幂等成功。
func runSnapshotUnpack(opts options) error {
if opts.bundle == "" {
return errors.New("snapshot-unpack 需要 -bundle <path>(-snapshot 可选,用于核对身份)")
}
archive, err := openArchive(opts)
if err != nil {
return err
}
defer archive.Close()
manifest, err := archive.Unpack(opts.bundle, opts.snapshot)
if err != nil {
return err
}
printJSON(map[string]any{
"format": librarysnapshot.Format,
"scope": manifest.Scope,
"tenant_id": manifest.TenantID,
"knowledge_base_id": manifest.KnowledgeBaseID,
"parts": len(manifest.Parts),
"created_at": manifest.CreatedAt,
})
return nil
}