llama-stack-mirror/tests/unit/cli/README.md
Akram Ben Aissi 1da7714bab Add version command with comprehensive unit tests and build integration
- Implement llama version command with table and JSON output formats
- Add build-time git information capture via scripts/generate_build_info.py
- Include comprehensive unit test suite (test_version.py, test_version_simple.py, test_version_integration.py)
- Add build system integration with custom setup.py command
- Update .gitignore to exclude generated build info file

Features:
- Display Llama Stack and client versions
- Show Python version and build information (git commit, date, branch, tag)
- Optional component/provider listing organized by API
- Support for both table and JSON output formats
- Build-time capture of git metadata for version tracking

Testing:
- 8 unit tests covering all functionality
- Integration tests for CLI execution
- Simple dependency-free validation tests
- Documentation for test suite and build process

Signed-off-by: Akram Ben Aissi <akram.benaissi@gmail.com>
2025-06-26 12:53:28 +02:00

2.5 KiB

CLI Unit Tests

This directory contains unit tests for the Llama Stack CLI commands.

Test Files

test_version.py

Comprehensive unit tests for the llama version command using pytest and mocking. These tests cover:

  • Package version retrieval
  • Build information handling
  • Component information retrieval
  • JSON and table output formats
  • Error handling scenarios
  • Component type detection

Requirements: pytest, unittest.mock

Run with: pytest tests/unit/cli/test_version.py -v

test_version_simple.py

Simple unit tests that can run without external dependencies. These tests verify:

  • File structure and existence
  • Code structure and imports
  • Logic validation
  • Configuration correctness

Requirements: None (uses only standard library)

Run with: python tests/unit/cli/test_version_simple.py

test_version_integration.py

Integration tests that test the actual CLI command execution. These tests:

  • Execute the actual CLI commands
  • Verify command-line interface
  • Test real output formats
  • Validate build script execution

Requirements: Full Llama Stack environment

Run with: python tests/unit/cli/test_version_integration.py

test_stack_config.py

Tests for stack configuration parsing and upgrading.

Running Tests

Run All CLI Tests

# With pytest (if available)
pytest tests/unit/cli/ -v

# Simple tests only (no dependencies)
python tests/unit/cli/test_version_simple.py

Run Specific Tests

# Run version command tests
python tests/unit/cli/test_version_simple.py

# Run integration tests (requires full environment)
python tests/unit/cli/test_version_integration.py

Test Coverage

The version command tests cover:

  • Package version detection
  • Build information retrieval
  • Component discovery and listing
  • JSON output format
  • Table output format
  • Error handling
  • CLI integration
  • Build script functionality
  • File structure validation

Adding New Tests

When adding new CLI commands or functionality:

  1. Create unit tests following the pattern in test_version.py
  2. Add simple validation tests in a test_<command>_simple.py file
  3. Consider integration tests for end-to-end validation
  4. Update this README with the new test information

Notes

  • Simple tests are preferred for CI/CD as they have no external dependencies
  • Integration tests are useful for local development and full validation
  • Mock-based tests provide comprehensive coverage of edge cases