Skip to content

fix(tests): all() on empty document list is vacuously True, masking empty-result regression in list_documents #269

Closed

Description

@piyushmakhija28

Summary

tests/test_documents_endpoint.py asserts all(doc['doc_id'] == 'doc_abc123' for doc in body['data']) to verify document listing. When body['data'] is an empty list [], all() returns True vacuously — a bug returning an empty document list passes the assertion silently.

Root Cause

tests/test_documents_endpoint.py around line 137:

body = response.json()
assert all(doc['doc_id'] == 'doc_abc123' for doc in body['data'])
# ↑ True when body['data'] == [] because all() on empty iterable is True

There is no assertion on the length of body['data'], so an empty response and a correct response are indistinguishable.

Failure Scenario

  1. A regression in list_documents causes it to return {"data": [], "pagination": {...}} for a tenant that has documents.
  2. all(... for doc in []) → True.
  3. Test passes. The regression ships to production.
  4. All users see empty document lists with no error.

Proposed Fix

body = response.json()
docs = body['data']
assert len(docs) == 1, f"Expected 1 document, got {len(docs)}: {docs}"
assert docs[0]['doc_id'] == 'doc_abc123'

Also add a test for page > total_pages returning 422:

def test_list_documents_page_out_of_range_returns_422(client, auth_headers):
    # Upload 1 document, then request page=999
    response = client.get('/v1/documents?page=999', headers=auth_headers)
    assert response.status_code == 422

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