Skip to content

fix(ingestion/tests): FakeSectionStore missing upsert_document_and_replace_sections method, crashing Scenario A/B tests #272

Closed

Description

@piyushmakhija28

Summary

ingestion/tests/conftest.py's FakeSectionStore implements replace_sections and upsert_document separately, but the production pipeline calls section_store.upsert_document_and_replace_sections() (the atomic combined method) for Scenario A/B paths. Any test that exercises ingest_document() with a Scenario A/B PDF will crash with AttributeError: 'FakeSectionStore' object has no attribute 'upsert_document_and_replace_sections'.

Root Cause

ingestion/tests/conftest.py around line 160:

class FakeSectionStore:
    def replace_sections(self, doc_id, rows): ...
    def upsert_document(self, ...): ...
    # upsert_document_and_replace_sections is NOT implemented

ingestion/pipeline.py (Scenario A/B path):

await section_store.upsert_document_and_replace_sections(
    tenant_id, doc_id, sections, ingest_status, ...
)   # ← AttributeError in tests using FakeSectionStore

Failure Scenario

  1. Test creates a FakeSectionStore and passes it to ingest_document().
  2. Pipeline detects Scenario A (has native TOC) or B (has heuristic headers).
  3. Pipeline calls section_store.upsert_document_and_replace_sections(...).
  4. AttributeError: 'FakeSectionStore' object has no attribute 'upsert_document_and_replace_sections'.
  5. Test crashes with ERROR instead of FAILED — masking as a setup problem, not a real test failure.
  6. The atomic Scenario A/B upsert path is never actually tested.

Proposed Fix

Add the missing method to FakeSectionStore:

class FakeSectionStore:
    def __init__(self):
        self._sections: dict[tuple[str, str], list] = {}
        self._documents: dict[str, dict] = {}

    def upsert_document_and_replace_sections(
        self,
        tenant_id: str,
        doc_id: str,
        sections: list,
        ingest_status: str,
        fallback_only: bool,
        **kwargs,
    ) -> None:
        key = (tenant_id, doc_id)
        self._documents[key] = {
            'doc_id': doc_id,
            'tenant_id': tenant_id,
            'ingest_status': ingest_status,
            'fallback_only': fallback_only,
        }
        self._sections[key] = sections

Also add a Protocol compliance test:

def test_fake_section_store_satisfies_protocol():
    from ingestion.store_protocol import SectionStore
    store = FakeSectionStore()
    assert isinstance(store, SectionStore)

Activity

  1. piyushmakhija28 commented on Jun 21, 2026

    @piyushmakhija28
    ContributorAuthor

    Fixed in PR #280 (Sprint R3/R4: fix(sprint-r3): root-cause fixes for all 39 bugs from code review round 3 + Sprint R4 round 4)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcode-reviewFound via automated code reviewpriority: mediumFunctional error with workaround

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions