agentleFS
NVIDIAKnown publisherNVIDIA/NeMo-Agent-Toolkit/.cursor/rules/nat-tests/integration-tests.mdc

NeMo-Agent-Toolkit / nat-tests

Cursor rule2.7k starsChanged 16 months agoApache-2.0View on GitHub

Follow these rules when the user's request involves writing, creating, or modifying integration tests for NeMo Agent Toolkit workflows

  • Reads credentials

Trending

Quiet since August.about the whole repository

Dec 2025: 0 mentionsJan 2026: 1 mentionFeb 2026: 0 mentionsMar 2026: 2 mentionsApr 2026: 4 mentionsMay 2026: 2 mentionsJun 2026: 1 mentionJul 2026: 1 mentionAug 2026: 1 mentionSep 2026: 0 mentionsOct 2026: 0 mentionsNov 2026: 0 mentions
Dec 2025Jun 2026Nov 2026
Mentions a month of the NVIDIA/NeMo-Agent-Toolkit repository that our weekly crawl found. There is no adoption data for this file yet.

Who's talking about NVIDIA/NeMo-Agent-Toolkit

The biggest 5 of 15 mentions linking to the repository that our crawl found. Each line is their own headline.

See all 15

Talked about on GitHub (15 times).

On GitHub · 15

10 more on GitHub

The file

Show its rules and text

We split this integration-tests.mdc into the rules it gives an agent

17 rules. About 0 are common, 9 are distinctive, and 8 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈9

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 8

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Follow these rules when writing integration tests for NeMo Agent Toolkit workflows.

    line 9
  2. Distinctive:

    Every integration test MUST include the decorators:

    line 13
  3. Very specific:

    Use scope="session" for service fixtures

    line 150
  4. Very specific:

    Add new services to tests/test_data/docker-compose.services.yml

    line 154
  5. Very specific:

    Use @pytest.mark.integration decorator, and optionally the @pytest.mark.slow decorator for slow tests

    line 160
  6. Very specific:

    Use @pytest.mark.usefixtures() for required API keys

    line 161
  7. Very specific:

    Use locate_example_config() for workflows with config classes

    line 162
  8. Very specific:

    Use run_workflow() for consistent test execution

    line 163
  9. Distinctive:

    Use simple, predictable questions and expected answers

    line 164
  10. Distinctive:

    Import test utilities within test functions (not module level)

    line 166
  11. Distinctive:

    Use session-scoped fixtures for services

    line 168
  12. Distinctive:

    Use lazy imports in fixtures for optional dependencies

    line 169
  13. Distinctive:

    Use complex questions with unpredictable LLM responses

    line 174
  14. Distinctive:

    Import third-party service libraries at module level in fixtures

    line 175
  15. Distinctive:

    Use function scope for service fixtures (use session scope)

    line 176
  16. Very specific:

    Add @pytest.mark.asyncio decorator - async tests are automatically detected and run by the async runner

    line 178
  17. Very specific:

    Test utilities and fixtures: packages/nvidia_nat_test/src/nat/test/plugin.py

    line 198

≈ “Common” is an estimate: at least 1 in 5 of the 3,030 Cursor rule files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
integration-tests.mdc
---
description: Follow these rules when the user's request involves writing, creating, or modifying integration tests for NeMo Agent Toolkit workflows
globs:
alwaysApply: false
---

# Integration Testing Guidelines

Follow these rules when writing integration tests for NeMo Agent Toolkit workflows.

## Required Test Structure

Every integration test MUST include the decorators:

```python
@pytest.mark.integration
async def test_workflow():
    from nat.test.utils import locate_example_config, run_workflow
    from workflow_package.register import WorkflowConfig

    config_file = locate_example_config(WorkflowConfig)
    await run_workflow(config_file=config_file, question="test", expected_answer="answer")
```

### Decorator Purposes

- `@pytest.mark.slow` - Tests taking longer than 30 seconds
- `@pytest.mark.integration` - Tests requiring external services or API keys
- `@pytest.mark.usefixtures(...)` - Ensures required fixtures are available

## API Key Fixtures

Available from `nvidia-nat-test` package:

- `nvidia_api_key`, `openai_api_key`, `tavily_api_key`
- `mem0_api_key`, `azure_openai_api_key`
- `serp_api_key`, `serperdev_api_key`

Multiple fixtures: `@pytest.mark.usefixtures("nvidia_api_key", "tavily_api_key")`

## Test Utility Functions

### locate_example_config()

Locates configuration files relative to workflow configuration class:

```python
from nat.test.utils import locate_example_config

config_file = locate_example_config(WorkflowConfig)  # finds config.yml
config_file = locate_example_config(WorkflowConfig, "config-alt.yml")
```

### run_workflow()

Runs workflow and validates expected answer:

```python
from nat.test.utils import run_workflow

# Basic usage - case-insensitive matching
await run_workflow(
    config_file=config_file,
    question="What are LLMs?",
    expected_answer="Large Language Model"
)

# Custom validation
result = await run_workflow(
    config_file=config_file,
    question="What are LLMs?",
    expected_answer="",
    assert_expected_answer=False
)
assert "large language model" in result.lower()

# Using config object instead of file
from nat.runtime.loader import load_config
config = load_config(config_file)
config.retrievers['retriever'].uri = HttpUrl(url=service_uri)
await run_workflow(config=config, question="...", expected_answer="...")
```

## Workflows Without Configuration Classes

For YAML-only workflows:

```python
from pathlib import Path

config_file = Path(__file__).parent / "configs/config.yml"
await run_workflow(config_file=config_file, question="...", expected_answer="...")
```

## Service Fixtures

Available service fixtures that ensure services are running:

- `milvus_uri`, `etcd_url`, `redis_url`
- `mysql_connection_info`, `opensearch_url`
- `phoenix_url`, `minio_client`

Example:

```python
@pytest.mark.slow
@pytest.mark.integration
@pytest.mark.usefixtures("nvidia_api_key")
async def test_workflow(milvus_uri: str):
    from pydantic import HttpUrl
    from nat.runtime.loader import load_config
    from nat.test.utils import locate_example_config, run_workflow

    config_file = locate_example_config(WorkflowConfig)
    config = load_config(config_file)
    config.retrievers['retriever'].uri = HttpUrl(url=milvus_uri)

    await run_workflow(config=config, question="test", expected_answer="answer")
```

## Creating Custom Service Fixtures

Pattern for new service fixtures:

```python
import os
import pytest

@pytest.fixture(name="service_uri", scope="session")
def service_uri_fixture(fail_missing: bool = False) -> str:
    """Ensure service is running and provide connection URI."""
    host = os.getenv("NAT_CI_SERVICE_HOST", "localhost")
    port = os.getenv("NAT_CI_SERVICE_PORT", "1234")
    uri = f"http://{host}:{port}"

    try:
        # Lazy import - optional dependency
        from service_library import ServiceClient
        ServiceClient(uri=uri).ping()
        return uri
    except Exception:
        reason = f"Unable to connect to Service at {uri}"
        if fail_missing:
            raise RuntimeError(reason)
        pytest.skip(reason=reason)
```

Key practices:

- Use `scope="session"` for service fixtures
- Lazy import service libraries inside fixture
- Allow configuration via environment variables, prefixed with `NAT_CI_`
- Skip tests if service unavailable (unless `--fail_missing`)
- Add new services to `tests/test_data/docker-compose.services.yml`

## Best Practices

### DO

- Use `@pytest.mark.integration` decorator, and optionally the `@pytest.mark.slow` decorator for slow tests
- Use `@pytest.mark.usefixtures()` for required API keys
- Use `locate_example_config()` for workflows with config classes
- Use `run_workflow()` for consistent test execution
- Use simple, predictable questions and expected answers
- Override config values to use test service URIs from fixtures
- Import test utilities within test functions (not module level)
- Make tests async with `async def`
- Use session-scoped fixtures for services
- Use lazy imports in fixtures for optional dependencies

### DON'T

- Hard-code service URLs (use fixtures instead)
- Use complex questions with unpredictable LLM responses
- Import third-party service libraries at module level in fixtures
- Use function scope for service fixtures (use session scope)
- Fail tests when services are unavailable (skip them instead)
- Add `@pytest.mark.asyncio` decorator - async tests are automatically detected and run by the async runner

## Running Integration Tests

```bash
# Set API keys
export NVIDIA_API_KEY=<key>

# Start services
docker compose -f tests/test_data/docker-compose.services.yml up -d

# Run tests
pytest --run_slow --run_integration

# Clean up
docker compose -f tests/test_data/docker-compose.services.yml down
```

## Reference

- Test utilities and fixtures: `packages/nvidia_nat_test/src/nat/test/plugin.py`
- Docker Compose services: `tests/test_data/docker-compose.services.yml`
- Full documentation: [Running Tests](mdc:docs/source/resources/running-tests.md)

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.