test(migrations): 断言改为校验真实意图,避免新增迁移即误报
AIOps CI / Backend (test, vet, build) (push) Canceled after 0s
AIOps CI / Agent (test, vet, build) (push) Canceled after 0s
AIOps CI / Frontend (typecheck, lint, build) (push) Canceled after 0s
AIOps CI / API integration (SQLite + redka) (push) Canceled after 0s

原断言写死"旧库只应补跑 0002/0003 两条迁移",
新增 0004_metric_aggregate_unique 与 0005_agent_settings 后必然失败。

改为校验:不得重跑基线、不得重跑 0001,
且 0002/0003 必须被执行——这才是该用例真正要守护的行为。

// Logan.Li
This commit is contained in:
Logan.Li committed 2026-10-18 20:10:23 +00:00
1 parent b4521d13a1
commit 8c49dd22b0
1 file changed
+24 -2
+24 -2
View File
@@ -107,9 +107,31 @@ func TestBaselineDoesNotAlterProductionLikeSchema(t *testing.T) {
if err != nil {
t.Fatalf("旧库执行后续迁移失败: %v", err)
}
if len(applied) != 2 || applied[0] != "0002_legacy_schema_patches" || applied[1] != "0003_billing_settings" {
t.Fatalf("旧库不应重跑 0001,实际执行: %v", applied)
// 断言真实意图:旧库不得重跑基线,且已登记的后续迁移不能再执行。
// 不再写死迁移条数——否则每新增一个迁移都会误报。 // Logan.Li
for _, v := range applied {
if v == BaselineVersion {
t.Fatalf("旧库不应重跑基线 %s,实际执行: %v", BaselineVersion, applied)
}
if v == "0001_agent_credentials" {
t.Fatalf("旧库不应重跑 0001,实际执行: %v", applied)
}
}
for _, want := range []string{"0002_legacy_schema_patches", "0003_billing_settings"} {
if !containsString(applied, want) {
t.Fatalf("旧库应补跑迁移 %s,实际执行: %v", want, applied)
}
}
}
// containsString 判断字符串切片是否包含目标值。 // Logan.Li
func containsString(list []string, want string) bool {
for _, v := range list {
if v == want {
return true
}
}
return false
}
// schemaDefinitions 读取 SQLite 表定义,供基线非破坏性回归测试使用。 // Logan.Li