|
| 1 | +# CLI & TUI Testing Guide |
| 2 | + |
| 3 | +How to manually test the tusk CLI in both print mode and interactive TUI mode. |
| 4 | + |
| 5 | +## Print Mode Testing |
| 6 | + |
| 7 | +Print mode (`--print`) runs headlessly — no interactive UI. Run it directly and inspect stderr: |
| 8 | + |
| 9 | +```bash |
| 10 | +cd /path/to/test-project |
| 11 | +/path/to/tusk drift run --print 2>&1 |
| 12 | +``` |
| 13 | + |
| 14 | +Filter for specific output: |
| 15 | + |
| 16 | +```bash |
| 17 | +/path/to/tusk drift run --print 2>&1 | grep -E "(➤|✓|Tests:|Error:)" |
| 18 | +``` |
| 19 | + |
| 20 | +### Testing failure scenarios |
| 21 | + |
| 22 | +To test startup failures, temporarily change the start command in `.tusk/config.yaml`: |
| 23 | + |
| 24 | +```yaml |
| 25 | +start: |
| 26 | + command: node -e "console.log('boot log line'); console.error('some error'); process.exit(1)" |
| 27 | +``` |
| 28 | +
|
| 29 | +To test with a service that starts but behaves differently, adjust the command or example codebase as needed. |
| 30 | +
|
| 31 | +**Always restore the config after testing.** |
| 32 | +
|
| 33 | +## TUI Testing with tmux |
| 34 | +
|
| 35 | +The TUI (interactive mode, no `--print`) requires a terminal. We use tmux for programmatic control — it lets us send keystrokes and capture output without needing to be in the terminal ourselves. |
| 36 | + |
| 37 | +### Option A: Native screenshots (recommended) |
| 38 | + |
| 39 | +Opens a real Terminal.app window with tmux inside it, then uses macOS `screencapture -l` to capture that specific window by ID. This produces pixel-perfect Retina screenshots and should always be used to verify TUI visual changes. |
| 40 | + |
| 41 | +**One-time setup:** Grant Screen Recording permission to Terminal.app in System Settings > Privacy & Security > Screen Recording. |
| 42 | + |
| 43 | +```bash |
| 44 | +# 1. Open Terminal.app with a tmux session |
| 45 | +osascript -e 'tell application "Terminal" |
| 46 | + do script "tmux new-session -s tui-test -x 200 -y 55" |
| 47 | +end tell' |
| 48 | +sleep 3 |
| 49 | +
|
| 50 | +# 2. Resize the window to fill most of the screen (fits 14"/16" MacBook Pro) |
| 51 | +osascript -e 'tell application "Terminal" to set bounds of front window to {0, 25, 1700, 1100}' |
| 52 | +sleep 1 |
| 53 | +
|
| 54 | +# 3. Hide tmux status bar (otherwise a green bar appears at the bottom) |
| 55 | +tmux set -t tui-test status off |
| 56 | +
|
| 57 | +# 4. Launch the TUI |
| 58 | +tmux send-keys -t tui-test 'cd /path/to/test-project && /path/to/tusk drift run' Enter |
| 59 | +
|
| 60 | +# 5. Wait for the state you want to capture |
| 61 | +# - Normal run with tests: ~25-30s (environment start + test execution) |
| 62 | +# - Startup failure with sandbox retry: ~15-18s |
| 63 | +# - Just initial render: ~3-5s |
| 64 | +sleep 25 |
| 65 | +
|
| 66 | +# 6. Navigate if needed |
| 67 | +tmux send-keys -t tui-test g # go to top (select Service Logs) |
| 68 | +tmux send-keys -t tui-test j # move selection down |
| 69 | +tmux send-keys -t tui-test J # scroll log panel down |
| 70 | +tmux send-keys -t tui-test D # half-page down in log panel |
| 71 | +sleep 1 |
| 72 | +
|
| 73 | +# 7. Find the Terminal.app window ID |
| 74 | +WINDOW_ID=$(python3 -c " |
| 75 | +import Quartz |
| 76 | +windows = Quartz.CGWindowListCopyWindowInfo(Quartz.kCGWindowListOptionOnScreenOnly, Quartz.kCGNullWindowID) |
| 77 | +for w in windows: |
| 78 | + if w.get('kCGWindowOwnerName') == 'Terminal' and w.get('kCGWindowLayer', 0) == 0: |
| 79 | + print(w['kCGWindowNumber']) |
| 80 | + break |
| 81 | +") |
| 82 | +
|
| 83 | +# 8. Capture the window |
| 84 | +screencapture -l "$WINDOW_ID" -o screenshot.png |
| 85 | +
|
| 86 | +# 9. Cleanup |
| 87 | +tmux send-keys -t tui-test q |
| 88 | +sleep 2 |
| 89 | +tmux kill-session -t tui-test |
| 90 | +osascript -e 'tell application "Terminal" to close front window' 2>/dev/null |
| 91 | +``` |
| 92 | + |
| 93 | +**Output:** ~2800x1800 Retina PNG with native font rendering. |
| 94 | + |
| 95 | +**Notes:** |
| 96 | +- `screencapture -l` captures by window ID — the Terminal window doesn't need to be in the foreground. You can keep working in other windows. |
| 97 | +- The `-o` flag removes the window shadow. |
| 98 | +- `screencapture -l` fails silently without Screen Recording permission — you get a blank or tiny image. |
| 99 | +- When finding the window ID, make sure to match `kCGWindowOwnerName == 'Terminal'` — other apps (Chrome, etc.) may be in front. |
| 100 | + |
| 101 | +### Option B: Text capture (quick functional checks) |
| 102 | + |
| 103 | +Uses a detached tmux session — no visible window, no permissions needed. Good for verifying that specific text appears in the TUI or that navigation works. **Not a substitute for screenshots** when verifying layout, colors, or visual rendering. |
| 104 | + |
| 105 | +```bash |
| 106 | +# 1. Detached tmux session (no visible window) |
| 107 | +tmux new-session -d -s tui-test -x 200 -y 55 |
| 108 | +
|
| 109 | +# 2. Launch the TUI |
| 110 | +tmux send-keys -t tui-test 'cd /path/to/test-project && /path/to/tusk drift run' Enter |
| 111 | +sleep 25 |
| 112 | +
|
| 113 | +# 3. Capture the screen as plain text |
| 114 | +SCREEN=$(tmux capture-pane -t tui-test -p) |
| 115 | +
|
| 116 | +# 4. Assert on content |
| 117 | +echo "$SCREEN" | grep -q "TEST EXECUTION" || echo "FAIL: header not found" |
| 118 | +echo "$SCREEN" | grep -q "Environment ready" || echo "FAIL: environment didn't start" |
| 119 | +
|
| 120 | +# 5. Navigate and capture again |
| 121 | +tmux send-keys -t tui-test j |
| 122 | +sleep 0.5 |
| 123 | +SCREEN=$(tmux capture-pane -t tui-test -p) |
| 124 | +
|
| 125 | +# 6. Cleanup |
| 126 | +tmux send-keys -t tui-test q |
| 127 | +sleep 1 |
| 128 | +tmux kill-session -t tui-test |
| 129 | +``` |
| 130 | + |
| 131 | +### TUI keyboard shortcuts reference |
| 132 | + |
| 133 | +| Key | Action | |
| 134 | +| --------- | --------------------------------------- | |
| 135 | +| `j` / `k` | Select next/previous test in left panel | |
| 136 | +| `g` / `G` | Jump to top/bottom of test list | |
| 137 | +| `u` / `d` | Half-page up/down in test list | |
| 138 | +| `J` / `K` | Scroll log panel down/up | |
| 139 | +| `U` / `D` | Half-page up/down in log panel | |
| 140 | +| `y` | Copy all logs | |
| 141 | +| `q` | Quit | |
| 142 | + |
| 143 | +## Recommended Dimensions |
| 144 | + |
| 145 | +| Setting | Value | Notes | |
| 146 | +| ------------ | ----- | ------------------------------------------ | |
| 147 | +| tmux columns | 200 | Wide enough for both TUI panels + detail | |
| 148 | +| tmux rows | 55 | Tall enough to see tests + logs | |
| 149 | +| Window bounds | {0, 25, 1700, 1100} | Fits 14"/16" MacBook Pro (adjust for your display) | |
| 150 | + |
| 151 | +## Common Gotchas |
| 152 | + |
| 153 | +1. **Timing is critical.** The TUI renders asynchronously. Capturing too early gives an incomplete screen. When in doubt, wait longer. |
| 154 | +2. **tmux status bar.** The green bar at the bottom of native screenshots is tmux's status line. Hide it with `tmux set -t tui-test status off` before capturing. |
| 155 | +3. **Scrolling.** Content often extends below the visible area of the log panel. Send `J` or `D` keys to scroll down before capturing. |
| 156 | +4. **Screen Recording permission.** Native `screencapture -l` fails silently without it. Grant it to Terminal.app in System Settings > Privacy & Security > Screen Recording. |
| 157 | +5. **YAML quoting.** When editing config.yaml with commands containing colons or quotes, wrap the entire value in double quotes and escape inner quotes. |
| 158 | +6. **Restore config.** Always restore `.tusk/config.yaml` after testing with modified start commands. |
| 159 | +7. **tmux targets by session name** (`-t tui-test`), so commands work regardless of which terminal you're focused on. You can keep working while tests run. |
| 160 | +8. **Window ID targeting.** When using `screencapture -l`, make sure the Python script finds the Terminal window, not Chrome or another app that may be in front. |
0 commit comments