Test qa

From minh2004pd/chatbotfullpipeline · View interactive version

Test qa is an AI agent skill from the GitHub repository minh2004pd/chatbotfullpipeline. Create test cases, run QA/QC checks, and ensure code quality. Use when asked to write tests, review code quality, or perform QA. Supports: unit tests, integration tests, coverage analysis, linting, type checking.

How to use this skill

Skill file

Test & QA Agent

Overview

This skill handles test creation, test execution, and quality assurance for the MemRAG project.

Test Structure

Backend Tests (pytest)

Frontend Tests

Commands

Run All Backend Tests

cd /home/minhdd/pet_proj/proj2/backend && uv run pytest tests/ -v

Run with Coverage

cd /home/minhdd/pet_proj/proj2/backend && uv run pytest tests/ -v --cov=app --cov-report=term-missing --cov-report=html

Run Specific Test File

cd /home/minhdd/pet_proj/proj2/backend && uv run pytest tests/test_wiki_service.py -v

Run Specific Test Function

cd /home/minhdd/pet_proj/proj2/backend && uv run pytest tests/test_wiki_service.py::test_slugify_basic -v

Run Tests Matching Pattern

cd /home/minhdd/pet_proj/proj2/backend && uv run pytest tests/ -k "wiki" -v

Linting & Formatting

# Backend
cd /home/minhdd/pet_proj/proj2/backend && uv run ruff format . && uv run ruff check .

# Frontend
cd /home/minhdd/pet_proj/proj2/frontend && npm run lint

Test Writing Conventions

Backend Test Patterns

  1. Use fixtures from conftest.py:
  1. Mock external services via dependency_overrides:
@pytest.fixture
def mock_qdrant_client(app):
    client = MagicMock()
    client.search.return_value = []
    app.dependency_overrides[get_qdrant_client] = lambda: client
    return client
  1. Async tests:
@pytest.mark.asyncio
async def test_something(service):
    result = await service.some_method()
    assert result is not None
  1. Patch LLM calls:
from unittest.mock import patch as _patch
from unittest.mock import AsyncMock

with _patch("app.services.wiki_service.get_genai_client") as mock_client:
    mock_client.return_value.aio.models.generate_content.side_effect = RuntimeError("LLM down")
    result = await service._extract_topics(text="some text", source_name="paper.pdf")
  1. Test structure:

Test Categories

  1. Unit Tests (test_*_service.py, test_*_repo.py)
  1. Integration Tests (test_*.py for API endpoints)
  1. Edge Cases

QA Checklist

When reviewing code or creating tests, ensure:

Code Quality

Test Coverage

Integration

Documentation

Creating New Tests

When asked to create tests:

  1. Identify what to test:
  1. Choose test type:
  1. Write the test:
  1. Verify:

Debugging Failed Tests

When tests fail:

  1. Read the error message carefully
  2. Check if it's a mock issue:
  1. Check if it's a logic issue:
  1. Run with verbose output:

```bash

uv run pytest tests/test_file.py::test_name -v -s

```

  1. Use pytest debugger:

```python

import pytest; pytest.set_trace()

```

Common Patterns

Testing Async Methods

@pytest.mark.asyncio
async def test_async_method(service):
    result = await service.async_method()
    assert result == expected

Testing Error Handling

@pytest.mark.asyncio
async def test_method_handles_error(service):
    with patch.object(service, "dependency", side_effect=RuntimeError("fail")):
        await service.method()  # Should not raise

Testing HTTP Endpoints

@pytest.mark.asyncio
async def test_endpoint(client):
    response = await client.post("/api/v1/chat", json={"message": "hello"})
    assert response.status_code == 200
    assert "response" in response.json()

Testing Wiki Service

@pytest.mark.asyncio
async def test_wiki_synthesis(service, repo):
    topics = [{"slug": "test-topic", "category": "topics", "title": "Test"}]
    synthesized = "---\ntitle: Test\nsources: [doc-1]\n---\n# Test"

    with (
        patch.object(service, "_extract_topics", new=AsyncMock(return_value=topics)),
        patch.object(service, "_synthesize_page", new=AsyncMock(return_value=synthesized)),
    ):
        await service.update_wiki_from_document(
            user_id=USER,
            document_id="doc-1",
            filename="test.pdf",
            full_text="content",
        )

    page = repo.read_page(user_id=USER, rel_path="pages/topics/test-topic.md")
    assert page is not None

Running Full QA Suite

Before marking a task complete:

# 1. Lint & format
cd /home/minhdd/pet_proj/proj2/backend && uv run ruff format . && uv run ruff check .

# 2. Run tests with coverage
cd /home/minhdd/pet_proj/proj2/backend && uv run pytest tests/ -v --cov=app --cov-report=term-missing

# 3. Frontend lint (if frontend changed)
cd /home/minhdd/pet_proj/proj2/frontend && npm run lint

Report results:

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.