Skip to content

Commit 823e4f3

Browse files
JuliaEdomclaude
andcommitted
fix(tests): don't require the BIRD dataset to be downloaded
Three of the new slice tests read the real `dev_tables.json`, which is fetched by `scripts/download_data.py` and is not in the repo — so they passed locally and failed the CI `test` job with FileNotFoundError. The dataset-independent halves (parsing a tables.json, rejecting an unknown db_id) now run against a synthetic file and cover the logic everywhere; the two that genuinely assert a property of BIRD's *data* — the real table list, and the global uniqueness of table names the slice depends on — skip when the dataset is absent, the same way the live-Postgres proofs skip without a DSN. Verified both ways: with the dataset 11 pass, with it hidden 9 pass + 2 skip. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 55b90ab commit 823e4f3

1 file changed

Lines changed: 38 additions & 8 deletions

File tree

‎tests/scripts/test_extract_pg_dump_slice.py‎

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import pytest
2323
from scripts.extract_pg_dump_slice import (
24+
DEFAULT_TABLES_JSON,
2425
Section,
2526
_verify,
2627
bird_tables,
@@ -172,6 +173,35 @@ def test_verify_passes_on_a_complete_slice() -> None:
172173
assert _verify(kept, {"posts", "circuits"}) == []
173174

174175

176+
def test_bird_tables_parses_a_tables_json(tmp_path: Path) -> None:
177+
tables_json = tmp_path / "dev_tables.json"
178+
tables_json.write_text(
179+
json.dumps(
180+
[
181+
{"db_id": "formula_1", "table_names_original": ["circuits", "drivers"]},
182+
{"db_id": "codebase_community", "table_names_original": ["posts", "postHistory"]},
183+
]
184+
),
185+
encoding="utf-8",
186+
)
187+
188+
assert bird_tables("codebase_community", tables_json) == {"posts", "posthistory"}
189+
190+
191+
def test_bird_tables_rejects_an_unknown_db(tmp_path: Path) -> None:
192+
tables_json = tmp_path / "dev_tables.json"
193+
tables_json.write_text(
194+
json.dumps([{"db_id": "formula_1", "table_names_original": ["circuits"]}]), encoding="utf-8"
195+
)
196+
197+
with pytest.raises(KeyError, match="unknown BIRD db_id"):
198+
bird_tables("not_a_bird_database", tables_json)
199+
200+
201+
@pytest.mark.skipif(
202+
not DEFAULT_TABLES_JSON.is_file(),
203+
reason="BIRD Mini-Dev not downloaded (scripts/download_data.py bird-mini-dev)",
204+
)
175205
def test_bird_tables_reads_the_real_dev_tables_json() -> None:
176206
tables = bird_tables("codebase_community")
177207

@@ -187,11 +217,6 @@ def test_bird_tables_reads_the_real_dev_tables_json() -> None:
187217
}
188218

189219

190-
def test_bird_tables_rejects_an_unknown_db() -> None:
191-
with pytest.raises(KeyError, match="unknown BIRD db_id"):
192-
bird_tables("not_a_bird_database")
193-
194-
195220
def test_extract_reads_from_a_real_file(tmp_path: Path) -> None:
196221
"""End-to-end on a Path, since `extract` opens the dump itself."""
197222
dump = tmp_path / "dump.sql"
@@ -214,15 +239,20 @@ def test_extract_reads_from_a_real_file(tmp_path: Path) -> None:
214239
}
215240

216241

242+
@pytest.mark.skipif(
243+
not DEFAULT_TABLES_JSON.is_file(),
244+
reason="BIRD Mini-Dev not downloaded (scripts/download_data.py bird-mini-dev)",
245+
)
217246
def test_dev_tables_json_table_names_are_globally_unique() -> None:
218247
"""The slice keys on table name alone — that is only sound if names don't collide.
219248
220249
If BIRD ever ships two databases sharing a table name, the slice would silently
221250
pull in the other database's rows. Pin the property that makes it safe.
251+
252+
Skipped when the dataset isn't downloaded (CI): this asserts a property of the
253+
BIRD data, not of our code, so there is nothing to check without the data.
222254
"""
223-
entries = json.loads(
224-
Path("data/bird_mini_dev/MINIDEV/dev_tables.json").read_text(encoding="utf-8")
225-
)
255+
entries = json.loads(DEFAULT_TABLES_JSON.read_text(encoding="utf-8"))
226256
seen: dict[str, str] = {}
227257
collisions: list[str] = []
228258
for entry in entries:

0 commit comments

Comments
 (0)