fix(library): 预备份与归档类型按版本登记显示
两处契约错:prebackup 只认"与拟发布快照同内容的那一份",而恢复作业登记的是 恢复前备份(必然不同),于是刚备份完就显示"尚未创建";归档里同时有目标基线与 每次预备份,overview 不给登记类型,页面只能把每份都写成"测试封存"。 现在 prebackup 取最近一次已登记的那份,并给出所属作业与 bound_to_target; overview 新增不含 evidence 的轻量版本清单供页面标注每份快照。闸口判定不变。
This commit is contained in:
@@ -305,6 +305,62 @@ func TestLibrarySyncEnqueueCreatesJobOnlyWithGrant(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// 真实现场(2026-10-29 16:59 的按版本恢复):恢复作业登记了"恢复前备份",
|
||||
// 但那份备份的内容就是**恢复前**的生产状态,永远不可能等于测试封存快照。
|
||||
// 旧逻辑只认"与测试封存同快照的预备份",于是刚备份完就显示"尚未创建/无记录"。
|
||||
func TestLibraryOverviewShowsLatestPrebackupWhenTargetDiffers(t *testing.T) {
|
||||
root := libraryFixtureRoot(t)
|
||||
sealed := sealSharedVersions(t, root, 1, 4)[0]
|
||||
now := time.Now().UTC()
|
||||
store := &fakeLibraryStore{versions: []governance.LibraryVersion{
|
||||
{ID: "ver-effective", Scope: "internal", Kind: governance.LibraryVersionProductionEffective,
|
||||
SnapshotID: "prod-restored-snapshot", CreatedAt: now},
|
||||
{ID: "ver-prebackup", Scope: "internal", Kind: governance.LibraryVersionProductionPrebackup,
|
||||
SnapshotID: "snap-before-restore", SourceJobID: "librestore-internal-1", CreatedAt: now.Add(-time.Second)},
|
||||
{ID: "ver-sealed", Scope: "internal", Kind: governance.LibraryVersionTestSealed,
|
||||
SnapshotID: sealed, CreatedAt: now.Add(-2 * time.Hour)},
|
||||
}}
|
||||
config := Config{Store: store, LibraryArchiveRoot: root, LibraryCapacityBudgetBytes: 1 << 30}
|
||||
request := httptest.NewRequest(http.MethodGet, "/api/v1/library/overview?scope=internal", nil)
|
||||
recorder := httptest.NewRecorder()
|
||||
libraryOverviewHandler(recorder, request, config)
|
||||
if recorder.Code != http.StatusOK {
|
||||
t.Fatalf("status = %d: %s", recorder.Code, recorder.Body.String())
|
||||
}
|
||||
var body struct {
|
||||
Production libraryKnownView `json:"production"`
|
||||
Prebackup libraryKnownView `json:"prebackup"`
|
||||
Versions []libraryVersionRef `json:"versions"`
|
||||
TestSealed *librarySnapshotView `json:"test_sealed"`
|
||||
Gate struct {
|
||||
SyncAllowed bool `json:"sync_allowed"`
|
||||
Reasons []string `json:"reasons"`
|
||||
} `json:"gate"`
|
||||
}
|
||||
if err := json.Unmarshal(recorder.Body.Bytes(), &body); err != nil {
|
||||
t.Fatalf("decode overview: %v", err)
|
||||
}
|
||||
if body.TestSealed == nil || body.TestSealed.SnapshotID != sealed {
|
||||
t.Fatalf("test sealed candidate must be the registered one: %+v", body.TestSealed)
|
||||
}
|
||||
if body.Prebackup.State != "known" || body.Prebackup.Version == nil ||
|
||||
body.Prebackup.Version.ID != "ver-prebackup" || body.Prebackup.Version.SourceJobID != "librestore-internal-1" {
|
||||
t.Fatalf("latest registered prebackup must be visible with its job: %+v", body.Prebackup)
|
||||
}
|
||||
if body.Prebackup.BoundToTarget {
|
||||
t.Fatal("a restore prebackup is not the publish target snapshot")
|
||||
}
|
||||
// 三类版本都要出现在轻量清单里,页面才能给每份归档写对类型。
|
||||
if len(body.Versions) != 3 {
|
||||
t.Fatalf("versions = %+v", body.Versions)
|
||||
}
|
||||
for _, reason := range body.Gate.Reasons {
|
||||
if strings.Contains(reason, "预备份") {
|
||||
t.Fatalf("a registered prebackup must not be reported as missing: %q", reason)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 三类版本必须分开读:production_effective 才是生产当前,测试封存不能顶替。
|
||||
func TestLibraryOverviewKeepsVersionKindsSeparate(t *testing.T) {
|
||||
now := time.Now().UTC()
|
||||
@@ -323,8 +379,9 @@ func TestLibraryOverviewKeepsVersionKindsSeparate(t *testing.T) {
|
||||
t.Fatalf("status = %d: %s", recorder.Code, recorder.Body.String())
|
||||
}
|
||||
var body struct {
|
||||
Production libraryKnownView `json:"production"`
|
||||
Prebackup libraryKnownView `json:"prebackup"`
|
||||
Production libraryKnownView `json:"production"`
|
||||
Prebackup libraryKnownView `json:"prebackup"`
|
||||
Versions []libraryVersionRef `json:"versions"`
|
||||
Diff struct {
|
||||
State string `json:"state"`
|
||||
} `json:"diff"`
|
||||
@@ -338,9 +395,17 @@ func TestLibraryOverviewKeepsVersionKindsSeparate(t *testing.T) {
|
||||
if body.Production.State != "known" || body.Production.Version == nil || body.Production.Version.ID != "ver-prod" {
|
||||
t.Fatalf("production must be the effective version, got %+v", body.Production)
|
||||
}
|
||||
// 预备份只对匹配目标快照的那一份生效;这里目标为空(归档不可用),所以是未知。
|
||||
if body.Prebackup.State != "unknown" {
|
||||
t.Fatalf("prebackup must stay unknown without a matching target snapshot: %+v", body.Prebackup)
|
||||
// 预备份按"最近一次生产写入前的备份"显示:归档不可用时没有可匹配的目标,
|
||||
// 但登记过的预备份必须仍然可见(否则真备份了却显示"尚未创建"),
|
||||
// 并且明确标出它并不是本次拟发布快照。
|
||||
if body.Prebackup.State != "known" || body.Prebackup.Version == nil || body.Prebackup.Version.ID != "ver-backup-other" {
|
||||
t.Fatalf("registered prebackup must stay visible: %+v", body.Prebackup)
|
||||
}
|
||||
if body.Prebackup.BoundToTarget {
|
||||
t.Fatalf("prebackup must not claim to be the publish target without one: %+v", body.Prebackup)
|
||||
}
|
||||
if len(body.Versions) != 3 {
|
||||
t.Fatalf("overview must expose every registered version kind, got %+v", body.Versions)
|
||||
}
|
||||
if body.Diff.State != "unknown" {
|
||||
t.Fatalf("diff must be unknown until the comparison is wired, got %q", body.Diff.State)
|
||||
|
||||
Reference in New Issue
Block a user