From 593aa74c6182ce2e5e23bc102daaaae71710c05d Mon Sep 17 00:00:00 2001 From: kshitijk4poor <82637225+kshitijk4poor@users.noreply.github.com> Date: Thu, 3 Sep 2026 04:00:56 +0530 Subject: [PATCH] test(state): pin that a v28 install still runs the trigram cron-exclusion migration The salvaged #101266 gated its rebuild on current_version < 27; main had already reached SCHEMA_VERSION 28 (column-reconciliation bumps), so on any existing install the gate would never fire and cron rows would stay in the trigram index forever. The cherry-pick resolution renumbers to v29; this test seeds a v28 database and asserts the migration runs. Mutation-checked against the original < 27 gate. --- .../state/test_fts_trigram_cron_exclusion.py | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tests/state/test_fts_trigram_cron_exclusion.py b/tests/state/test_fts_trigram_cron_exclusion.py index 14f85ce2f8..7fe99dfc7d 100644 --- a/tests/state/test_fts_trigram_cron_exclusion.py +++ b/tests/state/test_fts_trigram_cron_exclusion.py @@ -129,6 +129,38 @@ def test_existing_external_layout_rebuilds_trigram_on_upgrade(tmp_path): migrated.close() +def test_install_already_at_v28_still_gets_the_cron_exclusion_migration(tmp_path): + """The migration gate must fire for installs that were on main's v28. + + The original PR gated on ``current_version < 27``; main had meanwhile + reached SCHEMA_VERSION 28 via column-reconciliation bumps, so a v28 + database would have skipped the rebuild and kept cron rows in the trigram + index forever. Pin the gate against the version main actually shipped. + """ + db_path = tmp_path / "state.db" + old = SessionDB(db_path=db_path) + if not old._trigram_available: + old.close() + pytest.skip("trigram tokenizer unavailable in this SQLite build") + _install_pre_v27_trigram(old) + old.create_session("cli", source="cli") + old.create_session("cron", source="cron") + cli_id = old.append_message("cli", role="user", content="交互迁移内容") + cron_id = old.append_message("cron", role="user", content="定时迁移内容") + assert _trigram_rowids(old) == {cli_id, cron_id} + old._conn.execute("UPDATE schema_version SET version = 28") + old._conn.commit() + old.close() + + migrated = SessionDB(db_path=db_path) + try: + assert _trigram_rowids(migrated) == {cli_id}, ( + "a v28 database kept cron rows in the trigram index: the migration gate did not fire" + ) + finally: + migrated.close() + + def test_partial_upgrade_view_does_not_skip_historical_rebuild(tmp_path): db_path = tmp_path / "state.db" old = SessionDB(db_path=db_path)