Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 0 additions & 1 deletion claude_code_api/core/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import os
import re
from pathlib import Path

import structlog
from fastapi import HTTPException, status
Expand Down
5 changes: 2 additions & 3 deletions docker/oauth-proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
import argparse
import logging
import sys
from typing import Dict, Any
from urllib.parse import urlencode, parse_qs, urlparse
from typing import Dict

try:
from aiohttp import web, ClientSession, ClientError
Expand Down Expand Up @@ -69,7 +68,7 @@ async def handle_oauth_callback(self, request: web.Request) -> web.Response:
try:
# Forward the callback with all query parameters
async with session.get(target_url, params=query_params, timeout=10) as resp:
response_text = await resp.text()
await resp.text()
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Reading the response body with await resp.text() is unnecessary here as the content is not used. This operation consumes memory and CPU to read and decode the body, which is inefficient, especially for large responses. The async with block already handles the connection release properly, so this line can be safely removed.


logger.info(f"Container response: {resp.status}")

Expand Down
7 changes: 2 additions & 5 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,21 @@
import json
import os
import shutil
import sys
import tempfile
from pathlib import Path

import pytest
from fastapi.testclient import TestClient
from httpx import AsyncClient

# Add the project root to Python path for imports
PROJECT_ROOT = Path(__file__).parent.parent
sys.path.insert(0, str(PROJECT_ROOT))

from claude_code_api.core.config import settings

# Now import the app and configuration
from claude_code_api.main import app
from tests.model_utils import get_test_model_id

PROJECT_ROOT = Path(__file__).parent.parent


@pytest.fixture(scope="session", autouse=True)
def setup_test_environment():
Expand Down
29 changes: 11 additions & 18 deletions tests/test_end_to_end.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,23 @@
import os
import shutil
import tempfile
from pathlib import Path
from typing import Any, Dict, List

import pytest
from fastapi.testclient import TestClient
from httpx import AsyncClient

from claude_code_api.core.config import settings
from claude_code_api.core.session_manager import SessionManager
from claude_code_api.main import app
from claude_code_api.models.claude import get_available_models
from tests.model_utils import get_test_model_id

PROJECT_ROOT = Path(__file__).parent.parent
AVAILABLE_MODELS = get_available_models()
DEFAULT_MODEL = get_test_model_id()


def parse_sse_events(body_text: str) -> List[Dict[str, Any]]:
"""Parse SSE events from a streaming response body."""
Expand All @@ -33,24 +44,6 @@ def parse_sse_events(body_text: str) -> List[Dict[str, Any]]:
return events


# Import the FastAPI app
import sys
from pathlib import Path

# Add project root to path
PROJECT_ROOT = Path(__file__).parent.parent
sys.path.insert(0, str(PROJECT_ROOT))

from claude_code_api.core.config import settings
from claude_code_api.core.session_manager import SessionManager
from claude_code_api.main import app
from claude_code_api.models.claude import get_available_models
from tests.model_utils import get_test_model_id

AVAILABLE_MODELS = get_available_models()
DEFAULT_MODEL = get_test_model_id()


class TestConfig:
"""Test configuration."""

Expand Down
Loading