From 3ac8d8f2460cab8f527cdb333d359008ccd404b9 Mon Sep 17 00:00:00 2001 From: ted Date: Tue, 1 Dec 2026 21:08:47 +0800 Subject: [PATCH] test(pg): stop pinning migration 012 as the last PG migration in pg-log-writer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 变更摘要 - 改前:`test/unit/pg-log-writer.test.mjs` 的“PG migrations 011 and 012 …”用例断言 `applyPgMigrations()` 返回的最后一个迁移是 `012_optimize_usage_logs_and_attempts_indexes.sql`。`292743b1f`(2026-11-30)新增 `013_codex_slot_runtime.sql` 时没有同步它,用例自 11-30 起在 `origin/dev` 基线上就是红的(实得 `013_…`);它用 mock 池、不需要真实 PG 就会红,但文件不在 `test:ci` 固定集合里,所以一直没人发现。新增迁移的 PR(例如 #2441 的 `014_vm_daily_session_creations.sql`)每次都会让它多红一次。 - 改后:用例改为用迁移目录里按文件名排序的最后一个文件作为期望,并断言 011 与 012 都被应用且 012 在 011 之后;以后再增加迁移不必回头改它。只改这一个测试文件,没有改任何迁移或生产代码。 - 未改 / 延后:其它仍在基线上红的用例(例如 `scoped-intercept-session`、`scheduler-m0-migrations`、`issue-1776-active-usage-reconcile`、`kernel-switch-recovery`)不在本次范围。 ## 验收记录(Run) - 本机(Node 24)`pg-log-writer` 17 个用例 16 通过、0 失败(1 个依赖真实 PG 的用例被跳过);修复前该用例失败(实得 `013_codex_slot_runtime.sql`)。`biome format` 无需修改。 ## 回退与手破验证(Broken by hand) - 3 处手破(还原后 sha256 一致):往迁移目录临时加一个 `999_zz_tmp_probe.sql` 后用例仍绿(不再钉死 012);把断言改回 `mig012` 在存在新迁移文件时变红;把期望改成错误文件名变红。 ## 真实使用(Real use) - 不适用:只改测试,没有真实 PG;没有 `ph24`。 ## 未运行项(Not run) - 真实 PG18 上的迁移应用不在本测试范围;`npm run test:ci` 由 GitHub `ci` 检查覆盖。 --- test/unit/pg-log-writer.test.mjs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/test/unit/pg-log-writer.test.mjs b/test/unit/pg-log-writer.test.mjs index d1c5bba7cc..f8b0bbb92f 100644 --- a/test/unit/pg-log-writer.test.mjs +++ b/test/unit/pg-log-writer.test.mjs @@ -181,7 +181,13 @@ test('PG migrations 011 and 012 optimize usage_logs/request_attempts/account_all const mockPool = { connect: async () => client } const first = await applyPgMigrations(mockPool) - assert.equal(first.at(-1), mig012) + // The runner applies every migration file in order; do not pin 012 as the last one (newer migrations land after it). + const migrationFiles = fs + .readdirSync(PG_MIGRATIONS_DIR) + .filter((name) => name.endsWith('.sql')) + .sort() + assert.equal(first.at(-1), migrationFiles.at(-1)) + assert.ok(first.includes(mig011) && first.indexOf(mig012) > first.indexOf(mig011)) assert.ok(executedSql.some((s) => s.includes('DROP INDEX IF EXISTS idx_reqlog_cost_ts'))) assert.ok(executedSql.some((s) => s.includes('DROP INDEX IF EXISTS idx_request_attempt_request'))) assert.ok(executedSql.some((s) => s.includes('idx_alloc_account_id_desc')))