fix(library): 预备份与归档类型按版本登记显示

两处契约错:prebackup 只认"与拟发布快照同内容的那一份",而恢复作业登记的是
恢复前备份(必然不同),于是刚备份完就显示"尚未创建";归档里同时有目标基线与
每次预备份,overview 不给登记类型,页面只能把每份都写成"测试封存"。

现在 prebackup 取最近一次已登记的那份,并给出所属作业与 bound_to_target;
overview 新增不含 evidence 的轻量版本清单供页面标注每份快照。闸口判定不变。
This commit is contained in:
姚章浩
2026-10-30 01:33:50 +08:00
parent 72ea9726e7
commit 402173263e
2 changed files with 105 additions and 14 deletions
+35 -9
View File
@@ -55,6 +55,10 @@ type libraryKnownView struct {
// EmptyBaseline 表示"没有生效版本记录,但生产目标可读且确实是空的":
// 这是首次发布的合法起点,和"生产非空却没有权威版本"必须区分。
EmptyBaseline bool `json:"empty_baseline,omitempty"`
// BoundToTarget 只对预备份有意义:这份备份的内容是否就是当前待发布目标。
// 最近一次生产写入前的备份可能**不是**本次目标(例如刚按版本恢复过),
// 页面必须照实说是哪一次作业的备份,而不是一句"尚未创建"。
BoundToTarget bool `json:"bound_to_target,omitempty"`
}
// productionScopeState 只读探测生产目标:真正连库数一遍,不用缓存或推断。
@@ -302,11 +306,14 @@ type libraryGateView struct {
}
type libraryOverview struct {
Scope string `json:"scope"`
TestSealed *librarySnapshotView `json:"test_sealed,omitempty"`
TestSealedReason string `json:"test_sealed_reason,omitempty"`
Production libraryKnownView `json:"production"`
Prebackup libraryKnownView `json:"prebackup"`
Scope string `json:"scope"`
TestSealed *librarySnapshotView `json:"test_sealed,omitempty"`
TestSealedReason string `json:"test_sealed_reason,omitempty"`
Production libraryKnownView `json:"production"`
Prebackup libraryKnownView `json:"prebackup"`
// Versions 是已登记版本的轻量清单(不含 evidence):页面要按快照判断
// "这份归档是哪一类版本",不能把所有归档都写成测试封存。
Versions []libraryVersionRef `json:"versions"`
Diff libraryDiffView `json:"diff"`
Job *governance.LibraryJob `json:"job,omitempty"`
Jobs []governance.LibraryJob `json:"jobs"`
@@ -318,6 +325,17 @@ type libraryOverview struct {
Now time.Time `json:"now"`
}
// libraryVersionRef 只回答"这个快照被登记成哪一类版本、由哪个作业登记"。
type libraryVersionRef struct {
ID string `json:"id"`
Kind string `json:"kind"`
SnapshotID string `json:"snapshot_id"`
VersionLabel string `json:"version_label"`
SourceJobID string `json:"source_job_id"`
CreatedAt time.Time `json:"created_at"`
SupersededAt *time.Time `json:"superseded_at,omitempty"`
}
type libraryJobStore interface {
CreateLibraryJob(ctx context.Context, job governance.LibraryJob, stages []string, now time.Time) (governance.LibraryJob, bool, error)
LibraryJob(ctx context.Context, id string) (governance.LibraryJob, error)
@@ -669,7 +687,7 @@ func libraryOverviewHandler(w http.ResponseWriter, r *http.Request, config Confi
overview.TestSealed, overview.TestSealedReason = testSealedOf(versions, byID)
}
overview.Production = libraryKnownView{State: "unknown", Reason: "还没有生产验证通过的生效版本记录"}
overview.Prebackup = libraryKnownView{State: "unknown", Reason: "本次目标快照还没有生产预备份"}
overview.Prebackup = libraryKnownView{State: "unknown", Reason: "这个范围还没有任何生产预备份"}
target := ""
if overview.TestSealed != nil {
target = overview.TestSealed.SnapshotID
@@ -677,15 +695,23 @@ func libraryOverviewHandler(w http.ResponseWriter, r *http.Request, config Confi
for index := range versions {
item := versions[index]
view := libraryVersionViewOf(item)
overview.Versions = append(overview.Versions, libraryVersionRef{
ID: item.ID, Kind: string(item.Kind), SnapshotID: item.SnapshotID, VersionLabel: item.VersionLabel,
SourceJobID: item.SourceJobID, CreatedAt: item.CreatedAt, SupersededAt: item.SupersededAt,
})
switch item.Kind {
case governance.LibraryVersionProductionEffective:
if item.SupersededAt == nil {
overview.Production = libraryKnownView{State: "known", Version: &view}
}
case governance.LibraryVersionProductionPrebackup:
// 只有与目标快照绑定的预备份才算"这次同步前的备份"。
if target != "" && item.SnapshotID == target {
overview.Prebackup = libraryKnownView{State: "known", Version: &view}
// 页面要显示"最近一次生产写入前的备份",不是"与拟发布快照同内容的那一份":
// 恢复作业登记的是**恢复前**的备份,它和测试封存快照本来就不同;
// 只按目标匹配会让真登记过的预备份显示成"尚未创建"。
// versions 已按时间倒序,第一份就是最近一次;是否与本次目标同快照另给标志。
if overview.Prebackup.State != "known" {
overview.Prebackup = libraryKnownView{State: "known", Version: &view,
BoundToTarget: target != "" && item.SnapshotID == target}
}
}
}