From e351c3836853edc3befb860a4666b7cc2f5bb424 Mon Sep 17 00:00:00 2001 From: ZdenekSrotyr Date: Sun, 12 Apr 2026 08:40:12 +0200 Subject: [PATCH] test: add correctness test for _reattach_remote_extensions Verifies that _remote_attach table is actually found via table_catalog and contains expected extension data (not just resilience). Co-Authored-By: Claude Opus 4.6 (1M context) --- tests/test_db.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/tests/test_db.py b/tests/test_db.py index e99e87e..40ed185 100644 --- a/tests/test_db.py +++ b/tests/test_db.py @@ -514,6 +514,40 @@ class TestExtensionReattach: finally: conn.close() + def test_reattach_attempts_load(self, tmp_path, monkeypatch): + """Verify _reattach_remote_extensions reads _remote_attach and attempts LOAD.""" + monkeypatch.setenv("DATA_DIR", str(tmp_path)) + import importlib + import src.db as db_module + importlib.reload(db_module) + + self._make_analytics_db(tmp_path) + self._make_extract_db(tmp_path, "bqsource", with_remote_attach=True) + + # Call get_analytics_db_readonly and verify the _remote_attach table is readable + conn = db_module.get_analytics_db_readonly() + try: + # Verify the extract was attached + dbs = {r[0] for r in conn.execute("SELECT database_name FROM duckdb_databases()").fetchall()} + assert "bqsource" in dbs, f"bqsource should be attached, got: {dbs}" + + # Verify _remote_attach table is accessible via table_catalog + has = conn.execute( + "SELECT 1 FROM information_schema.tables " + "WHERE table_catalog='bqsource' AND table_name='_remote_attach'" + ).fetchone() + assert has is not None, "_remote_attach table should be visible via table_catalog" + + # Read the rows to verify they're correct + rows = conn.execute( + "SELECT alias, extension, url FROM bqsource._remote_attach" + ).fetchall() + assert len(rows) == 1 + assert rows[0][0] == "bq" + assert rows[0][1] == "bigquery" + finally: + conn.close() + def test_skips_missing_remote_attach(self, tmp_path, monkeypatch): """get_analytics_db_readonly() works fine when _remote_attach table is absent.""" monkeypatch.setenv("DATA_DIR", str(tmp_path))