fix(worker): 写集合预检经包装层转发,缺失即拒写
orchestrator 用 target.(WriteSetPlanner) 决定要不要在写第一笔之前算写集合, 而 contentTrackedTarget 只转发了 Current/Apply/Verify/Restore,断言恒为假, 台账既不落盘也不登记。真实现场:10-29 两次真作业的预备份证据里没有 writeset_digest,归档根下没有 writesets/,崩溃接管必然无台账可读。 现在包装层显式转发;内层不支持预检时返回硬错误,不退回"没有台账也照写"。 用例断言包装后仍实现 WriteSetPlanner,并覆盖"内层不支持"的硬错误。
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -147,3 +148,51 @@ func TestLedgerBackupStoreRefusesWithoutWriteSet(t *testing.T) {
|
||||
t.Fatalf("接管必须带上持久化的写集合:%+v", ref)
|
||||
}
|
||||
}
|
||||
|
||||
// 包装层必须把"写集合预检"这件事透出去:orchestrator 用的是类型断言,
|
||||
// 少一个方法就等于静默跳过台账(真实后果:真作业没有 writeset_digest、也没有
|
||||
// writesets/ 文件,崩溃接管无台账可读)。
|
||||
type plainTarget struct{ applied int }
|
||||
|
||||
func (t *plainTarget) Current(context.Context) (libraryrelease.CurrentState, error) {
|
||||
return libraryrelease.CurrentState{}, nil
|
||||
}
|
||||
func (t *plainTarget) Apply(context.Context, libraryrelease.Stage, string) error {
|
||||
t.applied++
|
||||
return nil
|
||||
}
|
||||
func (t *plainTarget) Verify(context.Context, libraryrelease.Expectation) error { return nil }
|
||||
func (t *plainTarget) Restore(context.Context, libraryrelease.BackupRef) error { return nil }
|
||||
|
||||
type planningTarget struct {
|
||||
plainTarget
|
||||
planned int
|
||||
}
|
||||
|
||||
func (t *planningTarget) PlanWriteSet(context.Context, libraryrelease.WriteSetPlan) (libraryrelease.WriteSet, error) {
|
||||
t.planned++
|
||||
return libraryrelease.WriteSet{Version: libraryrelease.WriteSetVersion, JobID: "job-1", Target: "internal"}, nil
|
||||
}
|
||||
|
||||
func TestContentTrackedTargetForwardsWriteSetPlanning(t *testing.T) {
|
||||
inner := &planningTarget{}
|
||||
wrapped := &contentTrackedTarget{inner: inner, onApply: func() {}}
|
||||
planner, ok := libraryrelease.Target(wrapped).(libraryrelease.WriteSetPlanner)
|
||||
if !ok {
|
||||
t.Fatal("包装后的目标必须仍然实现 WriteSetPlanner,否则写集合会被静默跳过")
|
||||
}
|
||||
if _, err := planner.PlanWriteSet(context.Background(), libraryrelease.WriteSetPlan{JobID: "job-1", Target: "internal"}); err != nil {
|
||||
t.Fatalf("plan: %v", err)
|
||||
}
|
||||
if inner.planned != 1 {
|
||||
t.Fatalf("预检必须落到内层目标,planned=%d", inner.planned)
|
||||
}
|
||||
|
||||
// 内层不支持预检 ⇒ 硬错误,不许"没有台账也照写"。
|
||||
strict := &contentTrackedTarget{inner: &plainTarget{}, onApply: func() {}}
|
||||
if _, err := strict.PlanWriteSet(context.Background(), libraryrelease.WriteSetPlan{}); err == nil {
|
||||
t.Fatal("内层不支持写集合预检时必须报错")
|
||||
} else if !strings.Contains(err.Error(), "写集合") {
|
||||
t.Fatalf("错误必须点名写集合:%v", err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user