# ╔══════════════════════════════════════════════════════════════════════╗
# ║                      TEST RECIPES                                    ║
# ║            Test workspace with different feature flags               ║
# ╚══════════════════════════════════════════════════════════════════════╝

# === FEATURE FLAGS ===
FEATURES_CLI := "cli,i18n,templates"
FEATURES_TUI := "tui,i18n,templates"
FEATURES_WEB := "web,i18n,templates"
FEATURES_AI := "ai_backend"
FEATURES_AGENT := "markup,nickel,cache"

# Help for test module
help:
    @echo "TEST MODULE"
    @echo ""
    @echo "Run all tests:"
    @echo "  just test::all          All tests (default features)"
    @echo "  just test::all-features All tests with all features"
    @echo ""
    @echo "Test specific backends:"
    @echo "  just test::cli          Test CLI backend features"
    @echo "  just test::tui          Test TUI backend features"
    @echo "  just test::web          Test Web backend features"
    @echo "  just test::ai-lib       Test AI backend lib (RAG, KG, embeddings)"
    @echo "  just test::ai           Test AI backend (FormBackend + microservice)"
    @echo "  just test::agent        Test Agent system (LLM execution)"
    @echo "  just test::prov-gen     Test Provisioning generator (IaC)"
    @echo ""
    @echo "Test by crate:"
    @echo "  just test::core         Test TypeDialog core"
    @echo "  just test::bins         Test all binaries"
    @echo ""
    @echo "Integration & docs:"
    @echo "  just test::integration  Run integration tests only"
    @echo "  just test::doc          Test documentation examples"

# === FULL TEST SUITES ===

# Run all tests (default features)
[doc("Run all tests with default features")]
all:
    @echo "=== Testing workspace (default features) ==="
    cargo test --target-dir=/tmp/typedialog-ci --workspace --lib
    @rm -rf /tmp/typedialog-ci
    @echo "✓ All tests passed"

# Run all tests with all features enabled
[doc("Run all tests with all features")]
all-features:
    @echo "=== Testing workspace (all features) ==="
    cargo test --target-dir=/tmp/typedialog-ci --workspace --all-features
    @rm -rf /tmp/typedialog-ci
    @echo "✓ All tests passed (all features)"

# === BACKEND-SPECIFIC TESTS ===

# Test CLI backend features
[doc("Test CLI backend")]
cli:
    @echo "=== Testing CLI backend ==="
    cargo test -p typedialog-core --features "{{ FEATURES_CLI }}" --lib
    cargo test -p typedialog --lib
    @echo "✓ CLI tests passed"

# Test TUI backend features
[doc("Test TUI backend")]
tui:
    @echo "=== Testing TUI backend ==="
    cargo test -p typedialog-core --features "{{ FEATURES_TUI }}" --lib
    cargo test -p typedialog-tui --lib
    @echo "✓ TUI tests passed"

# Test Web backend features
[doc("Test Web backend")]
web:
    @echo "=== Testing Web backend ==="
    cargo test -p typedialog-core --features "{{ FEATURES_WEB }}" --lib
    cargo test -p typedialog-web --lib
    @echo "✓ Web tests passed"

# Test AI backend library (RAG, Knowledge Graph, embeddings)
[doc("Test AI backend library")]
ai-lib:
    @echo "=== Testing AI backend library (RAG, KG, embeddings) ==="
    cargo test -p typedialog-core --features "{{ FEATURES_AI }}" --lib ai::
    @echo "✓ AI backend library tests passed"

# Test AI backend (FormBackend + microservice)
[doc("Test AI backend (FormBackend + microservice)")]
ai:
    @echo "=== Testing AI backend ==="
    cargo test -p typedialog-ai --lib
    @echo "✓ AI backend tests passed"

# Test Agent system (LLM execution, multi-provider)
[doc("Test Agent system (typedialog-ag)")]
agent:
    @echo "=== Testing Agent system ==="
    cargo test -p typedialog-ag-core --features "{{ FEATURES_AGENT }}" --lib
    @echo "✓ Agent tests passed"

# Test Provisioning generator (Infrastructure as Code)
[doc("Test Provisioning generator (typedialog-prov-gen)")]
prov-gen:
    @echo "=== Testing Provisioning generator ==="
    cargo test -p typedialog-prov-gen --lib
    @echo "✓ Provisioning generator tests passed"

# === CRATE-SPECIFIC TESTS ===

# Test core library only
[doc("Test typedialog-core")]
core:
    @echo "=== Testing TypeDialog core ==="
    cargo test -p typedialog-core --lib
    @echo "✓ Core tests passed"

# Test all binaries
[doc("Test all binaries")]
bins:
    @echo "=== Testing binaries ==="
    cargo test -p typedialog --lib
    cargo test -p typedialog-tui --lib
    cargo test -p typedialog-web --lib
    @echo "✓ Binary tests passed"

# === INTEGRATION & DOCS ===

# Run integration tests only
[doc("Run integration tests")]
integration:
    @echo "=== Running integration tests ==="
    cargo test --test '*' --all-features
    @echo "✓ Integration tests passed"

# Test documentation examples
[doc("Test documentation code examples")]
doc:
    @echo "=== Testing documentation examples ==="
    cargo test --doc --all-features
    @echo "✓ Doc tests passed"

# === TEST COVERAGE & ANALYSIS ===

# Run tests with output
[doc("Run tests with output")]
verbose:
    @echo "=== Testing with output ==="
    cargo test --all-features -- --nocapture
    @echo "✓ Tests complete"

# Show test list without running
[doc("List all tests without running")]
list:
    @echo "=== Available tests ==="
    cargo test --all-features -- --list
