Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
a748881
chore: Update FastAPI version to 0.121.2
ruivieira Dec 2, 2025
27604ee
:construction: added tests for HF detector FastAPI lifespan context
m-misiura Dec 3, 2025
f0ad358
Merge pull request #59 from m-misiura/bow-hf-test-client-integration
m-misiura Dec 3, 2025
fd4591f
Merge pull request #58 from ruivieira/fastapi-deps
ruivieira Dec 3, 2025
7098ba9
Add optional kwargs to custom detector params
RobGeada Dec 10, 2025
1d60579
Review comments
RobGeada Dec 10, 2025
34608fb
Merge pull request #60 from RobGeada/AddKwargsToCustomDetectors
RobGeada Dec 10, 2025
f8ebbc5
feat: Add Tier 1 testing
ruivieira Dec 17, 2025
5a03d8b
fix: Python path
ruivieira Dec 17, 2025
8193889
fix: Add coverage dependency
ruivieira Dec 17, 2025
1d3f336
refactor: Use common setup
ruivieira Dec 17, 2025
3a589d5
Merge pull request #61 from ruivieira/bow-tests
ruivieira Dec 17, 2025
2a08f01
fix: Pin urllib3 to 2.6.2
ruivieira Dec 17, 2025
e67a887
Merge pull request #62 from ruivieira/deps/urllib3
ruivieira Dec 18, 2025
a415c51
Use multithreaded prometheus metrics for HF detector
RobGeada Dec 18, 2025
8eecb58
Merge pull request #63 from RobGeada/MultithreadedPrometheusHFMetrics
RobGeada Dec 18, 2025
a9a7b8e
:arrow_down: downgrade `sentencepiece` to 0.1.96
m-misiura Dec 18, 2025
fab8ec4
Merge pull request #64 from m-misiura/downgrade_sentencepiece
m-misiura Dec 18, 2025
81f7219
Fixing Tier 1 - Hugging Face Runtime unit tests
m-misiura Dec 18, 2025
9db0f53
Update requirements.txt
npanpaliya Dec 19, 2025
389d237
Merge pull request #66 from npanpaliya/patch-1
m-misiura Dec 19, 2025
13ef711
Expand registry endpoint information for built-in detectors
RobGeada Dec 19, 2025
2190e36
Merge pull request #67 from RobGeada/ExpandedRegistry
RobGeada Dec 19, 2025
d0d08fa
Merge pull request #65 from m-misiura/fix_tests_hf_runtime
m-misiura Jan 6, 2026
792153c
:arrow_up: upgrade torch to 2.9.1 in requirements-dev.txt
m-misiura Jan 6, 2026
4b26af2
Merge pull request #68 from m-misiura/upgrade-dev-torch
m-misiura Jan 6, 2026
7809f7c
:construction: changing error handling in `test_filetype.py`
m-misiura Jan 6, 2026
633015b
Merge pull request #69 from m-misiura/fix_tests_built_in
m-misiura Jan 6, 2026
7c68ab8
ci(workflow): run build-and-push in upstream repository only
ruivieira Jan 19, 2026
933f44e
ci(workflow): update missed checkout to v4
ruivieira Jan 19, 2026
2622279
Merge pull request #73 from ruivieira/update-gha
ruivieira Jan 19, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion detectors/common/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
fastapi==0.112.0
fastapi==0.121.2
uvicorn==0.30.5
httpx==0.27.0
prometheus_client >= 0.18.0
Expand Down
70 changes: 70 additions & 0 deletions tests/detectors/huggingface/test_client_integration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
"""
Integration tests for HF detector FastAPI lifespan context
"""

import os
import sys
import pytest
from fastapi.testclient import TestClient

# Set up paths and MODEL_DIR before app import
_current_dir = os.path.dirname(__file__)
_tests_dir = os.path.dirname(os.path.dirname(_current_dir))
_project_root = os.path.dirname(_tests_dir)
_detectors_path = os.path.join(_project_root, "detectors")
_huggingface_path = os.path.join(_detectors_path, "huggingface")

for path in [_huggingface_path, _detectors_path, _project_root]:
if path not in sys.path:
sys.path.insert(0, path)

os.environ["MODEL_DIR"] = os.path.join(
_tests_dir, "dummy_models", "bert/BertForSequenceClassification"
)

from app import app # noqa: E402


class TestLifespanIntegration:
"""Test FastAPI lifespan context for HF detector."""

@pytest.fixture
def client(self):
"""Create test client with lifespan-initialized detector."""
with TestClient(app) as test_client:
yield test_client

def test_lifespan_loads_detector(self, client):
"""Verify lifespan initializes detector on startup."""
detectors = app.get_all_detectors()
assert len(detectors) > 0
detector = list(detectors.values())[0]
assert detector.model is not None
assert detector.tokenizer is not None

def test_lifespan_handles_requests(self, client):
"""Verify requests work through lifespan-initialized app."""
response = client.post(
"/api/v1/text/contents",
json={"contents": ["Test message"], "detector_params": {}},
)
assert response.status_code == 200
assert isinstance(response.json(), list)

def test_multiple_requests(self, client):
"""Verify detector handles multiple requests without state leakage."""
for i in range(10):
response = client.post(
"/api/v1/text/contents",
json={"contents": [f"Request {i}"], "detector_params": {}},
)
assert response.status_code == 200
assert isinstance(response.json(), list)

def test_lifespan_cleanup(self, client):
"""Verify lifespan cleanup runs on shutdown."""
assert len(app.get_all_detectors()) > 0

client.__exit__(None, None, None)

assert len(app.get_all_detectors()) == 0