fix(library): 续作在事务内校验阶段并原子入队
build / build (push) Successful in 1m29s

This commit is contained in:
姚章浩
2026-11-01 22:05:02 +08:00
parent e292b6f674
commit a98828dc4a
6 changed files with 363 additions and 43 deletions
+26
View File
@@ -33,6 +33,10 @@ type fakeLibraryStore struct {
// operations/lastOperation 记录"意图身份":重放与换键的差别在这里表达(F01)。
operations map[string]governance.LibraryOperation
lastOperation governance.LibraryOperation
// 续作:resumeOK/resumeErr 驱动存储层结果,resumeCalls 记录每次调用(断言不重复投递)。
resumeOK bool
resumeErr error
resumeCalls []string
}
func (f *fakeLibraryStore) CreateLibraryJob(_ context.Context, job governance.LibraryJob, _ []string, _ time.Time) (governance.LibraryJob, bool, error) {
@@ -59,6 +63,11 @@ func (f *fakeLibraryStore) EnsureLibraryOperation(_ context.Context, op governan
}
func (f *fakeLibraryStore) LibraryJob(_ context.Context, id string) (governance.LibraryJob, error) {
for _, job := range f.jobs {
if job.ID == id {
return job, nil
}
}
return governance.LibraryJob{ID: id}, nil
}
@@ -178,6 +187,23 @@ func (f *fakeLibraryStore) ResetQueueJobForResume(_ context.Context, _ string, _
return nil
}
// ResumeLibraryJob 模拟存储层事务语义:结果由 resumeResult 驱动,调用次数可断言"重复请求不重复投递"。
func (f *fakeLibraryStore) ResumeLibraryJob(_ context.Context, jobID, queueType string, _ time.Time) (governance.LibraryJob, bool, error) {
f.resumeCalls = append(f.resumeCalls, jobID+"/"+queueType)
if f.resumeErr != nil {
return governance.LibraryJob{}, false, f.resumeErr
}
if !f.resumeOK {
return governance.LibraryJob{}, false, nil
}
for _, job := range f.jobs {
if job.ID == jobID {
return job, true, nil
}
}
return governance.LibraryJob{}, false, nil
}
func TestLibrarySyncGateRequiresEveryPieceOfEvidence(t *testing.T) {
known := libraryKnownView{State: "known", Version: &libraryVersionView{ID: "v1"}}
cases := []struct {