#205 Apps: Implement testing framework and sandbox
Description
Edit## Parent Epic: #195
## Description
Create testing framework for app developers to test apps before deployment.
## Location
engine/apps/testing/sandbox.py, engine/apps/testing/mock_context.py
## AppSandbox Class
### Constructor
- app_class: App class to test
- Creates isolated test environment
### test_action() Method
```python
def test_action(
action_name: str,
config: dict | None = None,
secrets: dict | None = None,
**kwargs
) -> dict:
'''
Returns:
{
'result': <action result>,
'events': [<emitted events>],
'logs': [<log entries>],
'checkpoints': {<checkpoint data>},
'http_requests': [<made requests>],
}
'''
```
### Features
- Mock HTTP responses
- Capture emitted events
- Capture log entries
- Capture checkpoints
- Simulate replays (test idempotency)
- Timeout testing
## MockAppContext Class
### Captured Data
- events: list[dict]
- logs: list[dict]
- checkpoints: dict[str, Any]
- http_requests: list[dict]
- state: dict[str, Any]
### Mock HTTP
```python
sandbox = AppSandbox(MyApp)
sandbox.mock_http(
url='https://api.example.com/*',
response={'status': 200, 'json': {'ok': True}}
)
```
### Simulate Replay
```python
sandbox.set_checkpoint('step1', {'result': 'cached'})
result = sandbox.test_action('my_action', ...)
# Verify checkpoint was returned, not re-executed
```
## API Endpoint
POST /api/v1/apps/{app_id}/test
- Test app action in sandbox
- Body: {action_name, config, secrets, kwargs, mock_http}
- Permission: developer
- Returns sandbox result
## Testing
- Test sandbox isolation
- Test mock HTTP
- Test checkpoint replay
- Test event capture
- Test log capture
Comments
Loading comments...
Context
Loading context...
Audit History
View AllLoading audit history...