Skip to content

Commit d8b0988

Browse files
WIP: Add tmux-based CLI testing infrastructure
- Add integration and E2E test suites using tmux - Add automatic tmux detection in .bin/bun wrapper - Add test utilities for checking dependencies - Add comprehensive testing documentation - Update CLI to use strip-ansi for output cleaning 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
1 parent 10f0645 commit d8b0988

File tree

11 files changed

+867
-67
lines changed

11 files changed

+867
-67
lines changed

.bin/bun

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,14 @@ create_cache() {
172172
fi
173173
}
174174

175+
# Function to check if tmux is installed
176+
check_tmux_installed() {
177+
if ! command -v tmux &> /dev/null; then
178+
return 1
179+
fi
180+
return 0
181+
}
182+
175183
# Function to check if command doesn't need secrets
176184
# Returns 0 if secrets are NOT needed, 1 if they ARE needed
177185
doesnt_need_secrets() {
@@ -248,6 +256,43 @@ doesnt_need_secrets() {
248256
;;
249257
esac
250258
;;
259+
# Test command needs special handling
260+
test)
261+
# Check for integration/e2e tests that require tmux
262+
# Convention: test files matching *integration*.test.ts or *e2e*.test.ts
263+
local needs_tmux=false
264+
265+
for arg in "$@"; do
266+
# Check if running integration or e2e tests
267+
if [[ "$arg" =~ (integration|e2e).*\.test\.(ts|tsx|js|jsx) ]]; then
268+
needs_tmux=true
269+
break
270+
fi
271+
# Also check if running all tests and integration files exist
272+
if [[ "$arg" == "test" ]] || [[ -z "$arg" ]]; then
273+
if ls */src/__tests__/*integration*.test.ts 2>/dev/null || ls */src/__tests__/*e2e*.test.ts 2>/dev/null; then
274+
needs_tmux=true
275+
break
276+
fi
277+
fi
278+
done
279+
280+
# If running integration/e2e tests, check tmux availability
281+
if [ "$needs_tmux" = true ]; then
282+
if ! check_tmux_installed; then
283+
echo "⚠️ tmux not found but required for integration/E2E tests"
284+
echo ""
285+
echo "📦 Install tmux:"
286+
echo " macOS: brew install tmux"
287+
echo " Ubuntu: sudo apt-get install tmux"
288+
echo " Windows: Use WSL and run 'sudo apt-get install tmux'"
289+
echo ""
290+
echo "ℹ️ Skipping tmux-dependent tests..."
291+
echo ""
292+
fi
293+
fi
294+
return 1 # Tests need secrets
295+
;;
251296
*)
252297
# Default to needing secrets for all other commands
253298
return 1

CONTRIBUTING.md

Lines changed: 44 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -114,35 +114,35 @@ Before you begin, you'll need to install a few tools:
114114

115115
10. **Running in other directories**:
116116

117-
In order to run the CLI from other directories, you need to first publish the agents to the database.
117+
In order to run the CLI from other directories, you need to first publish the agents to the database.
118118

119-
- First, create a publisher profile at http://localhost:3000/publishers. Make sure the `publisher_id` is `codebuff`.
119+
- First, create a publisher profile at http://localhost:3000/publishers. Make sure the `publisher_id` is `codebuff`.
120120

121-
- Run:
121+
- Run:
122122

123-
```bash
124-
bun run start-bin publish base
125-
```
123+
```bash
124+
bun run start-bin publish base
125+
```
126126

127-
- It will give you an error along the lines of `Invalid agent ID: [some agent ID]`, e.g. `Invalid agent ID: context-pruner`. You need to publish that agent at the same time, e.g.:
127+
- It will give you an error along the lines of `Invalid agent ID: [some agent ID]`, e.g. `Invalid agent ID: context-pruner`. You need to publish that agent at the same time, e.g.:
128128

129-
```bash
130-
bun run start-bin publish base context-pruner
131-
```
129+
```bash
130+
bun run start-bin publish base context-pruner
131+
```
132132

133-
- Repeat this until there are no more errors.
133+
- Repeat this until there are no more errors.
134134

135-
- As of the time of writing, the command required is:
135+
- As of the time of writing, the command required is:
136136

137-
```bash
138-
bun start-bin publish base context-pruner file-explorer file-picker researcher thinker reviewer
139-
```
137+
```bash
138+
bun start-bin publish base context-pruner file-explorer file-picker researcher thinker reviewer
139+
```
140140

141-
- Now, you can start the CLI in any directory by running:
141+
- Now, you can start the CLI in any directory by running:
142142

143-
```bash
144-
bun run start-bin --cwd [some/other/directory]
145-
```
143+
```bash
144+
bun run start-bin --cwd [some/other/directory]
145+
```
146146

147147
## Understanding the Codebase
148148

@@ -204,6 +204,31 @@ bun test specific.test.ts # Run just one test file
204204

205205
**Writing tests:** Use `spyOn()` for mocking functions (it's cleaner than `mock.module()`), and always clean up with `mock.restore()` in your `afterEach()` blocks.
206206

207+
#### Interactive CLI Testing
208+
209+
For testing interactive CLI features (user input, real-time responses), install tmux:
210+
211+
```bash
212+
# macOS
213+
brew install tmux
214+
215+
# Ubuntu/Debian
216+
sudo apt-get install tmux
217+
218+
# Windows (via WSL)
219+
wsl --install
220+
sudo apt-get install tmux
221+
```
222+
223+
Run the proof-of-concept to validate your setup:
224+
225+
```bash
226+
cd cli
227+
bun run test:tmux-poc
228+
```
229+
230+
See [cli/src/__tests__/README.md](cli/src/__tests__/README.md) for comprehensive interactive testing documentation.
231+
207232
### Commit Messages
208233

209234
We use conventional commit format:

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,31 @@ We ❤️ contributions from the community - whether you're fixing bugs, tweakin
148148

149149
**Want to contribute?** Check out our [Contributing Guide](./CONTRIBUTING.md) to get started.
150150

151+
### Running Tests
152+
153+
To run the test suite:
154+
155+
```bash
156+
cd cli
157+
bun test
158+
```
159+
160+
**For interactive E2E testing**, install tmux:
161+
162+
```bash
163+
# macOS
164+
brew install tmux
165+
166+
# Ubuntu/Debian
167+
sudo apt-get install tmux
168+
169+
# Windows (via WSL)
170+
wsl --install
171+
sudo apt-get install tmux
172+
```
173+
174+
See [cli/src/__tests__/README.md](cli/src/__tests__/README.md) for comprehensive testing documentation.
175+
151176
Some ways you can help:
152177

153178
- 🐛 **Fix bugs** or add features

cli/README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,38 @@ Run the TUI in development mode:
1616
bun run dev
1717
```
1818

19+
## Testing
20+
21+
Run the test suite:
22+
23+
```bash
24+
bun test
25+
```
26+
27+
### Interactive E2E Testing
28+
29+
For testing interactive CLI features, install tmux:
30+
31+
```bash
32+
# macOS
33+
brew install tmux
34+
35+
# Ubuntu/Debian
36+
sudo apt-get install tmux
37+
38+
# Windows (via WSL)
39+
wsl --install
40+
sudo apt-get install tmux
41+
```
42+
43+
Then run the proof-of-concept:
44+
45+
```bash
46+
bun run test:tmux-poc
47+
```
48+
49+
See [src/__tests__/README.md](src/__tests__/README.md) for comprehensive testing documentation.
50+
1951
## Build
2052

2153
Build the package:

cli/knowledge.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
11
# CLI Package Knowledge
22

3+
## Test Naming Conventions
4+
5+
**IMPORTANT**: Follow these naming patterns for automatic dependency detection:
6+
7+
- **Unit tests:** `*.test.ts` (e.g., `cli-args.test.ts`)
8+
- **E2E tests:** `e2e-*.test.ts` (e.g., `e2e-cli.test.ts`)
9+
- **Integration tests:** `integration-*.test.ts` (e.g., `integration-tmux.test.ts`)
10+
11+
**Why?** The `.bin/bun` wrapper detects files matching `*integration*.test.ts` or `*e2e*.test.ts` patterns and automatically checks for tmux availability. If tmux is missing, it shows installation instructions but lets tests continue (they skip gracefully).
12+
13+
**Benefits:**
14+
15+
- Project-wide convention (not CLI-specific)
16+
- No hardcoded directory paths
17+
- Automatic dependency validation
18+
- Clear test categorization
19+
320
## Migration from Custom OpenTUI Fork
421

522
**October 2024**: Migrated from custom `CodebuffAI/opentui#codebuff/custom` fork to official `@opentui/react@^0.1.27` and `@opentui/core@^0.1.27` packages.

cli/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"build:binary": "bun ./scripts/build-binary.ts codecane $npm_package_version",
2323
"start": "bun run dist/index.js",
2424
"test": "bun test",
25+
"test:tmux-poc": "bun run src/__tests__/tmux-poc.ts",
2526
"pretypecheck": "bun run build:sdk",
2627
"typecheck": "tsc --noEmit -p ."
2728
},
@@ -46,6 +47,7 @@
4647
"@types/bun": "^1.3.0",
4748
"@types/node": "22",
4849
"@types/react": "^18.3.12",
49-
"@types/react-reconciler": "^0.32.0"
50+
"@types/react-reconciler": "^0.32.0",
51+
"strip-ansi": "^7.1.2"
5052
}
5153
}

0 commit comments

Comments
 (0)