bottest/PROMPT.md
Rodrigo Rodriguez (Pragmatismo) af41ecbdb0 feat: add BotUI orchestration for e2e browser tests
- Add BotUIInstance struct to start botui alongside botserver
- Update E2ETestContext to start botui and use its URL as base_url
- Add start_botui() method to TestContext
- Fix harness to use env vars BOTUI_PORT and BOTSERVER_URL for botui
- Update harness to use debug build by default
- Add SKIP_LLM_SERVER env var to skip local LLM server in tests
- Make stack_path absolute and canonicalize botserver paths
2025-12-14 15:59:07 -03:00

3.8 KiB

BotTest Development Prompt

Version: 6.1.0
Purpose: Test infrastructure for General Bots ecosystem


CRITICAL RULE

🚫 NO .md FILES IN ROOT OF ANY PROJECT

All documentation goes in botbook/src/17-testing/:

  • README.md - Testing overview
  • e2e-testing.md - E2E test guide
  • architecture.md - Testing architecture
  • performance.md - Performance testing
  • best-practices.md - Best practices

This PROMPT.md is the ONLY exception (it's for developers).


Core Principle

Reuse botserver bootstrap code - Don't duplicate installation logic. The bootstrap module already knows how to install PostgreSQL, MinIO, Redis. We wrap it with test-specific configuration (custom ports, temp directories).


Architecture

IMPORTANT: E2E tests always use USE_BOTSERVER_BOOTSTRAP=1 mode. No global PostgreSQL or other services are required. 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

TestContext provides:
    - db_pool() -> Database connection
    - minio_client() -> S3 client
    - redis_client() -> Redis client
    - mock_*() -> Mock server controls

On Drop:
    - Stop all services
    - Remove temp directory

Code Style

Same as botserver PROMPT.md:

  • KISS, NO TALK, SECURED CODE ONLY
  • No comments, no placeholders
  • Complete, production-ready code
  • Return 0 warnings

Test Categories

Unit Tests (no services)

#[test]
fn test_pure_logic() {
    // No TestHarness needed
    // Test pure functions directly
}

Integration Tests (with services)

#[tokio::test]
async fn test_with_database() {
    let ctx = TestHarness::quick().await.unwrap();
    let pool = ctx.db_pool().await.unwrap();
    // Use real database
}

E2E Tests (with browser)

#[tokio::test]
async fn test_user_flow() {
    let ctx = TestHarness::full().await.unwrap();
    let server = ctx.start_botserver().await.unwrap();
    let browser = Browser::new().await.unwrap();
    // Automate browser
}

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");

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;

Cleanup

Always automatic via Drop trait. But can force:

ctx.cleanup().await;  // Explicit cleanup

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

Documentation Location

For guides, tutorials, and reference: → Use botbook/src/17-testing/

Examples:

  • E2E testing setup → botbook/src/17-testing/e2e-testing.md
  • Architecture details → botbook/src/17-testing/architecture.md
  • Performance tips → botbook/src/17-testing/performance.md

Never create .md files at:

  • ✗ Root of bottest/
  • ✗ Root of botserver/
  • ✗ Root of botapp/
  • ✗ Any project root

All non-PROMPT.md documentation belongs in botbook.