F02:测试封存作业只展示只读导出测试版本,不再套用备份生产/同步 Wiki/ 生产验证/生产生效,也不再写目标维护;运行和失败终态都保留真实 export 状态。同一挂载覆盖 running→failed。 F03:版本列表按每个 snapshot_id 精确查询恢复验证记录,与详情使用同一 endpoint;同 scope 最新 passed 不再给其他快照染色,未演练与读取失败分开。 封存失败:已恢复写入者且确定不可重试的捕获校验错误使用永久失败,避免 第二次 attempt 的 already exists 覆盖第一因;业务 job 的 error 在失败重试 中保留第一条,成功时清除。瞬时不可达/超时仍保留重试。 验证:Go/前端全量、隔离 PG 精确快照与首因测试、临时独立 ES 的 Current→Prepare→Verify PASS、make verify 17 项。host libraryctl 仍是旧 f9c15a8f...dirty,360 镜像未替换 host 工具,本轮只单独准备包不切换。
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"knowledge-governance/internal/jobs"
|
||||
)
|
||||
|
||||
func TestLibraryCaptureValidationFailureIsTerminal(t *testing.T) {
|
||||
original := errors.New("LIBRARYCTL_FAILED: unverified legacy library chunk index coverage;已执行 recover 并确认写入者恢复")
|
||||
got := terminalLibraryCaptureError(original)
|
||||
terminal, code := jobs.Terminal(got)
|
||||
if !terminal || code != jobs.ErrCodeValidationFailed {
|
||||
t.Fatalf("validation failure must park immediately: terminal=%v code=%q err=%v", terminal, code, got)
|
||||
}
|
||||
if got.Error() != original.Error() {
|
||||
t.Fatalf("original cause changed: got %q want %q", got.Error(), original.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func TestLibraryCaptureTransientFailureStillRetries(t *testing.T) {
|
||||
for _, message := range []string{
|
||||
"library agent is unreachable",
|
||||
"context deadline exceeded",
|
||||
`LIBRARYCTL_FAILED: job "lib-internal-x" already exists with state "failed";已执行 recover 并确认写入者恢复`,
|
||||
} {
|
||||
got := terminalLibraryCaptureError(errors.New(message))
|
||||
if terminal, code := jobs.Terminal(got); terminal {
|
||||
t.Fatalf("%q must stay retryable, got terminal code=%q", message, code)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestLibraryCaptureOriginalFailureSurvivesRetryOverwrite(t *testing.T) {
|
||||
// 队列第二次 attempt 的 already exists 不能替换第一因;分类器保留首个
|
||||
// 校验错误为永久失败,因此队列不会产生第二次自动 attempt。
|
||||
first := errors.New("LIBRARYCTL_FAILED: unverified legacy library chunk index coverage;已执行 recover 并确认写入者恢复")
|
||||
second := errors.New(`LIBRARYCTL_FAILED: job "lib-internal-20261105T054158" already exists with state "failed";已执行 recover 并确认写入者恢复`)
|
||||
classified := terminalLibraryCaptureError(first)
|
||||
if terminal, _ := jobs.Terminal(classified); !terminal {
|
||||
t.Fatal("first validation error must terminate before retry")
|
||||
}
|
||||
if terminal, _ := jobs.Terminal(second); terminal {
|
||||
t.Fatal("second retry error must not be terminal")
|
||||
}
|
||||
if !strings.Contains(classified.Error(), "unverified legacy library chunk index coverage") {
|
||||
t.Fatalf("first cause lost: %v", classified)
|
||||
}
|
||||
}
|
||||
+24
-1
@@ -101,6 +101,29 @@ func stageSizesFrom(manifest librarysnapshot.Manifest) map[string]stageSize {
|
||||
// libraryCaptureJobType is shared with the API which enqueues it.
|
||||
const libraryCaptureJobType = "library.capture"
|
||||
|
||||
// 这些是源库内容/索引覆盖的确定性校验失败,不是网络抖动。agent 已经
|
||||
// 执行 recover 并确认写入者恢复后,继续自动重试只会复用失败 journal,
|
||||
// 用第二次“already exists”覆盖真正的第一因。只对这类错误走永久失败;
|
||||
// 不可达、超时、journal 竞争等仍保留正常重试。
|
||||
var terminalLibraryCaptureMarkers = []string{
|
||||
"unverified legacy library chunk index coverage",
|
||||
"missing library generated question index",
|
||||
"missing indexed library chunk",
|
||||
"empty library index content",
|
||||
}
|
||||
|
||||
func terminalLibraryCaptureError(err error) error {
|
||||
if err == nil || !strings.Contains(err.Error(), "已执行 recover 并确认写入者恢复") {
|
||||
return err
|
||||
}
|
||||
for _, marker := range terminalLibraryCaptureMarkers {
|
||||
if strings.Contains(err.Error(), marker) {
|
||||
return jobs.Permanent(jobs.ErrCodeValidationFailed, err)
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// librarySyncJobType 是生产同步作业的队列类型;与封存严格分开,状态不共用。
|
||||
const librarySyncJobType = "library.sync"
|
||||
|
||||
@@ -365,7 +388,7 @@ func workerHandlers(store *postgresstore.Store, config appconfig.Config) (map[st
|
||||
_ = store.AdvanceLibraryJob(ctx, libraryJobID, governance.LibraryJobFailed, "export", err.Error(),
|
||||
"agent 已执行恢复检查;确认来源 healthy 后可重试同一作业号", "", "", finishedAt)
|
||||
log.Printf("library capture failed scope=%s capture_job=%s: %v", payload.Scope, payload.CaptureJob, err)
|
||||
return err
|
||||
return terminalLibraryCaptureError(err)
|
||||
}
|
||||
// 执行后复核:结果里 agent 自报的身份必须还是期望实例,否则这次封存
|
||||
// 可能来自别的栈,绝不能登记成"本实例的测试封存"。
|
||||
|
||||
Reference in New Issue
Block a user