ratatui-testlib 0.1.0

Integration testing library for terminal user interface applications with Sixel and Bevy support
Documentation
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
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
# CI/CD Maintenance Guide

## Overview

The ratatui-testlib project uses GitHub Actions for continuous integration and deployment. This guide covers how to maintain and troubleshoot the CI/CD pipeline.

## CI/CD Architecture

### Workflow Files

Located in `.github/workflows/`:

1. **ci.yml** - Main CI pipeline (runs on every push/PR)
2. **release.yml** - Release automation (runs on version tags)
3. **benchmark.yml** - Performance benchmarking
4. **docs.yml** - Documentation validation

### CI Pipeline Stages

```
┌─────────────┐
│ Quick Check │ (fmt, clippy)
└──────┬──────┘
       ├──────────────────────────────────┐
       │                                  │
┌──────▼──────┐                  ┌────────▼────────┐
│ Test Suite  │                  │ Feature Tests   │
│ (stable/beta)│                  │ (all combos)    │
└──────┬──────┘                  └────────┬────────┘
       │                                  │
       ├──────────┬──────────┬───────────┼────────┐
       │          │          │           │        │
┌──────▼──────┐ ┌▼────────┐ ┌▼────────┐ ┌▼─────┐ ┌▼────────┐
│  Coverage   │ │ Security│ │Examples │ │ MSRV │ │  Docs   │
└─────────────┘ └─────────┘ └─────────┘ └──────┘ └─────────┘
       │          │          │           │        │
       └──────────┴──────────┴───────────┴────────┘
              ┌───────▼────────┐
              │  CI Success    │
              └────────────────┘
```

## Job Descriptions

### 1. Quick Check (check)

**Purpose**: Fast feedback on formatting and linting issues

**Runs**:
- `cargo fmt --check` - Ensures code is properly formatted
- `cargo clippy -- -D warnings` - Catches common mistakes and anti-patterns

**Caching**: Registry and dependency cache for fast execution

**Failure**: Indicates code style violations or clippy warnings

### 2. Test Suite (test)

**Purpose**: Run comprehensive test suite on multiple Rust versions

**Matrix**: `[stable, beta]`

**Runs**:
- `cargo test --lib` - Library tests
- `cargo test --test '*'` - Integration tests
- `cargo test --doc` - Documentation tests

**Headless Configuration**: Runs on Ubuntu without X11/Wayland display server

**Failure**: Test failures or panics

### 3. Feature Flag Tests (feature-tests)

**Purpose**: Ensure all feature combinations compile and work

**Matrix Tests**:
- `--no-default-features` - Minimal build
- `--all-features` - Full build
- Individual features: `async-tokio`, `bevy`, `bevy-ratatui`, `ratatui-helpers`, `sixel`, `snapshot-insta`

**Failure**: Feature combination incompatibility or missing conditional compilation

### 4. Code Coverage (coverage)

**Purpose**: Track test coverage and upload to Codecov

**Tool**: `cargo-tarpaulin`

**Configuration**:
- Timeout: 300 seconds
- Output: XML (Cobertura format)
- Workspace: All packages

**Artifacts**: Coverage reports uploaded to Codecov and GitHub Actions

**Failure**: Usually indicates tarpaulin installation or execution issues

### 5. Security Audit (security-audit)

**Purpose**: Check for known vulnerabilities in dependencies

**Tool**: `cargo-audit`

**Runs**: On every CI run

**Failure**: Known vulnerabilities in dependencies (check RustSec Advisory Database)

### 6. Build Examples (examples)

**Purpose**: Ensure all examples compile

**Runs**: `cargo build --examples --all-features`

**Failure**: Example compilation errors

### 7. MSRV Check (msrv)

**Purpose**: Verify Minimum Supported Rust Version (1.70)

**Runs**: `cargo check --all-features`

**Failure**: Code uses features from newer Rust versions

## Caching Strategy

### Cache Keys

```yaml
key: ${{ runner.os }}-${{ job }}-cargo-${{ hashFiles('**/Cargo.lock') }}
```

### Cached Paths

1. `~/.cargo/registry/index` - Crate registry index
2. `~/.cargo/registry/cache` - Downloaded crate archives
3. `~/.cargo/git/db` - Git dependencies
4. `target/` - Build artifacts

### Cache Benefits

- Reduces CI time from ~10-15 minutes to ~3-5 minutes
- Reduces network bandwidth usage
- Speeds up dependency compilation

## Dependabot Configuration

Located in `.github/dependabot.yml`

### Update Schedule

- **GitHub Actions**: Weekly (Mondays at 09:00)
- **Cargo Dependencies**: Weekly (Mondays at 09:00)

### Grouping Strategy

Dependencies are grouped by ecosystem:
- `tokio` group: All tokio-related crates
- `bevy` group: All bevy-related crates
- `ratatui` group: ratatui and crossterm
- `testing` group: insta, expect-test
- `development-dependencies`: All dev dependencies

### Pull Request Limits

- GitHub Actions: 5 concurrent PRs
- Cargo: 10 concurrent PRs

## Maintenance Tasks

### Weekly Tasks

1. **Review Dependabot PRs**
   ```bash
   # Check for open dependabot PRs
   gh pr list --label dependencies
   ```

2. **Check CI Success Rate**
   ```bash
   # View recent workflow runs
   gh run list --workflow=ci.yml --limit 20
   ```

3. **Review Coverage Trends**
   - Visit Codecov dashboard
   - Ensure coverage stays above 70% (MVP goal)

### Monthly Tasks

1. **Audit Dependencies**
   ```bash
   cargo audit
   cargo outdated
   ```

2. **Review Cache Effectiveness**
   - Check average CI run times
   - Verify cache hit rates in Actions logs

3. **Update MSRV** (if needed)
   - Test on new Rust versions
   - Update MSRV in workflow and Cargo.toml

### Quarterly Tasks

1. **Benchmark Performance**
   ```bash
   cargo criterion --all-features
   ```

2. **Review and Update CI Pipeline**
   - Check for new GitHub Actions versions
   - Evaluate new CI tools and practices

3. **Security Review**
   - Review all dependencies for security advisories
   - Update to latest patch versions

## Troubleshooting

### Common Issues

#### 1. Flaky Tests

**Symptoms**: Tests pass locally but fail in CI

**Causes**:
- Timing issues in headless environment
- Race conditions
- Platform-specific behavior

**Solutions**:
```rust
// Increase timeout for CI
#[cfg(test)]
const TIMEOUT: Duration = if cfg!(ci) {
    Duration::from_secs(10)
} else {
    Duration::from_secs(5)
};
```

#### 2. Cache Invalidation

**Symptoms**: CI runs slower than expected

**Causes**:
- Cargo.lock changed
- Cache eviction
- Cache corruption

**Solutions**:
```bash
# Manually clear cache in GitHub Actions settings
# Or update cache key in workflow file
```

#### 3. Tarpaulin Failures

**Symptoms**: Coverage job fails or times out

**Causes**:
- Tests hanging in tarpaulin
- Memory issues
- Timeout too short

**Solutions**:
```yaml
# Increase timeout
cargo tarpaulin --timeout 600

# Exclude problematic tests
cargo tarpaulin --exclude-files tests/flaky/*
```

#### 4. Feature Flag Conflicts

**Symptoms**: Feature combination tests fail

**Causes**:
- Missing `#[cfg(feature = "...")]` guards
- Feature dependencies not declared
- Incompatible features

**Solutions**:
```toml
# In Cargo.toml, declare feature dependencies
[features]
bevy-ratatui = ["bevy", "ratatui"]
```

### Debug Failed CI Runs

1. **View Logs**
   ```bash
   gh run view <run-id> --log
   ```

2. **Download Artifacts**
   ```bash
   gh run download <run-id>
   ```

3. **Reproduce Locally**
   ```bash
   # Use act to run GitHub Actions locally
   act -j test
   ```

4. **Check Specific Job**
   ```bash
   gh run view <run-id> --job <job-id>
   ```

## Performance Optimization

### Current Benchmarks

- Quick Check: ~2-3 minutes
- Test Suite: ~5-7 minutes per Rust version
- Feature Tests: ~3-5 minutes per combination
- Coverage: ~8-10 minutes
- **Total CI Time**: ~15-20 minutes (with caching)

### Optimization Strategies

1. **Parallel Execution**
   - Jobs run in parallel where possible
   - Test matrix parallelizes across Rust versions

2. **Incremental Compilation**
   - Cached build artifacts reduce rebuild times
   - Use `cargo build --release` only when needed

3. **Selective Testing**
   ```yaml
   # Only run expensive tests on main branch
   if: github.ref == 'refs/heads/main'
   ```

4. **Smart Caching**
   ```yaml
   # Cache by job type for better hit rates
   key: ${{ runner.os }}-${{ matrix.job }}-cargo-${{ hashFiles('**/Cargo.lock') }}
   ```

## Security Best Practices

### Secrets Management

Required secrets in repository settings:
- `CODECOV_TOKEN` - For coverage uploads
- `CARGO_REGISTRY_TOKEN` - For crates.io publishing

### Permissions

Workflows use minimal permissions:
```yaml
permissions:
  contents: read
  pull-requests: write  # For PR comments
```

### Dependency Auditing

Automated via:
1. Dependabot security updates (enabled)
2. `cargo audit` in CI
3. Manual quarterly reviews

## Monitoring and Alerts

### GitHub Actions Notifications

Configure in repository settings:
- Email notifications for failed runs
- Slack/Discord webhooks for CI status

### Codecov Integration

- Coverage decrease threshold: 5%
- Comment on PRs with coverage changes
- Fail CI if coverage drops significantly

### Metrics to Track

1. **CI Success Rate**: Should be >95%
2. **Average CI Duration**: Target <10 minutes
3. **Test Coverage**: MVP goal >70%, target >80%
4. **Cache Hit Rate**: Should be >80%
5. **Dependabot PR Merge Rate**: Should be >90%

## Future Enhancements

### Planned Improvements

1. **Cross-Platform Testing** (Phase 7+)
   - macOS runners
   - Windows runners
   - Multi-platform matrix

2. **Performance Regression Detection**
   - Automated benchmark comparison
   - Alert on >10% performance degradation

3. **Nightly Builds**
   - Test against Rust nightly
   - Early warning for upcoming breaking changes

4. **Deploy Previews**
   - PR preview environments
   - Documentation previews

5. **Advanced Coverage**
   - Branch coverage
   - Line-by-line coverage in PR comments

6. **Canary Deployments**
   - Gradual rollout to crates.io
   - Beta channel for early adopters

## FAQ

### Q: Why does CI take longer than local tests?

**A**: CI runs more comprehensive checks:
- Multiple Rust versions
- All feature combinations
- Code coverage
- Security audits
- Documentation builds

### Q: How do I skip CI for a commit?

**A**: Add `[skip ci]` to commit message (use sparingly):
```bash
git commit -m "docs: Update README [skip ci]"
```

### Q: Can I run CI locally?

**A**: Yes, using `act`:
```bash
# Install act
brew install act

# Run CI locally
act -j test
```

### Q: How do I update the MSRV?

**A**:
1. Test on new version locally
2. Update `rust-version` in Cargo.toml
3. Update toolchain in `.github/workflows/ci.yml`
4. Document in CHANGELOG.md

### Q: Why are feature tests failing?

**A**: Usually due to:
- Missing feature guards in code
- Undeclared feature dependencies
- Incompatible feature combinations

Check the specific feature matrix job logs for details.

## Resources

- [GitHub Actions Documentation]https://docs.github.com/en/actions
- [cargo-tarpaulin]https://github.com/xd009642/tarpaulin
- [cargo-audit]https://github.com/RustSec/rustsec/tree/main/cargo-audit
- [Codecov]https://docs.codecov.com/
- [Dependabot]https://docs.github.com/en/code-security/dependabot

## Support

For CI/CD issues:
1. Check this guide
2. Review workflow logs
3. Search existing issues
4. Open a new issue with `[CI]` prefix

---

**Last Updated**: 2025-11-19
**Maintainer**: Raibid Labs
**Status**: Active