From 26305cacf91f8a2e20e5a232a7a036a1bb82fb2c Mon Sep 17 00:00:00 2001 From: weichen Date: Wed, 14 Oct 2026 14:09:01 +0000 Subject: [PATCH] Assert account directory cursor fidelity in migration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Why: The U3 migration must replace the target schema seed with the source directory revision and cursor key. Evidence: Isolated PostgreSQL TestMigrateEndToEndAndIdempotent passed with field-by-field source and target comparison. Impact: Migration regressions that lose directory cursor identity now fail the existing end-to-end test. Refs: IAM U3 Stage 7; docs/proposals/2026-10-14-iam-u3-account-contract-and-plan.md §10 --- cmd/storage-migrate/integration_test.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/cmd/storage-migrate/integration_test.go b/cmd/storage-migrate/integration_test.go index d4997c0..1d15c90 100644 --- a/cmd/storage-migrate/integration_test.go +++ b/cmd/storage-migrate/integration_test.go @@ -45,6 +45,18 @@ func TestMigrateEndToEndAndIdempotent(t *testing.T) { target, cleanup := pgSchemaDSN(t) defer cleanup() fixture := buildFixture(t) + src, err := sql.Open("sqlite", fixture) + if err != nil { + t.Fatal(err) + } + defer src.Close() + var sourcePublic, sourceStaff, sourcePrivate, sourceSecret string + var sourceKeyVersion int64 + if err := src.QueryRow(`SELECT public_revision,staff_no_revision,private_revision,cursor_key_version,cursor_secret FROM account_directory_revision WHERE id=1`).Scan( + &sourcePublic, &sourceStaff, &sourcePrivate, &sourceKeyVersion, &sourceSecret, + ); err != nil { + t.Fatal(err) + } if err := cmdMigrate([]string{"--source", fixture, "--target", target, "--migration-id", "mig-e2e"}); err != nil { t.Fatalf("首次迁移:%v", err) @@ -61,6 +73,16 @@ func TestMigrateEndToEndAndIdempotent(t *testing.T) { } defer st.Close() db := st.DB() + var targetPublic, targetStaff, targetPrivate, targetSecret string + var targetKeyVersion int64 + if err := db.QueryRow(`SELECT public_revision,staff_no_revision,private_revision,cursor_key_version,cursor_secret FROM account_directory_revision WHERE id=1`).Scan( + &targetPublic, &targetStaff, &targetPrivate, &targetKeyVersion, &targetSecret, + ); err != nil { + t.Fatal(err) + } + if targetPublic != sourcePublic || targetStaff != sourceStaff || targetPrivate != sourcePrivate || targetKeyVersion != sourceKeyVersion || targetSecret != sourceSecret { + t.Fatal("迁移后的目录版本或游标密钥与源库不一致") + } var pinned, archived bool if err := db.QueryRow(`SELECT pinned, archived FROM conversations WHERE id='c1'`).Scan(&pinned, &archived); err != nil || !pinned || archived { t.Fatalf("布尔映射:pinned=%v archived=%v err=%v", pinned, archived, err)