diff --git a/paperforge/worker/ocr_tables.py b/paperforge/worker/ocr_tables.py index dd914f20..7495152b 100644 --- a/paperforge/worker/ocr_tables.py +++ b/paperforge/worker/ocr_tables.py @@ -232,8 +232,11 @@ def _table_note_falls_into_page_footnote_prior( return False return float(note_bbox[1]) >= float(prior_by_page[page]) - def build_table_inventory(structured_blocks: list[dict]) -> dict[str, Any]: + return build_table_inventory_legacy(structured_blocks) + + +def build_table_inventory_legacy(structured_blocks: list[dict]) -> dict[str, Any]: tables: list[dict] = [] captions: list[dict] = [] assets: list[dict] = [] diff --git a/tests/test_ocr_tables.py b/tests/test_ocr_tables.py index 501eeb1f..659a6b7b 100644 --- a/tests/test_ocr_tables.py +++ b/tests/test_ocr_tables.py @@ -1305,3 +1305,55 @@ def test_extract_table_number_supports_roman_and_s_prefix(text, expected_number) from paperforge.worker.ocr_tables import _extract_table_number assert _extract_table_number(text) == expected_number + + +def test_build_table_inventory_delegates_to_legacy_during_plan_b(monkeypatch) -> None: + from paperforge.worker import ocr_tables + + called = {} + + def fake_legacy(structured_blocks): + called["blocks"] = structured_blocks + return { + "tables": [], + "held_tables": [], + "unmatched_captions": [], + "unmatched_assets": [], + "official_table_count": 0, + } + + monkeypatch.setattr(ocr_tables, "build_table_inventory_legacy", fake_legacy, raising=False) + + blocks = [{"block_id": "cap1", "page": 1, "role": "table_caption", "text": "Table 1. Example"}] + result = ocr_tables.build_table_inventory(blocks) + + assert called["blocks"] == blocks + assert result["official_table_count"] == 0 + + +def test_public_table_inventory_contract_preserves_resolver_fields() -> None: + from paperforge.worker.ocr_tables import build_table_inventory + + structured_blocks = [ + { + "block_id": "cap1", + "page": 3, + "role": "table_caption", + "text": "Table 1. Example caption", + "bbox": [100, 100, 800, 140], + }, + { + "block_id": "asset1", + "page": 3, + "role": "table_html", + "raw_label": "table", + "text": "
x
", + "bbox": [100, 160, 800, 520], + }, + ] + + inventory = build_table_inventory(structured_blocks) + table = inventory["tables"][0] + + assert {"tables", "held_tables", "unmatched_captions", "unmatched_assets", "official_table_count"} <= set(inventory) + assert {"page", "caption_text", "has_asset", "asset_block_id", "match_status", "consumed_block_ids"} <= set(table)