From 71b3ab1d5dbb0702da576158e85baf5a25d50dc2 Mon Sep 17 00:00:00 2001 From: MS-01-Codex <3647348c-0c07-48e0-8938-fb9280321c5f@agents.multica.local> Date: Tue, 18 Aug 2026 20:12:18 +0800 Subject: [PATCH] test: cover m0004 add_mentor_note migration paths Co-authored-by: multica-agent --- tests/test_database_migrations.py | 90 +++++++++++++++++++++++++++---- 1 file changed, 81 insertions(+), 9 deletions(-) diff --git a/tests/test_database_migrations.py b/tests/test_database_migrations.py index efccab1..4c72bf3 100644 --- a/tests/test_database_migrations.py +++ b/tests/test_database_migrations.py @@ -18,20 +18,92 @@ class DatabaseMigrationTests(unittest.TestCase): rows = connection.execute( "SELECT version, name FROM schema_migrations" ).fetchall() - self.assertEqual( - [(row["version"], row["name"]) for row in rows], - [ - ("0001", "adopt_legacy_schema"), - ("0002", "create_job_runs"), - ("0003", "extend_llm_audit"), - ], - ) + self.assertEqual( + [(row["version"], row["name"]) for row in rows], + [ + ("0001", "adopt_legacy_schema"), + ("0002", "create_job_runs"), + ("0003", "extend_llm_audit"), + ("0004", "add_mentor_note"), + ], + ) + columns = { + str(row["name"]) + for row in connection.execute( + "PRAGMA table_info(mentor_preferences)" + ) + } + self.assertIn("note", columns) ReviewDatabase(path) with database.connect() as connection: count = connection.execute( "SELECT COUNT(*) AS count FROM schema_migrations" ).fetchone()["count"] - self.assertEqual(count, 3) + self.assertEqual(count, 4) + + def test_database_with_recorded_0004_and_note_column_starts_without_reapply( + self, + ) -> None: + with tempfile.TemporaryDirectory() as root: + path = Path(root) / "review.db" + database = ReviewDatabase(path) + with database.connect() as connection: + note_rows = [ + str(row["name"]) + for row in connection.execute( + "PRAGMA table_info(mentor_preferences)" + ) + ] + self.assertIn("note", note_rows) + ReviewDatabase(path) + with database.connect() as connection: + count = connection.execute( + "SELECT COUNT(*) AS count FROM schema_migrations" + ).fetchone()["count"] + self.assertEqual(count, 4) + + def test_old_database_without_0004_upgrades_and_adds_note_column(self) -> None: + with tempfile.TemporaryDirectory() as root: + path = Path(root) / "review.db" + database = ReviewDatabase(path) + with database.connect() as connection: + connection.execute( + "DELETE FROM schema_migrations WHERE version = '0004'" + ) + connection.execute( + "ALTER TABLE mentor_preferences DROP COLUMN note" + ) + ReviewDatabase(path) + with database.connect() as connection: + versions = { + str(row["version"]) + for row in connection.execute( + "SELECT version FROM schema_migrations" + ) + } + note_rows = [ + str(row["name"]) + for row in connection.execute( + "PRAGMA table_info(mentor_preferences)" + ) + ] + self.assertEqual(versions, {"0001", "0002", "0003", "0004"}) + self.assertIn("note", note_rows) + + def test_database_with_unknown_migration_is_rejected(self) -> None: + with tempfile.TemporaryDirectory() as root: + path = Path(root) / "review.db" + database = ReviewDatabase(path) + with database.connect() as connection: + connection.execute( + """ + INSERT INTO schema_migrations + (version, name, checksum, applied_at) + VALUES ('9999', 'unknown_legacy', 'x', '2026-08-01T00:00:00+00:00') + """ + ) + with self.assertRaises(MigrationError): + ReviewDatabase(path) def test_connection_factory_enables_required_pragmas(self) -> None: with tempfile.TemporaryDirectory() as root: