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
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
# ratatui-testlib Implementation Roadmap

## 🎉 Phase 1 Complete! Ready for Phase 2

**Current Status**: Phase 1 (100%) → Starting Phase 2

**Achievement**: Core PTY harness with screen capture and cursor tracking fully operational

**Decision**: Successfully switched from vt100 to **vtparse** for terminal emulation

**Reason**: vtparse provides lightweight VT100 parsing with DCS callbacks for Sixel support

**Impact**: ✅ Phase 3 (Sixel) ready for implementation. Solid foundation established.

**Phase 1 Summary**:
- ✅ 47/47 tests passing
- ✅ PTY management with portable-pty
- ✅ Screen state capture with vtparse
- ✅ Cursor position tracking
- ✅ Sixel infrastructure (DCS callbacks implemented)
- ✅ Complete API documentation
- ✅ CI/CD operational

---

## Project Vision

Create a Rust library for integration testing of terminal user interface applications, with first-class support for Ratatui, Bevy ECS integration, and graphics protocols like Sixel. **Primary goal: Enable comprehensive testing for the dgx-pixels project.**

## MVP Definition (Based on dgx-pixels Requirements)

The **Minimum Viable Product** must support the dgx-pixels project's testing needs:

1. ✅ Headless terminal emulation (CI/CD compatible)
2. ✅ Sixel graphics position verification and bounds checking (infrastructure ready)
3. ✅ Sixel clearing validation on screen transitions (infrastructure ready)
4. ⏳ Bevy ECS integration (query entities, control update cycles)
5. ⏳ bevy_ratatui plugin support
6. ✅ Text input and cursor position testing (basic - enhanced in Phase 2)
7. ⏳ Tokio async runtime support (Phase 2)
8. ✅ Runs in GitHub Actions without X11/Wayland

**Success Criteria**: Can detect and prevent the Sixel positioning and persistence bugs that occurred in dgx-pixels development.

## Phases

### Phase 0: Foundation ✅

**Goal**: Establish project structure, research, and documentation

**Status**: ✅ Complete (100%)

**Deliverables**:
- [x] Repository initialization
- [x] Comprehensive research documentation
- [x] Architecture design
- [x] Gap analysis of existing solutions
- [x] Testing approaches documentation
- [x] dgx-pixels requirements analysis
- [x] This roadmap

---

### Phase 1: Core PTY Harness ✅

**Goal**: Basic PTY-based test harness with screen capture and cursor tracking

**Priority**: P0 (Critical - MVP Blocker)

**Status**: ✅ **COMPLETE (100%)** - 2025-11-20

**Dependencies**: None

**Completed Tasks**:

1. **Project Setup**   - [x] Initialize Cargo workspace
   - [x] Set up CI/CD (GitHub Actions) with headless Linux runner
   - [x] Configure linting (clippy, rustfmt)
   - [x] Project structure and dependencies

2. **PTY Management Layer**   - [x] Integrate `portable-pty` crate
   - [x] Implement `TestTerminal` wrapper
   - [x] Handle PTY creation and lifecycle
   - [x] Implement process spawning (for external binaries)
   - [x] Add read/write operations with buffering
   - [x] Test on Linux (primary CI platform)

3. **Terminal Emulation Layer**   - [x] ~~Integrate `vt100` crate~~ **Use `vtparse` crate instead**
   - [x] **Validate Sixel support** - vtparse has DCS callbacks
   - [x] Implement `ScreenState` wrapper using vtparse VTParser
   - [x] Feed PTY output to vtparse parser with VTActor callbacks
   - [x] Expose screen query methods (`contents()`, `text_at()`, `row_contents()`)
   - [x] **Track cursor position via VTActor callbacks**
   - [x] **Implement DCS hook for Sixel detection** (infrastructure ready)

4. **Basic Test Harness**   - [x] Implement `TuiTestHarness` struct
   - [x] Add `new(width, height)` constructor
   - [x] Add `spawn(Command)` method for external processes
   - [x] Add `send_text(str)` method
   - [x] Add wait methods with polling (`wait_for`, `wait_for_text`)
   - [x] Add `screen_contents()` method
   - [x] **Add `cursor_position()` method**
   - [x] Implement error types (`TermTestError`)

5. **Testing & Documentation**   - [x] Write unit tests for PTY layer (100% core coverage)
   - [x] Write integration tests for harness (47 tests passing)
   - [x] Create basic usage examples (5 examples)
   - [x] Write API documentation (complete rustdoc)
   - [x] Test on Linux (primary platform)

**Success Criteria** (All Met):
- ✅ Can spawn a simple TUI app in PTY
- ✅ Can send text input
- ✅ Can capture screen contents and cursor position
- ✅ Works on Linux (CI validated)
- ✅ Basic examples run successfully
- ✅ CI/CD runs tests headlessly
- ✅ 47/47 tests passing

**Critical Decisions Made**:
- ✅ Use portable-pty for PTY management
- ✅ Use vtparse for VT100 parsing (provides DCS callbacks for Sixel)
- ✅ Implement polling-based wait conditions
- ✅ Builder pattern for harness configuration

**Actual Effort**: ~2 weeks (as estimated)

---

### Phase 2: Event Simulation & Async Support 🚀

**Goal**: Rich event simulation and Tokio async integration

**Priority**: P0 (Critical - MVP Blocker)

**Status**: 🚀 **READY TO START** - Phase 1 Complete

**Dependencies**: Phase 1 ✅

**Detailed Planning**:
- See **[PHASE2_CHECKLIST.md]./PHASE2_CHECKLIST.md** for comprehensive task breakdown
- See **[PHASE2_ARCHITECTURE.md]./PHASE2_ARCHITECTURE.md** for architecture decisions

**High-Level Tasks**:

1. **Event Simulation**
   - [ ] Create `KeyCode` enum (Char, Enter, Esc, Tab, arrows, function keys)
   - [ ] Create `Modifiers` bitflags (Ctrl, Alt, Shift, Meta)
   - [ ] Implement VT100 escape sequence generation
   - [ ] Add `send_key(KeyCode)` method to harness
   - [ ] Add `send_key_with_modifiers(KeyCode, Modifiers)` method
   - [ ] Add `send_keys(text)` convenience method (type text string)
   - [ ] Test all key types and modifiers
   - [ ] **Test navigation keys for dgx-pixels** (Tab, 1-8, Esc)

2. **Enhanced Wait Conditions**
   - [ ] Review and improve existing `wait_for()` (already functional)
   - [ ] Add `wait_for_cursor(row, col)` method
   - [ ] Add `wait_for_timeout()` with custom timeout
   - [ ] Improve timeout error messages (show current state)
   - [ ] Add debug logging for wait iterations
   - [ ] Create common wait pattern helpers

3. **Tokio Async Support** (MVP requirement)
   - [ ] Add tokio feature flag to Cargo.toml (already exists)
   - [ ] Create `AsyncTuiTestHarness` struct
   - [ ] Implement async spawn, send, wait methods
   - [ ] Use tokio::time for async sleeps and timeouts
   - [ ] Wrap blocking PTY I/O with spawn_blocking
   - [ ] Support Tokio runtime in tests
   - [ ] Write async integration tests using `#[tokio::test]`
   - [ ] Update async examples

4. **Testing & Documentation**
   - [ ] Create `tests/integration/events.rs` for event tests
   - [ ] Create `tests/integration/wait.rs` for wait tests
   - [ ] Create `tests/async_integration.rs` for async tests
   - [ ] Document all new APIs with rustdoc
   - [ ] Create `examples/keyboard_events.rs`
   - [ ] Create `examples/wait_patterns.rs`
   - [ ] Update `examples/async_test.rs` with new async harness
   - [ ] Write user guides (EVENT_SIMULATION.md, ASYNC_TESTING.md)

**Success Criteria**:
- [ ] Can send keyboard events (all key types)
- [ ] Can send keys with modifiers (Ctrl+C, Alt+key, etc.)
- [ ] Can type text strings
- [ ] Wait conditions work reliably with timeout
- [ ] AsyncTuiTestHarness works with Tokio runtime
- [ ] Can test dgx-pixels navigation (Tab, number keys, Esc)
- [ ] Examples demonstrate all patterns
- [ ] All tests pass (target: >70% coverage)
- [ ] Documentation is comprehensive

**API Preview**:

```rust
// Event simulation
harness.send_key(KeyCode::Enter)?;
harness.send_keys("hello")?;
harness.send_key_with_modifiers(KeyCode::Char('c'), Modifiers::CTRL)?;

// Wait conditions
harness.wait_for_text("Success")?;
harness.wait_for_cursor(5, 10)?;
harness.wait_for(|state| state.contains("Ready"))?;

// Async support
let mut harness = AsyncTuiTestHarness::new(80, 24).await?;
harness.spawn(cmd).await?;
harness.send_key(KeyCode::Enter).await?;
harness.wait_for(|state| state.contains("Done")).await?;
```

**Estimated Effort**: 1-2 weeks (10-14 days)

**Timeline Breakdown**:
- Week 1 (Days 1-5): Event simulation foundation
- Week 2 (Days 6-10): Async support and integration
- Buffer (Days 11-14): Polish and validation

**Key Deliverables**:
1. Event simulation module (`src/events.rs`)
2. AsyncTuiTestHarness (`src/async_harness.rs`)
3. Comprehensive tests (events, wait, async)
4. Updated examples and documentation
5. dgx-pixels navigation validation

---

### Phase 3: Sixel Graphics Support with Position Tracking

**Goal**: Enable Sixel testing with position verification and bounds checking

**Priority**: P0 (Critical - MVP Blocker, Original Motivation)

**Status**: ⏳ Waiting for Phase 2

**Dependencies**: Phase 2

**Tasks**:

1. **Sixel Sequence Detection**
   - [x] **Research Sixel support** - COMPLETE: vtparse validated with DCS callbacks
   - [ ] Enhance VTActor implementation with DCS callbacks
   - [ ] Detect Sixel escape sequences via dcs_hook (mode == 'q')
   - [ ] Parse Sixel escape sequences (structure validation)
   - [ ] Extract Sixel metadata (dimensions from raster attributes)
   - [ ] **Capture cursor position when Sixel is rendered**

2. **Sixel Position Tracking** (MVP requirement)
   - [ ] Implement `SixelRegion` type with position (partially done)
   - [ ] Track bounds (position + dimensions)
   - [ ] Associate Sixel sequences with terminal coordinates
   - [ ] Store Sixel regions in ScreenState
   - [ ] **Support area-bounded queries** (in/outside area)

3. **Sixel Validation** (MVP requirement)
   - [ ] Implement `assert_sixel_within(area)` helper
   - [ ] Implement `assert_no_sixel_outside(area)` helper
   - [ ] Implement `has_sixel_graphics()` check
   - [ ] Support clearing detection (compare before/after)

4. **Test Fixtures**
   - [ ] Include dgx-pixels test images
   - [ ] Create reference Sixel output files
   - [ ] Document fixture usage

5. **Testing & Documentation**
   - [ ] Test Sixel detection and parsing
   - [ ] Test position tracking accuracy
   - [ ] Test bounds checking assertions
   - [ ] **Test dgx-pixels preview area scenario**
   - [ ] Create Sixel testing guide

**Success Criteria**:
- Can capture Sixel sequences with positions
- Can verify Sixel within bounds (preview area)
- Can detect Sixel outside bounds
- Can detect Sixel clearing on screen change
- **Can prevent dgx-pixels Sixel bugs**

**Estimated Effort**: 2-3 weeks

**Risk Assessment**: ✅ LOW (vtparse DCS support validated)

---

### Phase 4: Bevy ECS Integration

**Goal**: Support testing of Bevy-based TUI applications (bevy_ratatui)

**Priority**: P0 (Critical - MVP Blocker for dgx-pixels)

**Status**: ⏳ Waiting for Phase 3

**Dependencies**: Phase 3

**Tasks**:

1. **Bevy Harness Wrapper**
   - [ ] Add bevy feature flag
   - [ ] Create `BevyTuiTestHarness` struct
   - [ ] Wrap `TuiTestHarness` + Bevy `App`
   - [ ] Support headless Bevy app initialization
   - [ ] Integrate with bevy_ratatui plugin

2. **Update Cycle Control** (MVP requirement)
   - [ ] Implement `update()` to run one Bevy frame
   - [ ] Implement `update_n(count)` to run N frames
   - [ ] Coordinate Bevy updates with terminal rendering
   - [ ] Handle event propagation to Bevy systems

3. **ECS Querying** (MVP requirement)
   - [ ] Implement `query_entities<Component>()`
   - [ ] Implement `get_resource<Resource>()`
   - [ ] Support component inspection
   - [ ] Access Bevy World for custom queries

4. **Event Integration**
   - [ ] Convert keyboard events to Bevy events
   - [ ] Implement `send_bevy_event<Event>()`
   - [ ] Support crossterm event types
   - [ ] Verify event processing in systems

5. **Testing & Documentation**
   - [ ] Test Bevy app lifecycle
   - [ ] Test ECS queries
   - [ ] Test system execution
   - [ ] **Test dgx-pixels Job entity creation**
   - [ ] Create Bevy integration guide

**Success Criteria**:
- Can create headless Bevy TUI test harness
- Can control Bevy update cycles frame-by-frame
- Can query entities and resources
- **Can test dgx-pixels screens and state**
- Examples show Bevy ECS testing patterns

**Estimated Effort**: 2-3 weeks

**Risk**: Medium (Bevy headless mode complexity)

---

### Phase 5: Snapshot Testing & High-Level Assertions

**Goal**: Ergonomic API for common assertions and snapshot testing

**Priority**: P0 (Critical - MVP for Developer Experience)

**Status**: ⏳ Waiting for Phase 4

**Dependencies**: Phase 4

**Tasks**:

1. **Snapshot Support**
   - [ ] Implement `Snapshot` type
   - [ ] Add metadata (size, cursor, timestamp)
   - [ ] Implement text serialization
   - [ ] Implement comparison methods
   - [ ] Generate useful diffs

2. **insta Integration**
   - [ ] Add insta feature flag
   - [ ] Implement insta-compatible serialization
   - [ ] Test with insta snapshots
   - [ ] Create insta examples

3. **High-Level Assertions** (MVP requirement)
   - [ ] Implement `assert_text_at(x, y, text)`
   - [ ] Implement `assert_text_contains(text)`
   - [ ] Implement `assert_area_contains_text(area, text)`
   - [ ] Implement `assert_cursor_position(x, y)`
   - [ ] Implement `assert_cursor_in_area(area)`

4. **Ratatui Helpers**
   - [ ] Add ratatui feature flag
   - [ ] Create `RatatuiTestHelper` wrapper
   - [ ] Area-based assertions
   - [ ] Layout verification helpers

5. **Testing & Documentation**
   - [ ] Test all assertion methods
   - [ ] Test snapshot workflow
   - [ ] **Create dgx-pixels test examples**
   - [ ] Write assertion cookbook

**Success Criteria**:
- Snapshots work with insta
- Assertions are ergonomic and intuitive
- **dgx-pixels use cases have helpers**
- Examples show best practices

**Estimated Effort**: 1-2 weeks

---

### Phase 6: Polish & Documentation (MVP Release)

**Goal**: Production-ready MVP for dgx-pixels

**Priority**: P0 (Critical - MVP Completeness)

**Status**: ⏳ Waiting for Phase 5

**Dependencies**: Phase 5

**Tasks**:

1. **Error Handling**
   - [ ] Audit all error types
   - [ ] Improve error messages (actionable)
   - [ ] Add error context (what failed, where)
   - [ ] Create error handling guide

2. **Debug Support** (MVP requirement)
   - [ ] Save terminal state on test failure
   - [ ] Export failed state as ANSI text file
   - [ ] Add verbose logging option (escape sequences)
   - [ ] Document debugging techniques

3. **Documentation**
   - [ ] Complete API documentation (rustdoc)
   - [ ] Write comprehensive user guide
   - [ ] Create cookbook/recipes
   - [ ] **Write dgx-pixels integration guide**
   - [ ] Add troubleshooting section

4. **CI/CD**
   - [x] Configure GitHub Actions for tests (already done)
   - [ ] Test on Ubuntu (primary)
   - [ ] Set up code coverage reporting
   - [ ] Configure dependabot

5. **Testing**
   - [ ] Achieve 70%+ code coverage (MVP goal)
   - [ ] Add integration tests for all features
   - [ ] **Create dgx-pixels example tests**
   - [ ] Stress testing (long-running tests)

**Success Criteria**:
- All public APIs documented
- Comprehensive test coverage
- No known critical bugs
- **dgx-pixels can adopt ratatui-testlib**
- Clear, helpful error messages
- CI/CD pipeline green

**Estimated Effort**: 2-3 weeks

---

## Post-MVP Phases (v0.2.0+)

### Phase 7: Enhanced Features

**Goal**: Nice-to-have features for broader ecosystem

**Priority**: P1 (High)

**Dependencies**: Phase 6 (MVP)

**Tasks**:

1. **Mouse Event Support**
   - [ ] Implement mouse event simulation
   - [ ] Add `send_mouse(event)` method
   - [ ] Test mouse click, drag, scroll

2. **Terminal Resize**
   - [ ] Implement `resize(width, height)` method (basic done)
   - [ ] Send SIGWINCH signal
   - [ ] Test resize handling

3. **expect-test Integration**
   - [ ] Add expect-test feature flag
   - [ ] Implement expect-compatible output
   - [ ] Create expect-test examples

4. **async-std Support**
   - [ ] Add async-std feature flag
   - [ ] Test with async-std runtime

5. **Performance**
   - [ ] Profile harness overhead
   - [ ] Optimize hot paths
   - [ ] Add benchmarks

**Estimated Effort**: 2-3 weeks

---

### Phase 8: Advanced Features (Future)

**Goal**: Advanced testing capabilities

**Priority**: P2 (Medium)

**Features**:
- Record/replay terminal sessions
- Visual regression testing
- Fuzzing support
- Terminal coverage metrics
- Multi-terminal testing (xterm, kitty, wezterm)
- Remote testing (SSH)
- Performance profiling tools

---

## Version Milestones

### v0.1.0 - MVP for dgx-pixels ⭐

**Target**: End of Phase 6 (3-4 months from Phase 0)

**Current Progress**: Phase 1 Complete (100%)

**Includes**:
- ✅ Core PTY harness (Phase 1) - COMPLETE
- ⏳ Event simulation + async (Phase 2) - READY TO START
- ⏳ Sixel position tracking (Phase 3)
- ⏳ Bevy ECS integration (Phase 4)
- ⏳ Snapshots + assertions (Phase 5)
- ⏳ Polish + docs (Phase 6)

**Capabilities**:
- Test dgx-pixels Sixel positioning
- Test dgx-pixels screen transitions
- Test dgx-pixels text input
- Test dgx-pixels Bevy systems
- Run in CI/CD headlessly

**Success**: dgx-pixels can adopt and use ratatui-testlib for integration testing

---

### v0.2.0 - Enhanced Features

**Includes**:
- ✅ Mouse events
- ✅ Terminal resize
- ✅ expect-test integration
- ✅ async-std support
- ✅ Performance optimization

### v0.3.0 - Cross-Platform

**Focus**: Windows and macOS support, broader testing

### v1.0.0 - Production Ready

**Focus**: Stable API, comprehensive docs, high adoption

---

## Dependencies (Current)

### Core Dependencies ✅

```toml
[dependencies]
portable-pty = "0.8"
vtparse = "0.7"          # ✅ CONFIRMED: Lightweight VT100 parser with DCS
termwiz = "0.22"         # For utilities, not core parsing
thiserror = "2.0"
anyhow = "1.0"
```

### MVP Dependencies (Phase 2+)

```toml
[dependencies.tokio]
version = "1.35"
optional = true
features = ["full"]

[dependencies.bitflags]  # NEW for Phase 2
version = "2.4"

[dependencies.bevy]
version = "0.14"
optional = true
default-features = false

[dependencies.bevy_ecs]
version = "0.14"
optional = true

[dependencies.bevy_ratatui]
version = "0.7"
optional = true

[dependencies.ratatui]
version = "0.29"
optional = true

[dependencies.crossterm]
version = "0.28"
optional = true

[dependencies.insta]
version = "1.34"
optional = true

[dependencies.serde]
version = "1.0"
features = ["derive"]
optional = true

[dependencies.serde_json]
version = "1.0"
optional = true
```

---

## Timeline Estimate

### MVP (v0.1.0) Progress

- **Phase 0**: ✅ Complete (2 weeks)
- **Phase 1**: ✅ Complete (2 weeks) - **DONE 2025-11-20**
- **Phase 2**: 🚀 Ready to Start (1-2 weeks) - **CURRENT**
- **Phase 3**: ⏳ Pending (2-3 weeks)
- **Phase 4**: ⏳ Pending (2-3 weeks)
- **Phase 5**: ⏳ Pending (1-2 weeks)
- **Phase 6**: ⏳ Pending (2-3 weeks)

**Total MVP**: 10-16 weeks (2.5-4 months)

**Current Position**: Week 4 of 16 (25% complete)

**Aggressive Target**: 3 months
**Realistic Target**: 4 months

---

## Success Metrics

### Technical (Phase 1) ✅

- [x] Test coverage > 70% (Phase 1: 100% core coverage)
- [x] Works on Linux headlessly in CI
- [x] Zero critical bugs for Phase 1
- [x] API is documented
- [x] Examples cover Phase 1 features

### Technical (MVP Target)

- [ ] Test coverage > 70% (overall)
- [ ] Works on Linux headlessly in CI
- [ ] Zero critical bugs for dgx-pixels use cases
- [ ] API is fully documented
- [ ] Examples cover all MVP features

### Adoption (MVP)

- [ ] dgx-pixels successfully integrates ratatui-testlib
- [ ] Can test all 8 dgx-pixels screens
- [ ] Detects Sixel positioning bugs
- [ ] Detects Sixel persistence bugs
- [ ] Test execution time < 100ms per test average

### Post-MVP

- [ ] Published on crates.io
- [ ] Listed in Ratatui ecosystem
- [ ] 3+ projects using ratatui-testlib
- [ ] Community contributions

---

## dgx-pixels Integration Checklist

### Pre-Integration (Phase 1-2)

- [x] ratatui-testlib can spawn external binaries
- [x] ratatui-testlib can send text input
- [ ] ratatui-testlib can send keyboard events (Phase 2)
- [ ] ratatui-testlib has async Tokio support (Phase 2)

### Integration Phase (Phase 3-4)

- [ ] ratatui-testlib tracks Sixel positions
- [ ] ratatui-testlib integrates with Bevy
- [ ] ratatui-testlib supports bevy_ratatui

### Testing Phase (Phase 5-6)

- [ ] Write dgx-pixels integration tests
- [ ] Test all 8 screens
- [ ] Test Sixel positioning
- [ ] Test screen transitions
- [ ] Verify bugs are caught

### Release

- [ ] dgx-pixels adopts ratatui-testlib
- [ ] CI/CD includes integration tests
- [ ] Documentation includes dgx-pixels examples

---

## Risk Mitigation (Updated)

### Critical Risks for MVP

| Risk | Probability | Impact | Status | Mitigation |
|------|-------------|--------|--------|------------|
| ~~Terminal emulation complexity~~ | ~~Medium~~ | ~~High~~ | ✅ RESOLVED | vtparse provides clean VTActor API |
| **Event simulation coverage** | Medium | High | 🔍 PHASE 2 | Comprehensive testing, reference VT100 spec |
| **Async harness complexity** | Medium | Medium | 🔍 PHASE 2 | Native async harness with tokio integration |
| **Bevy headless mode issues** | Medium | High | 📋 PLANNED | Prototype early, consult Bevy community |
| **CI/CD timing issues** | Low | Medium | ✅ MITIGATED | Robust timeouts, retry logic working |

---

## Next Steps (Phase 2)

**Immediate Actions**:

1. Review PHASE2_CHECKLIST.md for detailed task breakdown
2. Review PHASE2_ARCHITECTURE.md for design decisions
3. Add bitflags dependency to Cargo.toml
4. Create src/events.rs module for KeyCode, Modifiers, KeyEvent
5. Begin implementing escape sequence generation

**Week 1 Focus**: Event simulation foundation (KeyCode, escape sequences, harness methods)

**Week 2 Focus**: Async support (AsyncTuiTestHarness, tokio integration, testing)

**Success Definition**: Phase 2 complete when all acceptance criteria in PHASE2_CHECKLIST.md are met

---

## References

- **dgx-pixels Issue #1**: TUI Integration Testing Framework Requirements
- **dgx-pixels repo**: https://github.com/raibid-labs/dgx-pixels
- **ratatui**: https://github.com/ratatui/ratatui
- **bevy_ratatui**: https://github.com/cxreiff/bevy_ratatui
- **portable-pty**: https://github.com/wez/wezterm (WezTerm's PTY library)
- **vtparse**: https://docs.rs/vtparse/ (VT100 parser)

---

## Acknowledgments

This library is being built to support the **dgx-pixels** project and addresses real-world TUI testing needs. Special thanks to the dgx-pixels development for providing concrete requirements and use cases.

Phase 1 completion demonstrates the viability of PTY-based testing with modern Rust tooling.

---

**Document Status**: Updated for Phase 2 Start
**Current Phase**: Phase 2 (Event Simulation & Async Support)
**Phase 1 Status**: ✅ Complete (100%) - 47/47 tests passing
**MVP Target**: v0.1.0 in 2-3 months (from current date)
**Primary Use Case**: dgx-pixels integration testing