Skip to content

GeneralBots/bottest

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

45 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Bottest - General Bots Test Infrastructure

Version: 6.2.0
Purpose: Test infrastructure for General Bots ecosystem


Overview

Bottest provides the comprehensive testing infrastructure for the General Bots ecosystem, including unit tests, integration tests, and end-to-end (E2E) tests. It ensures code quality, reliability, and correct behavior across all components of the platform.

The test harness handles service orchestration, mock servers, fixtures, and browser automation, making it easy to write comprehensive tests that cover the entire system from database operations to full user flows.

For comprehensive documentation, see docs.pragmatismo.com.br or the BotBook for detailed guides and testing best practices.


πŸ—οΈ Testing Architecture

E2E tests use USE_BOTSERVER_BOOTSTRAP=1 mode. The botserver handles all service installation during bootstrap.

TestHarness::full() / E2E Tests
    β”‚
    β”œβ”€β”€ Allocate unique ports (15000+)
    β”œβ”€β”€ Create ./tmp/bottest-{uuid}/
    β”‚
    β”œβ”€β”€ Start mock servers only
    β”‚   β”œβ”€β”€ MockZitadel (wiremock)
    β”‚   └── MockLLM (wiremock)
    β”‚
    β”œβ”€β”€ Start botserver with --stack-path
    β”‚   └── Botserver auto-installs:
    β”‚       β”œβ”€β”€ PostgreSQL (tables)
    β”‚       β”œβ”€β”€ MinIO (drive)
    β”‚       └── Redis (cache)
    β”‚
    └── Return TestContext

πŸ§ͺ Test Categories

Unit Tests (no services)

#[test]
fn test_pure_logic() {
    // No TestHarness needed
    assert_eq!(add(2, 3), 5);
}

Integration Tests (with services)

#[tokio::test]
async fn test_with_database() {
    let ctx = TestHarness::quick().await?;
    let pool = ctx.db_pool().await?;
    
    // Use real database
    let user = fixtures::admin_user();
    ctx.insert(&user).await;
    
    // Test database operations
}

E2E Tests (with browser)

#[tokio::test]
async fn test_user_flow() {
    let ctx = TestHarness::full().await?;
    let server = ctx.start_botserver().await?;
    let browser = Browser::new().await?;
    
    // Automate browser
    browser.goto(server.url()).await?;
    browser.click("#login-button").await?;
    
    // Verify user flow
    assert!(browser.is_visible("#dashboard").await?);
}

🎭 Mock Server Patterns

Expect specific calls

ctx.mock_llm().expect_completion("hello", "Hi there!");

Verify calls were made

ctx.mock_llm().assert_called_times(2);

Simulate errors

ctx.mock_llm().next_call_fails(500, "Internal error");

Mock authentication

ctx.mock_zitadel().expect_login_success("user@example.com", "password");

🏭 Fixture Patterns

Factory functions

let user = fixtures::admin_user();
let bot = fixtures::bot_with_kb();
let session = fixtures::active_session(&user, &bot);

Insert into database

ctx.insert(&user).await;
ctx.insert(&bot).await;
ctx.insert(&session).await;

Custom fixtures

fn custom_bot() -> Bot {
    Bot {
        name: "Test Bot".to_string(),
        enabled: true,
        ..fixtures::base_bot()
    }
}

⚑ Parallel Safety

  • Each test gets unique ports via PortAllocator
  • Each test gets unique temp directory
  • No shared state between tests
  • Safe to run with cargo test -j 8

βœ… ZERO TOLERANCE POLICY

EVERY SINGLE WARNING MUST BE FIXED. NO EXCEPTIONS.

Absolute Prohibitions

❌ NEVER use #![allow()] or #[allow()] in source code
❌ NEVER use _ prefix for unused variables - DELETE or USE them
❌ NEVER use .unwrap() - use ? or proper error handling
❌ NEVER use .expect() - use ? or proper error handling  
❌ NEVER use panic!() or unreachable!()
❌ NEVER use todo!() or unimplemented!()
❌ NEVER leave unused imports or dead code
❌ NEVER add comments - code must be self-documenting

Code Patterns

// ❌ WRONG
let value = something.unwrap();

// βœ… CORRECT
let value = something?;
let value = something.ok_or_else(|| Error::NotFound)?;

// Use Self in Impl Blocks
impl TestStruct {
    fn new() -> Self { Self { } }  // βœ… Not TestStruct
}

// Derive Eq with PartialEq
#[derive(PartialEq, Eq)]  // βœ… Always both
struct TestStruct { }

// Inline Format Args
format!("Hello {name}")  // βœ… Not format!("{}", name)

πŸš€ Running Tests

Run all tests

cargo test -p bottest

Run specific test category

# Unit tests only
cargo test -p bottest --lib

# Integration tests
cargo test -p bottest --test '*'

# E2E tests only
cargo test -p bottest --test '*' -- --ignored

Run tests with output

cargo test -p bottest -- --nocapture

Run tests in parallel

cargo test -p bottest -j 8

πŸ“ Project Structure

bottest/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ lib.rs              # Test harness exports
β”‚   β”œβ”€β”€ harness.rs          # TestHarness implementation
β”‚   β”œβ”€β”€ context.rs          # TestContext for resource access
β”‚   β”œβ”€β”€ mocks/              # Mock server implementations
β”‚   β”‚   β”œβ”€β”€ zitadel.rs
β”‚   β”‚   └── llm.rs
β”‚   β”œβ”€β”€ fixtures.rs         # Factory functions
β”‚   └── utils.rs            # Testing utilities
β”œβ”€β”€ tests/                  # Integration and E2E tests
β”‚   β”œβ”€β”€ integration/
β”‚   β”‚   β”œβ”€β”€ database_tests.rs
β”‚   β”‚   └── api_tests.rs
β”‚   └── e2e/
β”‚       └── user_flows.rs
└── Cargo.toml

πŸ“š Documentation

Testing Documentation

All testing documentation is located in botbook/src/17-testing/:

  • README.md - Testing overview and philosophy
  • e2e-testing.md - E2E test guide with examples
  • architecture.md - Testing architecture and design
  • best-practices.md - Best practices and patterns
  • mock-servers.md - Mock server configuration
  • fixtures.md - Fixture usage and creation

Additional Resources


πŸ”— Related Projects

Project Description
botserver Main API server (tested)
botui Web UI (E2E tested)
botlib Shared library
botbook Documentation

πŸ”‘ Remember

  • ZERO WARNINGS - Every clippy warning must be fixed
  • NO ALLOW ATTRIBUTES - Never silence warnings
  • NO DEAD CODE - Delete unused code
  • NO UNWRAP/EXPECT - Use ? operator
  • INLINE FORMAT ARGS - format!("{name}") not format!("{}", name)
  • USE SELF - In impl blocks, use Self not type name
  • Reuse bootstrap - Don't duplicate botserver installation logic
  • Parallel safe - Each test gets unique ports and directories
  • Version 6.2.0 - Do not change without approval
  • GIT WORKFLOW - ALWAYS push to ALL repositories (github, pragmatismo)

πŸ“„ License

AGPL-3.0 - See LICENSE for details.

About

General Bots LLM tests.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages