Assert account directory cursor fidelity in migration
ci / vet-and-test (pull_request) Failing after 46s

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
This commit is contained in:
2026-10-14 14:09:01 +00:00
parent b080e98388
commit 26305cacf9
+22
View File
@@ -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)