LightRAG/tests
BukeLy 6559dc4fed test: Add comprehensive workspace isolation test suite for PR #2366
Why this change is needed:
PR #2366 introduces critical workspace isolation functionality to resolve
multi-instance concurrency issues, but lacks comprehensive automated tests
to validate the implementation. Without proper test coverage, we cannot
ensure the feature works correctly across all scenarios mentioned in the PR.

What this test suite covers:
1. Pipeline Status Isolation: Verifies different workspaces maintain
   independent pipeline status without interference
2. Lock Mechanism: Validates the new keyed lock system works correctly
   - Different workspaces can acquire locks in parallel
   - Same workspace locks serialize properly
   - No deadlocks occur
3. Backward Compatibility: Ensures legacy code without workspace parameters
   continues to work using default workspace
4. Multi-Workspace Concurrency: Confirms multiple LightRAG instances with
   different workspaces can run concurrently without data interference

Testing approach:
- All tests are automated and deterministic
- Uses timing assertions to verify parallel vs serial lock behavior
- Validates data isolation through direct namespace data inspection
- Comprehensive error handling and detailed test output

Test results:
All 9 test cases passed successfully, confirming the workspace isolation
feature is working correctly across all key scenarios.

Impact:
Provides confidence that PR #2366's workspace isolation feature is
production-ready and won't introduce regressions.

(cherry picked from commit 4742fc8efa)
2025-12-04 19:11:11 +08:00
..
e2e_real_service tests: stabilize integration tests + skip external services; fix multi-tenant API behavior and idempotency (#4) 2025-12-04 16:04:21 +08:00
gpt5_nano_compatibility tests: stabilize integration tests + skip external services; fix multi-tenant API behavior and idempotency (#4) 2025-12-04 16:04:21 +08:00
conftest.py tests: stabilize integration tests + skip external services; fix multi-tenant API behavior and idempotency (#4) 2025-12-04 16:04:21 +08:00
e2e_multi_tenant_state.py tests: stabilize integration tests + skip external services; fix multi-tenant API behavior and idempotency (#4) 2025-12-04 16:04:21 +08:00
README.md tests: stabilize integration tests + skip external services; fix multi-tenant API behavior and idempotency (#4) 2025-12-04 16:04:21 +08:00
test_aquery_data_endpoint.py Fix conditional logic in streaming response parser of unit test 2025-09-27 21:43:46 +08:00
test_backward_compatibility.py tests: stabilize integration tests + skip external services; fix multi-tenant API behavior and idempotency (#4) 2025-12-04 16:04:21 +08:00
test_curl_aquery_data.sh Add test script for aquery_data endpoint validation 2025-12-04 19:11:07 +08:00
test_document_routes_tenant_scoped.py tests: stabilize integration tests + skip external services; fix multi-tenant API behavior and idempotency (#4) 2025-12-04 16:04:21 +08:00
test_graph_storage.py Translate graph storage test from Chinese to English 2025-12-04 19:09:03 +08:00
test_idempotency.py tests: stabilize integration tests + skip external services; fix multi-tenant API behavior and idempotency (#4) 2025-12-04 16:04:21 +08:00
test_lightrag_ollama_chat.py tests: stabilize integration tests + skip external services; fix multi-tenant API behavior and idempotency (#4) 2025-12-04 16:04:21 +08:00
test_multi_tenant_backends.py tests: stabilize integration tests + skip external services; fix multi-tenant API behavior and idempotency (#4) 2025-12-04 16:04:21 +08:00
test_multitenant_e2e.py tests: stabilize integration tests + skip external services; fix multi-tenant API behavior and idempotency (#4) 2025-12-04 16:04:21 +08:00
test_overlap_validation.py Improve edge case handling for max_tokens=1 2025-12-04 19:09:07 +08:00
test_postgres_retry_integration.py Add PostgreSQL connection retry mechanism with comprehensive error handling 2025-12-04 19:08:58 +08:00
test_tenant_api_routes.py tests: stabilize integration tests + skip external services; fix multi-tenant API behavior and idempotency (#4) 2025-12-04 16:04:21 +08:00
test_tenant_models.py tests: stabilize integration tests + skip external services; fix multi-tenant API behavior and idempotency (#4) 2025-12-04 16:04:21 +08:00
test_tenant_security.py tests: stabilize integration tests + skip external services; fix multi-tenant API behavior and idempotency (#4) 2025-12-04 16:04:21 +08:00
test_tenant_storage_phase3.py tests: stabilize integration tests + skip external services; fix multi-tenant API behavior and idempotency (#4) 2025-12-04 16:04:21 +08:00
test_workspace_isolation.py test: Add comprehensive workspace isolation test suite for PR #2366 2025-12-04 19:11:11 +08:00
test_write_json_optimization.py Optimize JSON write with fast/slow path to reduce memory usage 2025-12-04 19:09:04 +08:00

LightRAG Test Suite Index

This directory contains organized test suites for LightRAG.

Test Suites

📁 gpt5_nano_compatibility/

Comprehensive test suite for gpt-5-nano model compatibility and configuration validation.

Contents:

  • test_gpt5_nano_compatibility.py - Primary compatibility test suite (5 tests)
  • test_env_config.py - .env configuration validation (6 tests)
  • test_direct_gpt5nano.py - Direct API testing
  • test_gpt5_reasoning.py - Reasoning token overhead analysis
  • README.md - Complete documentation

Run:

cd gpt5_nano_compatibility
python test_gpt5_nano_compatibility.py  # Primary test suite
python test_env_config.py               # Configuration tests

Status: All tests passing

What's Tested

OpenAI Integration

  • API connectivity with gpt-5-nano
  • Parameter normalization (max_tokens → max_completion_tokens)
  • Temperature parameter handling
  • Token budget adjustments for reasoning overhead
  • Backward compatibility with other models

Configuration

  • .env file loading
  • Configuration parser respects environment variables
  • Model selection from configuration

Models

  • gpt-5-nano (primary, cost-optimized)
  • text-embedding-3-small (embeddings)
  • gpt-4o-mini (backward compatibility)

Functionality

  • Embeddings generation
  • Entity extraction
  • LLM completion
  • Full RAG pipeline integration

Quick Start

  1. Setup environment:

    cp .env.example .env
    # Edit .env with your OpenAI API keys
    
  2. Run primary test suite:

    cd tests/gpt5_nano_compatibility
    python test_gpt5_nano_compatibility.py
    
  3. Expected output:

    ✅ Parameter Normalization: PASSED
    ✅ Configuration Loading: PASSED
    ✅ Embeddings: PASSED
    ✅ Simple Completion: PASSED
    ✅ Entity Extraction: PASSED
    🎉 ALL TESTS PASSED
    

Key Implementation Details

Parameter Normalization

The main gpt-5-nano compatibility fix is in /lightrag/llm/openai.py:

def _normalize_openai_kwargs_for_model(model: str, kwargs: dict[str, Any]) -> None:
    """Handle model-specific parameter constraints"""
    if model.startswith("gpt-5"):
        # Convert max_tokens → max_completion_tokens
        if "max_tokens" in kwargs:
            max_tokens = kwargs.pop("max_tokens")
            kwargs["max_completion_tokens"] = int(max(max_tokens * 2.5, 300))
        
        # Remove unsupported parameters
        kwargs.pop("temperature", None)

Why 2.5x Multiplier?

gpt-5-nano uses internal reasoning that consumes tokens. Testing showed:

  • Original token budget often leaves empty responses
  • 2.5x multiplication provides adequate margin
  • 300 token minimum ensures consistency
  • /docs/GPT5_NANO_COMPATIBILITY.md - Comprehensive user guide
  • /docs/GPT5_NANO_COMPATIBILITY_IMPLEMENTATION.md - Technical implementation details
  • gpt5_nano_compatibility/README.md - Detailed test documentation

Test Statistics

  • Total Tests: 11
  • Passing: 11
  • Failing: 0
  • Coverage: OpenAI integration, configuration, embeddings, LLM, RAG pipeline

Maintenance

When modifying LightRAG's OpenAI integration:

  1. Run tests to ensure compatibility
  2. Pay special attention to parameter handling
  3. Test with both gpt-5-nano and gpt-4o-mini
  4. Update documentation if behavior changes

Last Updated: 2024 Status: Production Ready Test Coverage: OpenAI API Integration (100%)