cli-testing-specialist 1.0.10

Comprehensive testing framework for CLI tools - automated analysis, test generation, and security validation
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
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
# CLI Testing Specialist - Usage Guide

**Version**: 1.0.9
**Last Updated**: 2025-01-16

This guide provides comprehensive usage examples and best practices for CLI Testing Specialist.

---

## Table of Contents

- [Basic Workflow]#basic-workflow
- [Command Reference]#command-reference
- [Common Use Cases]#common-use-cases
- [Test Categories]#test-categories
- [Report Formats]#report-formats
- [Advanced Usage]#advanced-usage
- [Troubleshooting]#troubleshooting
- [Best Practices]#best-practices

---

## Basic Workflow

### 1. Analyze → Generate → Run

The standard three-step workflow for testing any CLI tool:

```bash
# Step 1: Analyze the CLI tool
cli-testing-specialist analyze /usr/bin/curl -o curl-analysis.json

# Step 2: Generate test cases
cli-testing-specialist generate curl-analysis.json -o curl-tests -c all

# Step 3: Run tests and generate reports
cli-testing-specialist run curl-tests -f all -o curl-reports
```

### 2. Quick Test (One-Liner)

For rapid testing during development:

```bash
# Analyze, generate, and run in one command (requires shell scripting)
cli-testing-specialist analyze /usr/bin/curl -o /tmp/analysis.json && \
cli-testing-specialist generate /tmp/analysis.json -o /tmp/tests -c basic,security && \
cli-testing-specialist run /tmp/tests -f markdown -o /tmp/reports && \
cat /tmp/reports/*-report.md
```

---

## Command Reference

### `analyze` - Analyze CLI Tool

Extract CLI structure and options from a binary.

#### Basic Usage

```bash
# Analyze a system binary
cli-testing-specialist analyze /usr/bin/curl -o curl-analysis.json

# Analyze a local binary (development)
cli-testing-specialist analyze ./target/release/my-cli -o analysis.json

# Analyze with verbose output
cli-testing-specialist analyze /usr/bin/git -o git-analysis.json --verbose
```

#### Output Format

The analysis file is a JSON document containing:
- Binary metadata (name, version, path)
- Global options (flags, arguments)
- Subcommands (recursive structure)
- Inferred option types (numeric, path, enum, etc.)

**Example output structure**:
```json
{
  "binary_name": "curl",
  "version": "8.4.0",
  "global_options": [
    {
      "short": "-v",
      "long": "--verbose",
      "option_type": "Flag",
      "description": "Make the operation more talkative"
    }
  ],
  "subcommands": [],
  "metadata": {
    "total_options": 237,
    "analysis_duration_ms": 109
  }
}
```

---

### `generate` - Generate Test Cases

Create BATS test files from analysis results.

#### Basic Usage

```bash
# Generate all test categories
cli-testing-specialist generate analysis.json -o tests -c all

# Generate specific categories
cli-testing-specialist generate analysis.json -o tests -c basic,security,help

# Include resource-intensive tests
cli-testing-specialist generate analysis.json -o tests -c all --include-intensive
```

#### Category Options

| Category | Description | Default | Intensive |
|----------|-------------|---------|-----------|
| `basic` | Help, version, exit codes || No |
| `help` | Subcommand help validation || No |
| `security` | Injection, null bytes, path traversal || No |
| `path` | Special characters, Unicode || No |
| `input-validation` | Numeric/enum validation || No |
| `destructive-ops` | Confirmation prompts || No |
| `performance` | Startup time, memory || No |
| `multi-shell` | bash/zsh compatibility || No |
| `directory-traversal` | Large directories, symlinks | ⚠️ | **Yes** |

**Note**: Use `--include-intensive` to enable `directory-traversal` tests (may consume significant disk space/time).

#### Output Structure

```
tests/
├── basic.bats           # Basic validation tests
├── security.bats        # Security vulnerability tests
├── help.bats            # Help text validation
├── path.bats            # Path handling tests
├── input-validation.bats
├── destructive-ops.bats
├── performance.bats
└── multi-shell.bats
```

---

### `run` - Execute Tests

Run BATS test suites and generate reports.

#### Basic Usage

```bash
# Run all tests with Markdown report
cli-testing-specialist run tests -f markdown -o reports

# Run with all report formats
cli-testing-specialist run tests -f all -o reports

# Run with custom timeout (default: 300s)
cli-testing-specialist run tests -f json -o reports --timeout 600
```

#### Report Format Options

| Format | File Extension | Use Case |
|--------|---------------|----------|
| `markdown` | `.md` | GitHub/GitLab display |
| `json` | `.json` | CI/CD integration, programmatic processing |
| `html` | `.html` | Interactive browser viewing |
| `junit` | `.xml` | CI/CD (GitHub Actions, GitLab CI, Jenkins) |
| `all` | All formats | Comprehensive reporting |

#### Skip Categories

```bash
# Skip performance tests (for fast feedback)
cli-testing-specialist run tests -f markdown -o reports --skip performance

# Skip multiple categories
cli-testing-specialist run tests -f json -o reports --skip performance,multi-shell
```

---

## Common Use Cases

### Use Case 1: Testing a Rust CLI (clap)

```bash
# Build your CLI
cargo build --release

# Analyze
cli-testing-specialist analyze ./target/release/my-cli -o analysis.json

# Generate tests (all categories)
cli-testing-specialist generate analysis.json -o tests -c all

# Run tests
cli-testing-specialist run tests -f all -o reports

# View HTML report
open reports/my-cli-tests-report.html  # macOS
# xdg-open reports/my-cli-tests-report.html  # Linux
```

### Use Case 2: Testing a Node.js CLI (commander.js)

```bash
# Build your CLI
npm run build

# Make binary executable
chmod +x ./bin/my-cli.js

# Analyze
cli-testing-specialist analyze ./bin/my-cli.js -o analysis.json

# Generate and run
cli-testing-specialist generate analysis.json -o tests -c all
cli-testing-specialist run tests -f markdown -o reports
```

**Note**: Node.js CLIs may use different exit codes than Rust CLIs:
- commander.js: Exit code 1 for errors
- clap: Exit code 2 for usage errors

### Use Case 3: Security Testing Only

```bash
# Generate security-focused tests
cli-testing-specialist generate analysis.json -o tests -c security,input-validation,destructive-ops

# Run with detailed logging
cli-testing-specialist run tests -f json -o reports --verbose

# Check for failures
jq '.total_failed' reports/tests-report.json
```

### Use Case 4: CI/CD Integration

```bash
# In your CI script (e.g., .github/workflows/test.yml)

# 1. Build binary
cargo build --release

# 2. Analyze
cli-testing-specialist analyze ./target/release/my-cli -o analysis.json

# 3. Generate tests
cli-testing-specialist generate analysis.json -o tests -c all

# 4. Run tests with JUnit XML for CI
cli-testing-specialist run tests -f junit -o reports

# 5. Upload reports as artifacts
# (GitHub Actions: upload-artifact@v4)
```

### Use Case 5: Development Workflow

```bash
# Quick test during development (basic tests only)
cli-testing-specialist analyze ./target/debug/my-cli -o /tmp/analysis.json && \
cli-testing-specialist generate /tmp/analysis.json -o /tmp/tests -c basic,help && \
cli-testing-specialist run /tmp/tests -f markdown

# Full test before commit
cli-testing-specialist analyze ./target/release/my-cli -o analysis.json && \
cli-testing-specialist generate analysis.json -o tests -c all && \
cli-testing-specialist run tests -f all -o reports
```

---

## Test Categories

### Basic Validation

Tests fundamental CLI functionality.

**What's tested**:
- `--help` displays help text
- `--version` displays version
- Exit codes (0 for success, non-zero for errors)
- No-args behavior (help/error/execute)

**Example test**:
```bash
@test "curl --help should display help and exit 0" {
  run curl --help
  [ "$status" -eq 0 ]
  [[ "$output" =~ "Usage:" ]]
}
```

### Security

Tests for common security vulnerabilities.

**What's tested**:
- Command injection (`;`, `|`, `&&`, etc.)
- Null byte injection (`\0`)
- Path traversal (`../`, `../../etc/passwd`)
- Special characters (`'`, `"`, `$`, `` ` ``)

**Example test**:
```bash
@test "curl should reject command injection in URL" {
  run curl "http://example.com; cat /etc/passwd"
  [ "$status" -ne 0 ]
}
```

### Input Validation

Tests option validation and error handling.

**What's tested**:
- Invalid numeric values (negative, zero, non-numeric)
- Invalid enum values
- Invalid path formats
- Boundary conditions

**Example test**:
```bash
@test "curl --max-time should reject negative values" {
  run curl --max-time -1 http://example.com
  [ "$status" -ne 0 ]
  [[ "$output" =~ "invalid" ]]
}
```

### Destructive Operations

Tests confirmation prompts and safety mechanisms.

**What's tested**:
- `--yes` / `--force` flag presence
- Confirmation prompt behavior
- Non-interactive mode support

**Example test**:
```bash
@test "rm should require --force for destructive operation" {
  run rm /important/file
  [ "$status" -ne 0 ]
  [[ "$output" =~ "confirm" || "$output" =~ "force" ]]
}
```

### Help

Tests help text quality and consistency.

**What's tested**:
- Help text presence for all subcommands
- Usage examples
- Option descriptions
- Consistent formatting

**Example test**:
```bash
@test "git commit --help should show usage" {
  run git commit --help
  [ "$status" -eq 0 ]
  [[ "$output" =~ "usage:" || "$output" =~ "Usage:" ]]
}
```

### Path Handling

Tests file and directory path processing.

**What's tested**:
- Special characters in paths (`spaces`, `!@#$%`)
- Unicode filenames
- Deep directory hierarchies
- Non-existent paths

**Example test**:
```bash
@test "curl should handle paths with spaces" {
  run curl --output "file with spaces.txt" http://example.com
  [ "$status" -eq 0 ]
}
```

### Performance

Tests execution speed and resource usage.

**What's tested**:
- Startup time (< 1 second)
- Memory usage (reasonable limits)
- Large input handling

**Example test**:
```bash
@test "curl should start in under 1 second" {
  start=$(date +%s)
  run curl --version
  end=$(date +%s)
  duration=$((end - start))
  [ "$duration" -lt 1 ]
}
```

### Multi-Shell

Tests compatibility across different shells.

**What's tested**:
- bash compatibility
- zsh compatibility
- Exit code consistency
- Output consistency

**Example test**:
```bash
@test "curl --help should work in zsh" {
  run zsh -c "curl --help"
  [ "$status" -eq 0 ]
}
```

### Directory Traversal (Intensive)

Tests handling of large/complex directory structures.

**What's tested**:
- Large file counts (1000+ files)
- Deep nesting (10+ levels)
- Symlink loops
- Filesystem edge cases

**⚠️ Warning**: These tests are resource-intensive. Use `--include-intensive` flag.

---

## Report Formats

### Markdown Reports

Best for: GitHub/GitLab display, quick review

```bash
cli-testing-specialist run tests -f markdown -o reports
cat reports/tests-report.md
```

**Features**:
- Summary statistics table
- Test suite breakdown
- Detailed failure messages
- Shell compatibility matrix

### JSON Reports

Best for: CI/CD integration, programmatic analysis

```bash
cli-testing-specialist run tests -f json -o reports

# Extract statistics with jq
jq '.total_tests' reports/tests-report.json
jq '.total_passed' reports/tests-report.json
jq '[.suites[].tests[] | select(.status == "failed")] | length' reports/tests-report.json
```

**Structure**:
```json
{
  "binary_name": "curl",
  "total_tests": 42,
  "total_passed": 40,
  "total_failed": 2,
  "total_skipped": 0,
  "duration_secs": 5.2,
  "test_suites": [
    {
      "name": "basic",
      "tests": [...]
    }
  ]
}
```

### HTML Reports

Best for: Interactive viewing, presentations

```bash
cli-testing-specialist run tests -f html -o reports
open reports/tests-report.html
```

**Features**:
- 📊 Visual statistics cards
- 📈 Progress bar with success rate
- 🔍 Collapsible test details
- 🎨 Professional design (Bootstrap 5)
- ⚡ Zero CDN dependencies (self-contained)
- 📱 Fully responsive

### JUnit XML Reports

Best for: CI/CD systems (GitHub Actions, GitLab CI, Jenkins)

```bash
cli-testing-specialist run tests -f junit -o reports
```

**CI Integration Example**:
```yaml
# .github/workflows/test.yml
- name: Run tests
  run: cli-testing-specialist run tests -f junit -o reports

- name: Publish test results
  uses: EnricoMi/publish-unit-test-result-action@v2
  with:
    files: reports/*.xml
```

---

## Advanced Usage

### Custom Configuration

Create a configuration file to customize test generation:

```yaml
# cli-test-config.yml
version: "1.0"

# Skip specific test categories
skip_categories:
  - performance
  - directory-traversal

# Custom test priorities
test_priorities:
  security: critical
  input-validation: high
  basic: medium

# Resource limits
resource_limits:
  timeout_seconds: 600
  max_memory_mb: 1024
```

Use with:
```bash
cli-testing-specialist generate analysis.json -o tests -c all --config cli-test-config.yml
```

### Parallel Test Execution

BATS automatically runs test files in parallel. Adjust parallelism:

```bash
# Run with 4 parallel jobs
cli-testing-specialist run tests -f markdown -o reports --jobs 4

# Run serially (for debugging)
cli-testing-specialist run tests -f markdown -o reports --jobs 1
```

### Filtering Tests

```bash
# Run only security tests
cli-testing-specialist run tests -f markdown -o reports --category security

# Skip performance tests
cli-testing-specialist run tests -f markdown -o reports --skip performance
```

### Debugging Test Failures

```bash
# Enable verbose output
cli-testing-specialist run tests -f markdown -o reports --verbose

# Run a single test file manually
bats tests/security.bats

# Run with BATS verbose mode
bats -p tests/security.bats
```

---

## Troubleshooting

### Issue: "BATS not found"

**Solution**: Install BATS (Bash Automated Testing System)

```bash
# macOS
brew install bats-core

# Ubuntu/Debian
sudo apt-get install bats

# Manual installation
git clone https://github.com/bats-core/bats-core.git
cd bats-core
sudo ./install.sh /usr/local
```

### Issue: "Binary not found"

**Solution**: Ensure the binary path is correct and executable

```bash
# Check binary exists
ls -la /usr/bin/curl

# Make binary executable
chmod +x ./target/release/my-cli

# Use absolute path
cli-testing-specialist analyze $(pwd)/target/release/my-cli -o analysis.json
```

### Issue: "No help output detected"

**Solution**: Verify your CLI supports `--help` or `-h`

```bash
# Test manually
/usr/bin/curl --help
/usr/bin/curl -h
/usr/bin/curl help

# If none work, your CLI may not be compatible
```

### Issue: "Tests failing in CI but passing locally"

**Common causes**:
1. **Different binary**: CI may build a different binary version
   ```bash
   # Verify binary in CI
   cli-testing-specialist analyze ./my-cli --verbose
   ```

2. **Resource limits**: CI environments may have strict limits
   ```bash
   # Skip intensive tests in CI
   cli-testing-specialist generate analysis.json -o tests -c all  # Don't use --include-intensive
   ```

3. **Shell differences**: CI may use different shell
   ```bash
   # Test in specific shell
   bash -c "cli-testing-specialist run tests -f markdown"
   ```

### Issue: "Analysis timeout"

**Solution**: Increase timeout for slow binaries

```bash
# Default timeout: 30 seconds
cli-testing-specialist analyze ./slow-cli -o analysis.json --timeout 120
```

---

## Best Practices

### 1. Version Your Analysis Files

Keep analysis files in version control to track CLI evolution:

```bash
# Generate versioned analysis
cli-testing-specialist analyze ./my-cli -o analysis-v1.0.0.json

# Commit to git
git add analysis-v1.0.0.json
git commit -m "Add CLI analysis for v1.0.0"
```

### 2. Use Specific Categories in Development

Run fast tests during development, comprehensive tests before release:

```bash
# Development (fast feedback)
cli-testing-specialist generate analysis.json -o tests -c basic,help

# Pre-release (comprehensive)
cli-testing-specialist generate analysis.json -o tests -c all
```

### 3. Integrate with CI/CD

Add CLI testing to your CI pipeline:

```yaml
# .github/workflows/test.yml
name: CLI Testing

on: [push, pull_request]

jobs:
  cli-test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Build CLI
        run: cargo build --release

      - name: Install BATS
        run: sudo apt-get install -y bats

      - name: Install cli-testing-specialist
        run: cargo install cli-testing-specialist

      - name: Analyze CLI
        run: cli-testing-specialist analyze ./target/release/my-cli -o analysis.json

      - name: Generate tests
        run: cli-testing-specialist generate analysis.json -o tests -c all

      - name: Run tests
        run: cli-testing-specialist run tests -f junit -o reports

      - name: Upload reports
        if: always()
        uses: actions/upload-artifact@v4
        with:
          name: test-reports
          path: reports/
```

### 4. Review Generated Tests

Always review generated tests before integrating:

```bash
# Generate tests
cli-testing-specialist generate analysis.json -o tests -c all

# Review test files
cat tests/security.bats
cat tests/basic.bats

# Run manually if needed
bats tests/security.bats
```

### 5. Keep Tests Updated

Regenerate tests when your CLI changes:

```bash
# After adding new options/subcommands
cli-testing-specialist analyze ./my-cli -o analysis.json
cli-testing-specialist generate analysis.json -o tests -c all

# Compare with previous tests
diff -r tests/ tests-old/
```

### 6. Use HTML Reports for Stakeholders

Generate HTML reports for non-technical stakeholders:

```bash
cli-testing-specialist run tests -f html -o reports
open reports/tests-report.html
```

### 7. Monitor Test Trends

Track test results over time in CI:

```bash
# Extract metrics
jq '.total_passed, .total_failed, .duration_secs' reports/tests-report.json

# Store in metrics system (e.g., Prometheus, CloudWatch)
```

---

## Next Steps

- **[Configuration Guide]./CONFIGURATION.md**: Advanced configuration options
- **[Report Formats]./REPORT-FORMATS.md**: Detailed report format specifications
- **[Target Tools]./TARGET-TOOLS.md**: CLI tool compatibility guidelines
- **[Contributing Guide]../CONTRIBUTING.md**: How to contribute to the project

---

**Questions or Issues?**

- 📖 [Documentation]../README.md
- 🐛 [Report an Issue]https://github.com/sanae-abe/cli-testing-specialist/issues
- 💬 [Discussions]https://github.com/sanae-abe/cli-testing-specialist/discussions