feat(tests): add integration tests for API endpoints #149#154
feat(tests): add integration tests for API endpoints #149#154Aharshi3614 wants to merge 3 commits into
Conversation
|
@Aharshi3614 is attempting to deploy a commit to the s3dfx-cyber's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThis PR adds a comprehensive Python integration test suite for TENET AI API endpoints, including environment-driven configuration, a health-check fixture, payload helper, and tests covering health, auth, ingest/analyzer validation, event retrieval, utility endpoints, threat detection, performance, and error handling. ChangesIntegration Test Suite for TENET AI API Endpoints
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related issues
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@tests/integration/test_api_integration.py`:
- Around line 88-92: The test test_ingest_health_response_schema currently
asserts an exact version string ("0.1.0") which will break on normal version
bumps; change the assertion in test_ingest_health_response_schema (and the
similar assertions around lines 101-105) to validate the version more
flexibly—e.g., assert that data["version"] is a non-empty string or matches a
semantic version pattern, or compare it against the package/app runtime version
constant if available—so the test verifies format/presence rather than a
hard-coded value.
- Around line 150-167: The tests test_valid_key_accepted_on_ingest and
test_valid_key_accepted_on_analyzer currently assert a strict 200 response,
coupling auth checks to downstream availability; update both assertions to
accept successful auth responses even if downstream is degraded by asserting
r.status_code is in an allowed set (e.g., {200, 503}) or by asserting the
response is not an authentication failure (e.g., not 401/403), so the tests only
validate that VALID_HEADERS are accepted rather than the full service health.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: eae01221-6742-43f1-86e5-c725a7210263
📒 Files selected for processing (1)
tests/integration/test_api_integration.py
| def test_ingest_health_response_schema(self): | ||
| data = requests.get(f"{INGEST_URL}/health", timeout=5).json() | ||
| assert data["service"] == "ingest" | ||
| assert data["version"] == "0.1.0" | ||
| assert data["status"] in ("healthy", "degraded") |
There was a problem hiding this comment.
Avoid hard-coding exact service version in health schema assertions.
Pinning "0.1.0" makes these tests fail on normal version bumps even when the endpoint contract is still valid.
Proposed fix
- assert data["version"] == "0.1.0"
+ assert isinstance(data.get("version"), str) and data["version"]
...
- assert data["version"] == "0.1.0"
+ assert isinstance(data.get("version"), str) and data["version"]Also applies to: 101-105
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@tests/integration/test_api_integration.py` around lines 88 - 92, The test
test_ingest_health_response_schema currently asserts an exact version string
("0.1.0") which will break on normal version bumps; change the assertion in
test_ingest_health_response_schema (and the similar assertions around lines
101-105) to validate the version more flexibly—e.g., assert that data["version"]
is a non-empty string or matches a semantic version pattern, or compare it
against the package/app runtime version constant if available—so the test
verifies format/presence rather than a hard-coded value.
| def test_valid_key_accepted_on_ingest(self): | ||
| r = requests.post( | ||
| f"{INGEST_URL}/v1/events/llm", | ||
| headers=VALID_HEADERS, | ||
| json=llm_payload("Hello world"), | ||
| timeout=5, | ||
| ) | ||
| assert r.status_code == 200 | ||
|
|
||
| def test_valid_key_accepted_on_analyzer(self): | ||
| r = requests.post( | ||
| f"{ANALYZER_URL}/v1/analyze", | ||
| headers=VALID_HEADERS, | ||
| json={"prompt": "Hello world"}, | ||
| timeout=5, | ||
| ) | ||
| assert r.status_code == 200 | ||
|
|
There was a problem hiding this comment.
Decouple valid-key auth checks from downstream service availability.
These tests currently require 200 only; they can fail when auth passes but dependencies are degraded (e.g., transient 503), which turns auth checks into infrastructure-flakiness checks.
Proposed fix
- assert r.status_code == 200
+ assert r.status_code in (200, 503)
...
- assert r.status_code == 200
+ assert r.status_code in (200, 503)🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@tests/integration/test_api_integration.py` around lines 150 - 167, The tests
test_valid_key_accepted_on_ingest and test_valid_key_accepted_on_analyzer
currently assert a strict 200 response, coupling auth checks to downstream
availability; update both assertions to accept successful auth responses even if
downstream is degraded by asserting r.status_code is in an allowed set (e.g.,
{200, 503}) or by asserting the response is not an authentication failure (e.g.,
not 401/403), so the tests only validate that VALID_HEADERS are accepted rather
than the full service health.
|
@Aharshi3614 needs fixes |
Description
Implements comprehensive integration tests for all TENET AI API endpoints as specified in issue #149.
Tests cover the full request/response cycle for both the Ingest (port 8000) and Analyzer (port 8100) services across 10 test classes:
TestHealthEndpoints- health checks for both servicesTestAuthFlow- authentication and authorization edge casesTestIngestEndpoint- full ingest happy pathTestIngestValidation- input validation and edge casesTestAnalyzerEndpoint- analyzer verdict, schema, error handlingTestEventRetrieval- event retrieval by ID, pagination, org isolationTestStatsAndCircuit- stats endpoint and circuit breaker statusTestThreatDetection- 12 parametrized accuracy test casesTestPerformance- response time and batch request testsTestErrorHandling- 404, 405, 422 error code verificationRelated Issue
Fixes #149
Type of Change
How Has This Been Tested?
Ran locally with both services running via uvicorn:
pytest tests/integration/test_api_integration.py -v
Result: 80 passed in 200s
Checklist
Summary by cubic
Adds end-to-end integration tests for the Ingest and Analyzer services to validate health, auth, core flows, and failure modes across the full request/response cycle. Fulfills issue #149 and reduces false failures by tolerating expected degraded states.
New Features
Bug Fixes
Written for commit 3c35bbb. Summary will update on new commits.
Summary by CodeRabbit