Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

test: verify the parser memory cap with controlled allocation (#8193)

LearningCircuit8404182a0475
diff --git a/tests/security/test_isolated_upload_loader.py b/tests/security/test_isolated_upload_loader.py
index eb898e7b87..70fb583d7a 100644
--- a/tests/security/test_isolated_upload_loader.py
+++ b/tests/security/test_isolated_upload_loader.py
@@ -475,24 +475,51 @@ def test_real_worker_parses_without_importing_the_ml_stack(tmp_path):
@pytest.mark.skipif(sys.platform != "linux", reason="Linux RLIMIT_DATA only")
-def test_real_worker_has_live_data_limit(monkeypatch, tmp_path):
- # The unit test above calls _cap_data_memory itself. This one uses the
- # production argv and main(): a cap far below what the parser libraries
- # need to import must make the real child refuse a valid document.
- source = tmp_path / "capped.docx"
- source.write_bytes(_docx_bytes())
- monkeypatch.setattr(
- isolated_loader, "MAX_CHILD_DATA_BYTES", 64 * 1024 * 1024
[email protected]("headroom_mb", [16, 96], ids=["bounded", "healthy"])
+def test_real_worker_has_live_data_limit(headroom_mb):
+ # Exercise main() and its real kernel limit, replacing only parser work
+ # with a predictable allocation. Native parser imports can wrap memory
+ # failures in unrelated exception types, so they cannot prove which cap
+ # stopped the child. Real DOCX parsing is covered independently above.
+ script = "\n".join(
+ [
+ "import sys",
+ "from contextlib import nullcontext",
+ "from pathlib import Path",
+ "from local_deep_research.security import isolated_worker",
+ "status = Path('/proc/self/status').read_text()",
+ "current = int(next(line.split()[1] for line in status.splitlines()",
+ " if line.startswith('VmData:'))) * 1024",
+ "def parse(path, extension):",
+ " data = bytearray(64 * 1024 * 1024)",
+ " return {'status': 'ok', 'documents': [",
+ " {'page_content': str(len(data)), 'metadata': {}}]}",
+ "isolated_worker._result = parse",
+ "isolated_worker._nltk_regex_budget = lambda ext: nullcontext()",
+ _worker_argv("unused"),
+ f"sys.argv[3] = str(current + {headroom_mb} * 1024 * 1024)",
+ "raise SystemExit(isolated_worker.main())",
+ ]
)
- # A native import may report a failed mapping rather than MemoryError.
- # A timeout, crash or ordinary parser error must still fail this check.
- with pytest.raises(
- (
- isolated_loader.ParserMemoryLimitError,
- isolated_loader.ParserResourceError,
- )
- ):
- isolated_loader.load_documents_isolated(str(source), ".docx")
+ result = subprocess.run(
+ [sys.executable, "-c", script],
+ check=False,
+ capture_output=True,
+ timeout=30,
+ )
+ assert result.returncode == 0, result.stderr[-2000:]
+ if headroom_mb == 16:
+ assert json.loads(result.stdout) == {
+ "status": "error",
+ "kind": "memory",
+ }
+ with pytest.raises(isolated_loader.ParserMemoryLimitError):
+ isolated_loader._documents_from_output(result.stdout)
+ else:
+ documents = isolated_loader._documents_from_output(result.stdout)
+ assert [doc.page_content for doc in documents] == [
+ str(64 * 1024 * 1024)
+ ]
def test_worker_reports_memory_exhaustion_as_its_own_kind(tmp_path):