From a307c6ca2ccb9a6a108b26a1f8be2c4c9162e3c0 Mon Sep 17 00:00:00 2001 From: wangjia <809946525@qq.com> Date: Wed, 29 Jul 2026 07:08:56 +0800 Subject: [PATCH] =?UTF-8?q?fix(test):=20codes-lib=20=E8=BF=81=E7=A7=BB?= =?UTF-8?q?=E5=BE=80=E8=BF=94=E6=B5=8B=E8=AF=95=E6=94=B9=E7=94=A8=20m.Migr?= =?UTF-8?q?ate(21)=20=E6=98=BE=E5=BC=8F=E5=AE=9A=E4=BD=8D=E7=89=88?= =?UTF-8?q?=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit TestCodesLibMigrateRoundTrip 硬编码 6 次 Steps(-1),假设 000027 是迁移栈顶;本功能 加了 000028_routing_profiles 后 6 步落在版本 22、跳过了 000022 down,导致断言失败。 根因不是迁移 SQL(000022 up/down 正确、codes-lib 表无 FK——推翻了 FK 假设),而是 测试的脆弱步数计数被新增迁移打乱。改用 m.Migrate(21) 显式降到 000022 down 之后的 边界,不受栈顶新增迁移影响。全仓 go test ./... 恢复 0 FAIL。 Co-Authored-By: Claude Opus 4.8 Claude-Session: https://claude.ai/code/session_01A79VtQA1BwTuQN1ThpvYpo --- .../internal/store/codes_lib_migrate_test.go | 29 ++++--------------- 1 file changed, 6 insertions(+), 23 deletions(-) diff --git a/server/internal/store/codes_lib_migrate_test.go b/server/internal/store/codes_lib_migrate_test.go index 529c2ae..9dbd61b 100644 --- a/server/internal/store/codes_lib_migrate_test.go +++ b/server/internal/store/codes_lib_migrate_test.go @@ -104,29 +104,12 @@ func TestCodesLibMigrateRoundTrip(t *testing.T) { // the reviewer's repro hit: the lib's `codes` table collides with the // name 000022's down script renames legacy_codes back to. m := newSQLiteStepper(t, db) - // 000027 (pay_promo_paid_unique), 000026 (notices), 000025 - // (user_device_limit_override), 000024 (invite_rewards) and 000023 - // (pay_purchases/source-enum) now sit on top of 000022 - // (codes_lib_legacy_rename) and are unrelated to this collision — step - // them back down first so we land exactly on the 000022 boundary the - // test targets. - if err := m.Steps(-1); err != nil { - t.Fatalf("step 000027 down: %v", err) - } - if err := m.Steps(-1); err != nil { - t.Fatalf("step 000026 down: %v", err) - } - if err := m.Steps(-1); err != nil { - t.Fatalf("step 000025 down: %v", err) - } - if err := m.Steps(-1); err != nil { - t.Fatalf("step 000024 down: %v", err) - } - if err := m.Steps(-1); err != nil { - t.Fatalf("step 000023 down: %v", err) - } - if err := m.Steps(-1); err != nil { - t.Fatalf("step 000022 down: %v (this is the reviewer-reported collision — "+ + // 所有排在 000022 之上的迁移(000023..最新,如 pay_purchases / invite_rewards / + // notices / routing_profiles …)都与本冲突无关 —— 一次性降到版本 21,恰好落在 + // 000022(codes_lib_legacy_rename)down 之后的边界。用版本号显式定位而非硬编码 + // Steps(-1) 计数,避免栈顶新增迁移(如 000028)后步数漂移、跳过 000022 down。 + if err := m.Migrate(21); err != nil { + t.Fatalf("migrate down to v21 (past 000022 down): %v (this is the reviewer-reported collision — "+ "000022 down must DROP the codes-lib tables before renaming legacy_* back)", err) }