@jaguilar87/gaia-ops 2.2.0 → 2.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +137 -1
- package/README.en.md +29 -23
- package/README.md +24 -17
- package/agents/{claude-architect.md → gaia.md} +6 -6
- package/commands/{architect.md → gaia.md} +6 -6
- package/config/AGENTS.md +5 -5
- package/config/agent-catalog.md +14 -14
- package/config/context-contracts.md +4 -4
- package/config/embeddings_info.json +14 -0
- package/config/intent_embeddings.json +2002 -0
- package/config/intent_embeddings.npy +0 -0
- package/index.js +3 -1
- package/package.json +3 -2
- package/speckit/README.en.md +20 -69
- package/templates/CLAUDE.template.md +5 -13
- package/tests/README.en.md +224 -0
- package/tests/README.md +338 -0
- package/tests/fixtures/project-context.aws.json +53 -0
- package/tests/fixtures/project-context.gcp.json +53 -0
- package/tests/integration/RUN_TESTS.md +185 -0
- package/tests/integration/__init__.py +0 -0
- package/tests/integration/test_hooks_integration.py +473 -0
- package/tests/integration/test_hooks_workflow.py +397 -0
- package/tests/permissions-validation/MANUAL_VALIDATION.md +434 -0
- package/tests/permissions-validation/test_permissions_validation.py +527 -0
- package/tests/system/__init__.py +0 -0
- package/tests/system/permissions_helpers.py +318 -0
- package/tests/system/test_agent_definitions.py +166 -0
- package/tests/system/test_configuration_files.py +121 -0
- package/tests/system/test_directory_structure.py +231 -0
- package/tests/system/test_permissions_system.py +1006 -0
- package/tests/tools/__init__.py +0 -0
- package/tests/tools/test_agent_router.py +266 -0
- package/tests/tools/test_clarify_engine.py +413 -0
- package/tests/tools/test_context_provider.py +157 -0
- package/tests/validators/__init__.py +0 -0
- package/tests/validators/test_approval_gate.py +415 -0
- package/tests/validators/test_commit_validator.py +446 -0
- package/tools/context_provider.py +28 -7
- package/tools/generate_embeddings.py +3 -3
- package/tools/semantic_matcher.py +2 -2
package/tests/README.md
ADDED
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
# Claude Agent System - Test Suite
|
|
2
|
+
|
|
3
|
+
Comprehensive test suite for the Claude agent orchestration system.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This test suite validates all components of the agent system including:
|
|
8
|
+
- System structure and file organization
|
|
9
|
+
- Agent definitions and prompts
|
|
10
|
+
- Configuration files
|
|
11
|
+
- Routing and context provisioning
|
|
12
|
+
- Security validators and approval gates
|
|
13
|
+
- Git commit standards enforcement
|
|
14
|
+
|
|
15
|
+
## Test Structure
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
tests/
|
|
19
|
+
├── system/ # System integrity tests
|
|
20
|
+
│ ├── test_directory_structure.py # File/directory existence
|
|
21
|
+
│ ├── test_agent_definitions.py # Agent prompt validation
|
|
22
|
+
│ └── test_configuration_files.py # Config file validation
|
|
23
|
+
│
|
|
24
|
+
├── tools/ # Tool functionality tests
|
|
25
|
+
│ ├── test_agent_router.py # Semantic routing tests
|
|
26
|
+
│ └── test_context_provider.py # Context generation tests
|
|
27
|
+
│
|
|
28
|
+
├── validators/ # Validation logic tests
|
|
29
|
+
│ ├── test_approval_gate.py # Approval workflow tests
|
|
30
|
+
│ └── test_commit_validator.py # Git commit validation tests
|
|
31
|
+
│
|
|
32
|
+
├── integration/ # End-to-end integration tests
|
|
33
|
+
│ └── (future integration tests)
|
|
34
|
+
│
|
|
35
|
+
├── fixtures/ # Test fixtures and data
|
|
36
|
+
│ └── (test data files)
|
|
37
|
+
│
|
|
38
|
+
└── README.md # This file
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Running Tests
|
|
42
|
+
|
|
43
|
+
### Run All Tests
|
|
44
|
+
```bash
|
|
45
|
+
cd /home/jaguilar/aaxis/rnd/repositories/.claude
|
|
46
|
+
python3 -m pytest tests/ -v
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Run Specific Test Categories
|
|
50
|
+
```bash
|
|
51
|
+
# System integrity tests
|
|
52
|
+
python3 -m pytest tests/system/ -v
|
|
53
|
+
|
|
54
|
+
# Tool tests
|
|
55
|
+
python3 -m pytest tests/tools/ -v
|
|
56
|
+
|
|
57
|
+
# Validator tests
|
|
58
|
+
python3 -m pytest tests/validators/ -v
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### Run Individual Test Files
|
|
62
|
+
```bash
|
|
63
|
+
python3 -m pytest tests/system/test_directory_structure.py -v
|
|
64
|
+
python3 -m pytest tests/tools/test_agent_router.py -v
|
|
65
|
+
python3 -m pytest tests/validators/test_commit_validator.py -v
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Run with Coverage
|
|
69
|
+
```bash
|
|
70
|
+
python3 -m pytest tests/ --cov=.claude/tools --cov-report=term
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Test Categories
|
|
74
|
+
|
|
75
|
+
### 1. System Tests (`system/`)
|
|
76
|
+
|
|
77
|
+
**test_directory_structure.py** (~15 tests)
|
|
78
|
+
- Validates all required directories exist
|
|
79
|
+
- Checks file structure integrity
|
|
80
|
+
- Verifies symlinks and permissions
|
|
81
|
+
|
|
82
|
+
**test_agent_definitions.py** (~10 tests)
|
|
83
|
+
- Validates agent prompt structure
|
|
84
|
+
- Checks required sections in agent files
|
|
85
|
+
- Ensures consistency across agents
|
|
86
|
+
|
|
87
|
+
**test_configuration_files.py** (~12 tests)
|
|
88
|
+
- Validates JSON configuration files
|
|
89
|
+
- Checks git_standards.json structure
|
|
90
|
+
- Verifies schema files
|
|
91
|
+
|
|
92
|
+
### 2. Tool Tests (`tools/`)
|
|
93
|
+
|
|
94
|
+
**test_agent_router.py** (~15 tests)
|
|
95
|
+
- Semantic routing accuracy (target: >75%)
|
|
96
|
+
- Intent classification tests
|
|
97
|
+
- Capability validation tests
|
|
98
|
+
- Agent selection logic
|
|
99
|
+
|
|
100
|
+
**test_context_provider.py** (7 tests)
|
|
101
|
+
- Context contract generation
|
|
102
|
+
- Context enrichment logic
|
|
103
|
+
- Token efficiency validation
|
|
104
|
+
|
|
105
|
+
### 3. Validator Tests (`validators/`)
|
|
106
|
+
|
|
107
|
+
**test_approval_gate.py** (17 tests)
|
|
108
|
+
- Approval workflow validation
|
|
109
|
+
- User response processing
|
|
110
|
+
- Audit trail logging
|
|
111
|
+
|
|
112
|
+
**test_commit_validator.py** (31 tests)
|
|
113
|
+
- Conventional Commits validation
|
|
114
|
+
- Forbidden footer detection
|
|
115
|
+
- Commit message format checking
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
### 5. Integration Tests (`integration/`)
|
|
119
|
+
|
|
120
|
+
**test_hooks_integration.py** (~55 tests)
|
|
121
|
+
- Pre-hook validation and blocking (~18 tests)
|
|
122
|
+
- PolicyEngine command classification (~10 tests)
|
|
123
|
+
- GitOps security validation (~9 tests)
|
|
124
|
+
- Settings permission matching (~8 tests)
|
|
125
|
+
- Ask permission triggers (~4 tests)
|
|
126
|
+
- Permission workflow scenarios (~4 tests)
|
|
127
|
+
- Post-hook audit logging (~2 tests)
|
|
128
|
+
|
|
129
|
+
**test_hooks_workflow.py** (~19 tests)
|
|
130
|
+
- Complete validation → execution → audit workflows (~4 tests)
|
|
131
|
+
- Error handling and recovery (~5 tests)
|
|
132
|
+
- Settings merge and resolution (~2 tests)
|
|
133
|
+
- GitOps-specific workflows (~3 tests)
|
|
134
|
+
- Tier escalation scenarios (~3 tests)
|
|
135
|
+
- Audit trail integrity (~2 tests)
|
|
136
|
+
|
|
137
|
+
**Key Features:**
|
|
138
|
+
- End-to-end workflow validation
|
|
139
|
+
- Pre/post hook integration
|
|
140
|
+
- Settings merge and permission resolution
|
|
141
|
+
- GitOps security enforcement
|
|
142
|
+
- Tier-based command classification
|
|
143
|
+
- Audit trail verification
|
|
144
|
+
|
|
145
|
+
**Testing Ask Permissions:**
|
|
146
|
+
```bash
|
|
147
|
+
# Integration tests verify ask permissions are triggered correctly
|
|
148
|
+
python3 -m pytest tests/integration/test_hooks_integration.py::TestAskPermissionTriggers -v
|
|
149
|
+
|
|
150
|
+
# Test complete workflow including settings merge
|
|
151
|
+
python3 -m pytest tests/integration/test_hooks_workflow.py::TestSettingsMergeWorkflow -v
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
**Quick Run:**
|
|
155
|
+
```bash
|
|
156
|
+
# Run all integration tests
|
|
157
|
+
python3 -m pytest tests/integration/ -v
|
|
158
|
+
|
|
159
|
+
# Run specific test class
|
|
160
|
+
python3 -m pytest tests/integration/test_hooks_integration.py::TestPreToolUseHook -v
|
|
161
|
+
|
|
162
|
+
# Run workflow tests
|
|
163
|
+
python3 -m pytest tests/integration/test_hooks_workflow.py -v
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
## Test Metrics
|
|
167
|
+
|
|
168
|
+
### Current Coverage (Updated 2025-11-07)
|
|
169
|
+
- **Total Tests:** 257 tests passing
|
|
170
|
+
- `integration/` - ~60 tests - Hooks workflow and security validation
|
|
171
|
+
- `system/` - ~10 tests - Agent definitions and configuration
|
|
172
|
+
- `tools/` - ~15 tests - Routing and context provisioning
|
|
173
|
+
- `validators/` - ~10 tests - Approval gates and commit validation
|
|
174
|
+
- `permissions-validation/` - ~5 tests - Permission system validation
|
|
175
|
+
- Additional test suites - ~157 tests
|
|
176
|
+
- **Pass Rate:** >95%
|
|
177
|
+
- **Execution Time:** <2 seconds
|
|
178
|
+
- **Routing Accuracy:** 92.7% on semantic routing tests
|
|
179
|
+
|
|
180
|
+
### Run Current Metrics
|
|
181
|
+
```bash
|
|
182
|
+
python3 -m pytest tests/ -v --tb=short
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
## Key Test Features
|
|
186
|
+
|
|
187
|
+
### Semantic Routing Tests
|
|
188
|
+
- Validates intent classification accuracy
|
|
189
|
+
- Tests capability validator logic
|
|
190
|
+
- Ensures proper agent selection
|
|
191
|
+
- Golden set accuracy benchmarking
|
|
192
|
+
|
|
193
|
+
### Commit Validation Tests
|
|
194
|
+
- Enforces Conventional Commits format
|
|
195
|
+
- Blocks forbidden footers (Claude signatures)
|
|
196
|
+
- Validates subject line rules
|
|
197
|
+
- Tests type and scope validation
|
|
198
|
+
|
|
199
|
+
### Approval Gate Tests
|
|
200
|
+
- Validates approval workflow
|
|
201
|
+
- Tests summary generation
|
|
202
|
+
- Ensures audit logging
|
|
203
|
+
- Verifies user response handling
|
|
204
|
+
|
|
205
|
+
## Test Dependencies
|
|
206
|
+
|
|
207
|
+
Required packages:
|
|
208
|
+
```bash
|
|
209
|
+
pip install pytest pytest-cov
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
Optional (for schema validation):
|
|
213
|
+
```bash
|
|
214
|
+
pip install jsonschema
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
## Writing New Tests
|
|
218
|
+
|
|
219
|
+
### Test File Template
|
|
220
|
+
```python
|
|
221
|
+
"""
|
|
222
|
+
Test suite for [component name]
|
|
223
|
+
Description of what this test file validates
|
|
224
|
+
"""
|
|
225
|
+
|
|
226
|
+
import pytest
|
|
227
|
+
from pathlib import Path
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
class TestComponentName:
|
|
231
|
+
"""Test suite for specific component"""
|
|
232
|
+
|
|
233
|
+
@pytest.fixture
|
|
234
|
+
def setup(self):
|
|
235
|
+
"""Setup test fixtures"""
|
|
236
|
+
return {}
|
|
237
|
+
|
|
238
|
+
def test_feature_works(self, setup):
|
|
239
|
+
"""Test description"""
|
|
240
|
+
assert True, "Failure message"
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
if __name__ == "__main__":
|
|
244
|
+
pytest.main([__file__, "-v"])
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
### Best Practices
|
|
248
|
+
1. Use descriptive test names (test_what_it_validates)
|
|
249
|
+
2. Include docstrings for all test classes and methods
|
|
250
|
+
3. Use fixtures for common setup
|
|
251
|
+
4. Assert with clear failure messages
|
|
252
|
+
5. Keep tests independent and isolated
|
|
253
|
+
|
|
254
|
+
## Continuous Integration
|
|
255
|
+
|
|
256
|
+
These tests should be run:
|
|
257
|
+
- Before committing changes to agent system
|
|
258
|
+
- After modifying routing logic
|
|
259
|
+
- When updating configuration files
|
|
260
|
+
- Before deploying to production
|
|
261
|
+
|
|
262
|
+
## Troubleshooting
|
|
263
|
+
|
|
264
|
+
### Import Errors
|
|
265
|
+
If you see import errors, ensure you're running from the correct directory:
|
|
266
|
+
```bash
|
|
267
|
+
cd /home/jaguilar/aaxis/rnd/repositories/.claude
|
|
268
|
+
python3 -m pytest tests/ -v
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
### Path Issues
|
|
272
|
+
Tests use `Path(__file__).resolve().parents[N]` to find system directories.
|
|
273
|
+
Ensure test files maintain the correct directory depth.
|
|
274
|
+
|
|
275
|
+
### Fixture Not Found
|
|
276
|
+
If a fixture is not found, check that:
|
|
277
|
+
1. The fixture is defined in the same test class
|
|
278
|
+
2. The fixture name matches the parameter name
|
|
279
|
+
3. pytest is discovering the test file correctly
|
|
280
|
+
|
|
281
|
+
## Contributing
|
|
282
|
+
|
|
283
|
+
When adding new tests:
|
|
284
|
+
1. Place in appropriate category directory
|
|
285
|
+
2. Follow naming convention: `test_*.py`
|
|
286
|
+
3. Update this README with test count
|
|
287
|
+
4. Ensure all tests pass before committing
|
|
288
|
+
|
|
289
|
+
## References
|
|
290
|
+
|
|
291
|
+
- Agent Router: `.claude/tools/agent_router.py`
|
|
292
|
+
- Context Provider: `.claude/tools/context_provider.py`
|
|
293
|
+
- Commit Validator: `.claude/tools/commit_validator.py`
|
|
294
|
+
- Approval Gate: `.claude/tools/approval_gate.py`
|
|
295
|
+
- Agent Definitions: `.claude/agents/*.md`
|
|
296
|
+
- Configuration: `.claude/config/*.json`
|
|
297
|
+
|
|
298
|
+
---
|
|
299
|
+
|
|
300
|
+
Last Updated: 2025-11-05
|
|
301
|
+
Total Tests: ~212 (includes 53 permissions + 74 integration tests)
|
|
302
|
+
|
|
303
|
+
### 4. Permissions Tests (`system/`)
|
|
304
|
+
|
|
305
|
+
**test_permissions_system.py** (53 tests)
|
|
306
|
+
- Settings file loading and merging (10 tests)
|
|
307
|
+
- Permission priority resolution: deny > ask > allow (12 tests)
|
|
308
|
+
- Execution standards enforcement (8 tests)
|
|
309
|
+
- Security tier validation (T0-T3) (15 tests)
|
|
310
|
+
- Production vs development mode (8 tests)
|
|
311
|
+
|
|
312
|
+
**Key Features:**
|
|
313
|
+
- Validates settings merge logic (project + shared)
|
|
314
|
+
- Tests permission precedence rules
|
|
315
|
+
- Validates tier definitions and enforcement
|
|
316
|
+
- Tests environment-specific behavior
|
|
317
|
+
|
|
318
|
+
**Quick Run:**
|
|
319
|
+
```bash
|
|
320
|
+
# From tests directory
|
|
321
|
+
./run_permissions_tests.sh
|
|
322
|
+
|
|
323
|
+
# Or directly with pytest
|
|
324
|
+
python3 -m pytest tests/system/test_permissions_system.py -v
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
**Helper Module:** `permissions_helpers.py`
|
|
328
|
+
- Settings loading utilities
|
|
329
|
+
- Merge logic implementation
|
|
330
|
+
- Environment detection
|
|
331
|
+
- Permission level checking
|
|
332
|
+
|
|
333
|
+
**Documentation:** See `PERMISSIONS_MIGRATION.md` for:
|
|
334
|
+
- Migration from manual to automated testing
|
|
335
|
+
- Test suite structure and coverage
|
|
336
|
+
- CI/CD integration guide
|
|
337
|
+
- Troubleshooting and best practices
|
|
338
|
+
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"metadata": {
|
|
3
|
+
"version": "1.0",
|
|
4
|
+
"last_updated": "2025-11-10T10:00:00Z",
|
|
5
|
+
"cloud_provider": "aws",
|
|
6
|
+
"aws_account": "123456789012",
|
|
7
|
+
"environment": "non-prod",
|
|
8
|
+
"primary_region": "us-east-1"
|
|
9
|
+
},
|
|
10
|
+
"paths": {
|
|
11
|
+
"gitops": "./gitops",
|
|
12
|
+
"terraform": "./terraform",
|
|
13
|
+
"app_services": "./app-services"
|
|
14
|
+
},
|
|
15
|
+
"sections": {
|
|
16
|
+
"project_details": {
|
|
17
|
+
"account_id": "123456789012",
|
|
18
|
+
"region": "us-east-1",
|
|
19
|
+
"environment": "non-prod",
|
|
20
|
+
"cluster_name": "test-eks-cluster",
|
|
21
|
+
"cloud_provider": "aws"
|
|
22
|
+
},
|
|
23
|
+
"terraform_infrastructure": {
|
|
24
|
+
"layout": {
|
|
25
|
+
"base_path": "./terraform"
|
|
26
|
+
},
|
|
27
|
+
"provider_credentials": {
|
|
28
|
+
"aws": {
|
|
29
|
+
"account_id": "123456789012",
|
|
30
|
+
"region": "us-east-1"
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"gitops_configuration": {
|
|
35
|
+
"repository": {
|
|
36
|
+
"path": "./gitops"
|
|
37
|
+
},
|
|
38
|
+
"flux_details": {
|
|
39
|
+
"version": "2.1.0",
|
|
40
|
+
"namespaces": ["flux-system"]
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"cluster_details": {
|
|
44
|
+
"namespaces": ["default", "test-namespace"]
|
|
45
|
+
},
|
|
46
|
+
"operational_guidelines": {
|
|
47
|
+
"commit_standards": {
|
|
48
|
+
"validation_required": true,
|
|
49
|
+
"config_path": ".claude/config/git_standards.json"
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"metadata": {
|
|
3
|
+
"version": "1.0",
|
|
4
|
+
"last_updated": "2025-11-10T10:00:00Z",
|
|
5
|
+
"cloud_provider": "gcp",
|
|
6
|
+
"project_id": "test-gcp-project",
|
|
7
|
+
"environment": "non-prod",
|
|
8
|
+
"primary_region": "us-central1"
|
|
9
|
+
},
|
|
10
|
+
"paths": {
|
|
11
|
+
"gitops": "./gitops",
|
|
12
|
+
"terraform": "./terraform",
|
|
13
|
+
"app_services": "./app-services"
|
|
14
|
+
},
|
|
15
|
+
"sections": {
|
|
16
|
+
"project_details": {
|
|
17
|
+
"project_id": "test-gcp-project",
|
|
18
|
+
"region": "us-central1",
|
|
19
|
+
"environment": "non-prod",
|
|
20
|
+
"cluster_name": "test-gke-cluster",
|
|
21
|
+
"cloud_provider": "gcp"
|
|
22
|
+
},
|
|
23
|
+
"terraform_infrastructure": {
|
|
24
|
+
"layout": {
|
|
25
|
+
"base_path": "./terraform"
|
|
26
|
+
},
|
|
27
|
+
"provider_credentials": {
|
|
28
|
+
"gcp": {
|
|
29
|
+
"project": "test-gcp-project",
|
|
30
|
+
"region": "us-central1"
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"gitops_configuration": {
|
|
35
|
+
"repository": {
|
|
36
|
+
"path": "./gitops"
|
|
37
|
+
},
|
|
38
|
+
"flux_details": {
|
|
39
|
+
"version": "2.1.0",
|
|
40
|
+
"namespaces": ["flux-system"]
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"cluster_details": {
|
|
44
|
+
"namespaces": ["default", "test-namespace"]
|
|
45
|
+
},
|
|
46
|
+
"operational_guidelines": {
|
|
47
|
+
"commit_standards": {
|
|
48
|
+
"validation_required": true,
|
|
49
|
+
"config_path": ".claude/config/git_standards.json"
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
# Integration Tests - Quick Reference
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
This directory contains **75 integration tests** validating the hooks and permissions system.
|
|
6
|
+
|
|
7
|
+
- **test_hooks_integration.py**: 55 tests for pre/post hooks, policy engine, permissions
|
|
8
|
+
- **test_hooks_workflow.py**: 20 tests for complete workflows and error handling
|
|
9
|
+
|
|
10
|
+
## Quick Commands
|
|
11
|
+
|
|
12
|
+
### Run All Integration Tests
|
|
13
|
+
```bash
|
|
14
|
+
cd /home/jaguilar/aaxis/rnd/repositories/ops/.claude-shared
|
|
15
|
+
python3 -m pytest tests/integration/ -v
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
### Run Specific Test File
|
|
19
|
+
```bash
|
|
20
|
+
# Pre/post hook tests
|
|
21
|
+
python3 -m pytest tests/integration/test_hooks_integration.py -v
|
|
22
|
+
|
|
23
|
+
# Workflow tests
|
|
24
|
+
python3 -m pytest tests/integration/test_hooks_workflow.py -v
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### Run Specific Test Class
|
|
28
|
+
```bash
|
|
29
|
+
# Pre-hook validation tests
|
|
30
|
+
python3 -m pytest tests/integration/test_hooks_integration.py::TestPreToolUseHook -v
|
|
31
|
+
|
|
32
|
+
# Policy engine tests
|
|
33
|
+
python3 -m pytest tests/integration/test_hooks_integration.py::TestPolicyEngine -v
|
|
34
|
+
|
|
35
|
+
# GitOps security tests
|
|
36
|
+
python3 -m pytest tests/integration/test_hooks_integration.py::TestGitOpsSecurityValidation -v
|
|
37
|
+
|
|
38
|
+
# Settings merge tests
|
|
39
|
+
python3 -m pytest tests/integration/test_hooks_workflow.py::TestSettingsMergeWorkflow -v
|
|
40
|
+
|
|
41
|
+
# Complete workflow tests
|
|
42
|
+
python3 -m pytest tests/integration/test_hooks_workflow.py::TestCompleteWorkflow -v
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Run Specific Test
|
|
46
|
+
```bash
|
|
47
|
+
# Single test
|
|
48
|
+
python3 -m pytest tests/integration/test_hooks_integration.py::TestPreToolUseHook::test_hook_allows_read_operations -v
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Run with Different Output Formats
|
|
52
|
+
```bash
|
|
53
|
+
# Short traceback
|
|
54
|
+
python3 -m pytest tests/integration/ -v --tb=short
|
|
55
|
+
|
|
56
|
+
# No traceback (summary only)
|
|
57
|
+
python3 -m pytest tests/integration/ -v --tb=no
|
|
58
|
+
|
|
59
|
+
# Show print statements
|
|
60
|
+
python3 -m pytest tests/integration/ -v -s
|
|
61
|
+
|
|
62
|
+
# Stop on first failure
|
|
63
|
+
python3 -m pytest tests/integration/ -v -x
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Test Categories
|
|
67
|
+
|
|
68
|
+
### Pre-Tool Use Hook Tests (18 tests)
|
|
69
|
+
- Read operations allowed
|
|
70
|
+
- Write operations blocked
|
|
71
|
+
- Dry-run operations allowed
|
|
72
|
+
- GitOps security enforcement
|
|
73
|
+
- Error message quality
|
|
74
|
+
|
|
75
|
+
### Policy Engine Tests (10 tests)
|
|
76
|
+
- Tier classification (T0-T3)
|
|
77
|
+
- Command validation
|
|
78
|
+
- Invalid input handling
|
|
79
|
+
- Credential requirement detection
|
|
80
|
+
|
|
81
|
+
### GitOps Security Tests (9 tests)
|
|
82
|
+
- Kubectl read/write validation
|
|
83
|
+
- Helm operations
|
|
84
|
+
- Flux reconciliation blocking
|
|
85
|
+
- Dry-run support
|
|
86
|
+
|
|
87
|
+
### Settings Permission Tests (8 tests)
|
|
88
|
+
- Priority rules (deny > ask > allow)
|
|
89
|
+
- Pattern matching (wildcards, regex)
|
|
90
|
+
- Default deny behavior
|
|
91
|
+
- Missing settings handling
|
|
92
|
+
|
|
93
|
+
### Ask Permission Tests (4 tests)
|
|
94
|
+
- Terraform apply triggers ask
|
|
95
|
+
- Git push triggers ask
|
|
96
|
+
- Kubectl apply triggers ask
|
|
97
|
+
- Other commands default deny
|
|
98
|
+
|
|
99
|
+
### Workflow Tests (20 tests)
|
|
100
|
+
- Complete validation → execution → audit flow
|
|
101
|
+
- Error handling and recovery
|
|
102
|
+
- Settings merge and precedence
|
|
103
|
+
- Tier escalation scenarios
|
|
104
|
+
- Audit trail integrity
|
|
105
|
+
|
|
106
|
+
## Expected Results
|
|
107
|
+
|
|
108
|
+
```
|
|
109
|
+
========================= 75 passed in 0.5s =========================
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
- **Pass rate**: 100% (75/75)
|
|
113
|
+
- **Execution time**: < 0.5 seconds
|
|
114
|
+
- **No failures expected**
|
|
115
|
+
|
|
116
|
+
## Troubleshooting
|
|
117
|
+
|
|
118
|
+
### Import Errors
|
|
119
|
+
If you see import errors, ensure you're running from the correct directory:
|
|
120
|
+
```bash
|
|
121
|
+
cd /home/jaguilar/aaxis/rnd/repositories/ops/.claude-shared
|
|
122
|
+
python3 -m pytest tests/integration/ -v
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### Missing Hooks
|
|
126
|
+
Some tests may be skipped if hooks are not available:
|
|
127
|
+
```
|
|
128
|
+
⚠️ pre_tool_use hook not available
|
|
129
|
+
⚠️ post_tool_use hook not available
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
This is expected if running outside the .claude-shared environment.
|
|
133
|
+
|
|
134
|
+
### Test Failures
|
|
135
|
+
If tests fail, check:
|
|
136
|
+
1. Hooks are in correct location: `hooks/pre_tool_use.py` and `hooks/post_tool_use.py`
|
|
137
|
+
2. Settings helpers are importable: `tests/system/permissions_helpers.py`
|
|
138
|
+
3. Python version is 3.8+ (tested with 3.12.7)
|
|
139
|
+
|
|
140
|
+
## What's Being Tested
|
|
141
|
+
|
|
142
|
+
### Pre-Hook Validation
|
|
143
|
+
- ✅ Blocks T3 operations (apply, delete, push)
|
|
144
|
+
- ✅ Allows T0 operations (get, describe, list)
|
|
145
|
+
- ✅ Allows T1 operations (validate, plan, template)
|
|
146
|
+
- ✅ Allows T2 operations (--dry-run)
|
|
147
|
+
- ✅ Provides helpful error messages
|
|
148
|
+
|
|
149
|
+
### Post-Hook Audit
|
|
150
|
+
- ✅ Logs all command executions
|
|
151
|
+
- ✅ Records metrics (duration, success/failure)
|
|
152
|
+
- ✅ Handles large output gracefully
|
|
153
|
+
- ✅ Creates necessary directories
|
|
154
|
+
|
|
155
|
+
### Settings System
|
|
156
|
+
- ✅ Merges project + shared settings
|
|
157
|
+
- ✅ Respects precedence rules
|
|
158
|
+
- ✅ Resolves permissions correctly
|
|
159
|
+
- ✅ Handles missing configurations
|
|
160
|
+
|
|
161
|
+
### Complete Workflows
|
|
162
|
+
- ✅ Pre-hook → Command → Post-hook flow
|
|
163
|
+
- ✅ Blocked commands stop at pre-hook
|
|
164
|
+
- ✅ Validation workflows pass through
|
|
165
|
+
- ✅ Tier escalation is blocked
|
|
166
|
+
|
|
167
|
+
## CI/CD Integration
|
|
168
|
+
|
|
169
|
+
To run in CI/CD pipelines:
|
|
170
|
+
|
|
171
|
+
```yaml
|
|
172
|
+
test-integration:
|
|
173
|
+
script:
|
|
174
|
+
- cd ops/.claude-shared
|
|
175
|
+
- python3 -m pytest tests/integration/ -v --tb=short --junitxml=integration-results.xml
|
|
176
|
+
artifacts:
|
|
177
|
+
reports:
|
|
178
|
+
junit: ops/.claude-shared/integration-results.xml
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
---
|
|
182
|
+
|
|
183
|
+
**Last Updated**: 2025-11-05
|
|
184
|
+
**Total Tests**: 75
|
|
185
|
+
**Pass Rate**: 100%
|
|
File without changes
|