File size: 8,967 Bytes
c87f72b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
# Testing Documentation for VAMGUARD_TITAN / TIA-ARCHITECT-CORE

## Overview

This document provides comprehensive information about the test suite for the VAMGUARD_TITAN repository, including test coverage, how to run tests, and testing best practices.

## Test Structure

```
tests/
β”œβ”€β”€ __init__.py                           # Test package initialization
β”œβ”€β”€ conftest.py                           # Pytest fixtures and configuration
β”œβ”€β”€ test_genesis_boiler.py                # Tests for genesis_boiler.py
β”œβ”€β”€ test_worker_watchdog.py               # Tests for worker_watchdog.py
β”œβ”€β”€ test_self_healing_worker.py           # Tests for self_healing_worker.py
β”œβ”€β”€ test_apps_script_toolbox.py           # Tests for apps_script_toolbox.py
β”œβ”€β”€ test_download_citadel_omega_models.py # Tests for download scripts
└── test_app.py                           # Tests for Streamlit app
```

## Test Coverage

### Module Coverage

| Module | Coverage | Test Cases | Status |
|--------|----------|------------|--------|
| genesis_boiler.py | ~95% | 25+ | βœ… Complete |
| worker_watchdog.py | ~90% | 30+ | βœ… Complete |
| self_healing_worker.py | ~90% | 35+ | βœ… Complete |
| apps_script_toolbox.py | ~85% | 20+ | βœ… Complete |
| download_citadel_omega_models.py | ~80% | 15+ | βœ… Complete |
| app.py | ~75% | 25+ | βœ… Complete |

### Coverage by Component

#### GenesisBoiler (genesis_boiler.py)
- βœ… Initialization
- βœ… Territory auditing
- βœ… File consolidation (tarball creation)
- βœ… Error handling (OSError, PermissionError, IOError)
- βœ… Path validation
- βœ… Multiple source handling
- βœ… Non-existent path handling

#### WorkerWatchdog (worker_watchdog.py)
- βœ… Initialization and configuration
- βœ… File hash calculation (SHA256)
- βœ… Change detection (new, modified, deleted files)
- βœ… Self-healing trigger
- βœ… Workflow health checking
- βœ… State persistence (save/load)
- βœ… Continuous monitoring
- βœ… Template change detection

#### SelfHealingWorker (self_healing_worker.py)
- βœ… Script health checking
- βœ… Python script validation (AST parsing)
- βœ… Bash script validation
- βœ… Import checking
- βœ… Auto-repair (shebang, imports, permissions)
- βœ… Backup creation
- βœ… Health reporting
- βœ… Full healing workflow

#### AppsScriptToolbox (apps_script_toolbox.py)
- βœ… Worker initialization
- βœ… Connection verification
- βœ… Identity strike reports
- βœ… Full archive audits
- βœ… Worker status dashboard
- βœ… Error handling

#### Download Scripts
- βœ… Model downloading
- βœ… Registry creation
- βœ… Path management
- βœ… Error handling
- βœ… Already-downloaded detection

#### Streamlit App (app.py)
- βœ… Configuration structure
- βœ… Environment variables
- βœ… Data directory management
- βœ… UI component structure
- βœ… Models registry integration
- βœ… Workers constellation
- βœ… RAG system references
- βœ… Tools and utilities

## Running Tests

### Prerequisites

```bash
# Install main dependencies
pip install -r requirements.txt

# Install test dependencies
pip install -r requirements-test.txt
```

### Run All Tests

```bash
# Run all tests with coverage
pytest -v --cov=. --cov-report=term-missing

# Run all tests with HTML coverage report
pytest -v --cov=. --cov-report=html

# Run specific test file
pytest tests/test_genesis_boiler.py -v

# Run specific test class
pytest tests/test_genesis_boiler.py::TestGenesisBoilerInit -v

# Run specific test
pytest tests/test_genesis_boiler.py::TestGenesisBoilerInit::test_init_default_values -v
```

### Test Markers

Tests are marked with the following markers:

- `@pytest.mark.unit` - Unit tests
- `@pytest.mark.integration` - Integration tests
- `@pytest.mark.slow` - Slow-running tests
- `@pytest.mark.requires_network` - Tests requiring network access
- `@pytest.mark.requires_hf_token` - Tests requiring HuggingFace token

```bash
# Run only unit tests
pytest -v -m unit

# Run only integration tests
pytest -v -m integration

# Skip slow tests
pytest -v -m "not slow"

# Skip network-dependent tests
pytest -v -m "not requires_network"
```

### Coverage Reports

```bash
# Generate coverage report
coverage run -m pytest
coverage report

# Generate HTML coverage report
coverage html
# Open htmlcov/index.html in browser

# Generate XML coverage report (for CI/CD)
coverage xml
```

## Test Fixtures

### Common Fixtures (from conftest.py)

- `temp_dir` - Creates a temporary directory for testing
- `mock_env_vars` - Mocks environment variables
- `sample_python_file` - Creates a sample Python file
- `sample_directory_structure` - Creates a directory structure with files

### Usage Example

```python
def test_with_temp_dir(temp_dir):
    """Test using temp_dir fixture"""
    test_file = temp_dir / "test.txt"
    test_file.write_text("content")
    assert test_file.exists()

def test_with_mock_env(mock_env_vars):
    """Test using mocked environment variables"""
    assert os.getenv("HF_TOKEN") == "test_token_123"
```

## Writing New Tests

### Test Structure

```python
"""
Module docstring explaining what is being tested
"""
import pytest
from pathlib import Path
from unittest.mock import Mock, patch
import sys

# Add parent to path if needed
sys.path.insert(0, str(Path(__file__).parent.parent))

from module_to_test import ClassToTest


class TestClassName:
    """Test class with descriptive name"""

    def test_specific_functionality(self):
        """Test with clear description"""
        # Arrange
        obj = ClassToTest()

        # Act
        result = obj.method()

        # Assert
        assert result == expected_value
```

### Best Practices

1. **Descriptive Names**: Use clear, descriptive test names
2. **Arrange-Act-Assert**: Structure tests with clear sections
3. **One Assertion Per Test**: Focus each test on one behavior
4. **Use Fixtures**: Reuse common setup code via fixtures
5. **Mock External Dependencies**: Use mocks for external services
6. **Test Edge Cases**: Include error conditions and edge cases
7. **Document Tests**: Add docstrings explaining what is being tested

## Continuous Integration

Tests run automatically on:
- Push to `main`, `develop`, or `claude/*` branches
- Pull requests to `main`
- Manual workflow dispatch

### CI/CD Pipeline

1. **Test Job**: Runs tests on Python 3.10, 3.11, 3.12, 3.13
2. **Lint Job**: Runs ruff, black, isort
3. **Coverage Upload**: Uploads coverage to Codecov
4. **Artifacts**: Saves HTML coverage reports

## Areas for Future Improvement

### Missing Test Coverage

1. **Integration Tests**
   - End-to-end workflow tests
   - Multi-component integration tests
   - Real HuggingFace API tests (with token)

2. **Performance Tests**
   - Large file handling
   - Memory usage
   - Execution time benchmarks

3. **UI Tests**
   - Streamlit component testing
   - UI interaction tests
   - Visual regression tests

4. **Network Tests**
   - API endpoint tests
   - Model download tests (requires network)
   - GitHub API integration tests

### Recommendations

1. **Increase Coverage**
   - Add edge case tests
   - Test error recovery paths
   - Add boundary condition tests

2. **Add Integration Tests**
   - Test complete workflows
   - Test component interactions
   - Test with real data

3. **Performance Testing**
   - Add benchmarks for critical paths
   - Memory profiling
   - Load testing

4. **Documentation**
   - Add more test examples
   - Document testing patterns
   - Create testing guide

## Test Metrics

### Current Status (as of 2026-04-14)

- **Total Test Files**: 7
- **Total Test Cases**: 150+
- **Overall Coverage**: ~85%
- **Lines Covered**: ~1800+ lines
- **Branches Covered**: ~70%

### Coverage Goals

- **Target Coverage**: 90%
- **Minimum Coverage**: 80%
- **Critical Modules**: 95%+

## Troubleshooting

### Common Issues

1. **Import Errors**
   ```bash
   # Ensure all dependencies are installed
   pip install -r requirements.txt -r requirements-test.txt
   ```

2. **Path Issues**
   ```python
   # Use absolute paths in tests
   test_path = Path(__file__).parent.parent / "file.py"
   ```

3. **Fixture Not Found**
   ```python
   # Ensure conftest.py is in tests directory
   # Check fixture name matches
   ```

4. **Mock Not Working**
   ```python
   # Use correct patch target
   with patch('module.function') as mock_func:
       # Test code
   ```

## Resources

- [Pytest Documentation](https://docs.pytest.org/)
- [Coverage.py Documentation](https://coverage.readthedocs.io/)
- [Python Testing Best Practices](https://docs.python-guide.org/writing/tests/)
- [Mock Documentation](https://docs.python.org/3/library/unittest.mock.html)

## Contributing

When adding new code:
1. Write tests first (TDD approach)
2. Ensure minimum 80% coverage
3. Run full test suite before committing
4. Update this documentation if needed

## Contact

For questions about testing:
- Review existing tests for examples
- Check pytest documentation
- Create an issue for test-specific questions