# Test Scripts

This directory contains functional test scripts for OmniClaude infrastructure and services.

## Available Tests

### Intelligence Functional Test

**File**: `test_intelligence_functionality.sh`

**Purpose**: Verifies the Intelligence infrastructure is working correctly by testing actual Qdrant queries, pattern retrieval, and manifest injection capabilities.

**What it tests**:
- ✅ Qdrant connectivity and health
- ✅ Collection verification (archon_vectors, code_generation_patterns, etc.)
- ✅ Pattern retrieval via Python API
- ✅ ManifestInjector infrastructure availability
- ✅ Query performance (measures response times)
- ⚠️ Cache availability (optional - Valkey/Redis)

**Usage**:
```bash
# Run the test
./scripts/tests/test_intelligence_functionality.sh

# Expected output:
# ===========================================
# TEST SUMMARY
# ===========================================
# Passed: 7
# Failed: 0
#
# ✅ ALL TESTS PASSED
```

**Success Criteria**:
- All Qdrant collections accessible
- Pattern retrieval returns results
- Query performance <2000ms (excellent <100ms)
- ManifestInjector infrastructure available

**Troubleshooting**:

If tests fail:

1. **Qdrant not accessible**:
   ```bash
   docker ps | grep qdrant
   docker logs archon-qdrant
   ```

2. **No patterns found**:
   ```bash
   curl http://localhost:6333/collections
   # Verify collections have vectors
   ```

3. **Slow query times (>2000ms)**:
   - Check Qdrant container resources
   - Reduce pattern limit in manifest_injector.py
   - Check network connectivity

4. **ManifestInjector import errors**:
   - Circular import warnings are expected (known issue)
   - File existence is verified as a fallback
   - Runtime functionality is not affected

## Performance Benchmarks

### Query Performance Thresholds

| Metric | Excellent | Good | Acceptable | Issue |
|--------|-----------|------|------------|-------|
| Average query time | <100ms | <500ms | <2000ms | >2000ms |
| Pattern retrieval | <50ms | <200ms | <1000ms | >1000ms |

### Expected Results (Baseline)

Based on test runs on local development environment:

- **Qdrant connectivity**: <10ms
- **Pattern retrieval**: 5-50ms
- **Collection query**: 5-30ms average
- **Total test runtime**: 10-30 seconds

## Adding New Tests

When adding new functional tests:

1. **Create script**: `test_<feature>_functionality.sh`
2. **Make executable**: `chmod +x test_<feature>_functionality.sh`
3. **Follow patterns**:
   - Set `-e` for exit on error
   - Use helper functions: `pass_test()`, `fail_test()`, `warn_test()`
   - Add summary section at end
   - Document in this README

4. **Test structure**:
   ```bash
   #!/bin/bash
   set -e

   # Load environment
   source .env

   # Test counters
   TESTS_PASSED=0
   TESTS_FAILED=0

   # Helper functions
   pass_test() { ... }
   fail_test() { ... }

   # Tests...

   # Summary
   echo "Passed: $TESTS_PASSED"
   echo "Failed: $TESTS_FAILED"
   ```

## CI/CD Integration

These tests can be integrated into CI/CD pipelines:

```bash
# Run all tests and check exit code
./scripts/tests/test_intelligence_functionality.sh
if [ $? -eq 0 ]; then
  echo "Intelligence tests passed"
else
  echo "Intelligence tests failed"
  exit 1
fi
```

## Known Issues

### Circular Import in Config Module

**Issue**: `cannot import name 'reload_settings' from partially initialized module 'config'`

**Impact**: Does not affect runtime functionality. ManifestInjector works correctly when services are running.

**Workaround**: Test checks for file existence and handles import errors gracefully.

**Status**: Known issue, low priority (does not affect functionality).

## Related Documentation

- **Intelligence Infrastructure**: `/Volumes/PRO-G40/Code/omniclaude/CLAUDE.md#intelligence-infrastructure`  <!-- local-path-ok -->
- **Qdrant Configuration**: `~/.claude/CLAUDE.md#qdrant-configuration`
- **Manifest Injection**: `/Volumes/PRO-G40/Code/omniclaude/agents/lib/manifest_injector.py`  <!-- local-path-ok -->
- **Health Check Script**: `/Volumes/PRO-G40/Code/omniclaude/scripts/health_check.sh`  <!-- local-path-ok -->

---

**Last Updated**: 2025-11-09
**Test Coverage**: Intelligence infrastructure, Qdrant connectivity, pattern retrieval
