Skip to content

Commit 812751c

Browse files
committed
test(file_processors): send the test id on raw process_file requests
The four file-processor integration tests that upload a file started failing under the recording harness with 400 "Test ID is required for file ID allocation". These tests call the endpoint with bare requests.post rather than the OGX client, so nothing injects the provider-data header the recorder reads the test id from. That did not matter before: a direct upload was handed straight to the processor and no file record was ever created. Staging the upload into the Files API means an ID now gets allocated per request, and in record/replay mode allocation is deterministic and refuses to run without a test id. Adds a test_context_headers fixture following the same idiom as tests/integration/files/test_files.py, and passes it on the four upload requests. Outside record/replay mode get_test_context() is empty and the fixture sends nothing, so the docling workflow is unaffected. Signed-off-by: Charlie Doern <cdoern@redhat.com>
1 parent 73baa57 commit 812751c

1 file changed

Lines changed: 25 additions & 4 deletions

File tree

tests/integration/file_processors/test_file_processors.py

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,23 @@
1010
import pytest
1111
import requests
1212

13+
from ogx.core.testing_context import get_test_context
14+
15+
16+
@pytest.fixture
17+
def test_context_headers() -> dict[str, str]:
18+
"""Propagate the test id on raw requests.
19+
20+
These tests bypass the OGX client, so nothing injects the header the
21+
recorder relies on. A direct upload is now staged into the Files API before
22+
processing, and deterministic file-ID allocation refuses to run without a
23+
test id.
24+
"""
25+
test_id = get_test_context()
26+
if not test_id:
27+
return {}
28+
return {"X-OGX-Provider-Data": json.dumps({"__test_id": test_id})}
29+
1330

1431
@pytest.fixture(autouse=True)
1532
def skip_if_no_file_processor_provider(ogx_client, require_server):
@@ -45,11 +62,12 @@ def test_pdf_content(test_pdf_path: Path) -> bytes:
4562
class TestFileProcessors:
4663
"""Provider-agnostic integration tests for the file-processors/process endpoint."""
4764

48-
def test_process_file_basic(self, process_url, test_pdf_content):
65+
def test_process_file_basic(self, process_url, test_pdf_content, test_context_headers):
4966
"""Test basic file processing without chunking."""
5067
resp = requests.post(
5168
process_url,
5269
files={"file": ("test.pdf", test_pdf_content, "application/pdf")},
70+
headers=test_context_headers,
5371
timeout=120,
5472
)
5573
assert resp.status_code == 200, f"Unexpected status: {resp.status_code} {resp.text}"
@@ -69,12 +87,13 @@ def test_process_file_basic(self, process_url, test_pdf_content):
6987
assert chunk["content"] is not None
7088
assert len(chunk["content"].strip()) > 0
7189

72-
def test_process_file_with_auto_chunking(self, process_url, test_pdf_content):
90+
def test_process_file_with_auto_chunking(self, process_url, test_pdf_content, test_context_headers):
7391
"""Test file processing with auto chunking strategy."""
7492
chunking_strategy = json.dumps({"type": "auto"})
7593
resp = requests.post(
7694
process_url,
7795
files={"file": ("test.pdf", test_pdf_content, "application/pdf")},
96+
headers=test_context_headers,
7897
data={"chunking_strategy": chunking_strategy},
7998
timeout=120,
8099
)
@@ -96,7 +115,7 @@ def test_process_file_with_auto_chunking(self, process_url, test_pdf_content):
96115
assert "document_id" in chunk["metadata"]
97116
assert chunk["metadata"]["filename"] == "test.pdf"
98117

99-
def test_process_file_with_static_chunking(self, process_url, test_pdf_content):
118+
def test_process_file_with_static_chunking(self, process_url, test_pdf_content, test_context_headers):
100119
"""Test file processing with static chunking strategy."""
101120
chunking_strategy = json.dumps(
102121
{
@@ -110,6 +129,7 @@ def test_process_file_with_static_chunking(self, process_url, test_pdf_content):
110129
resp = requests.post(
111130
process_url,
112131
files={"file": ("test.pdf", test_pdf_content, "application/pdf")},
132+
headers=test_context_headers,
113133
data={"chunking_strategy": chunking_strategy},
114134
timeout=120,
115135
)
@@ -125,12 +145,13 @@ def test_process_file_with_static_chunking(self, process_url, test_pdf_content):
125145
chunk_ids.add(chunk["chunk_id"])
126146
assert chunk["chunk_metadata"]["content_token_count"] > 0
127147

128-
def test_chunk_id_uniqueness(self, process_url, test_pdf_content):
148+
def test_chunk_id_uniqueness(self, process_url, test_pdf_content, test_context_headers):
129149
"""Test chunk IDs are unique across chunks."""
130150
chunking_strategy = json.dumps({"type": "auto"})
131151
resp = requests.post(
132152
process_url,
133153
files={"file": ("test.pdf", test_pdf_content, "application/pdf")},
154+
headers=test_context_headers,
134155
data={"chunking_strategy": chunking_strategy},
135156
timeout=120,
136157
)

0 commit comments

Comments
 (0)