forked from rtk-ai/rtk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-all.sh
More file actions
executable file
·583 lines (410 loc) · 21.2 KB
/
Copy pathtest-all.sh
File metadata and controls
executable file
·583 lines (410 loc) · 21.2 KB
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
#!/usr/bin/env bash
#
# RTK Smoke Test Suite
# Exercises every command to catch regressions after merge.
# Exit code: number of failures (0 = all green)
#
set -euo pipefail
PASS=0
FAIL=0
SKIP=0
FAILURES=()
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
CYAN='\033[0;36m'
BOLD='\033[1m'
NC='\033[0m'
# ── Helpers ──────────────────────────────────────────
assert_ok() {
local name="$1"
shift
local output
if output=$("$@" 2>&1); then
PASS=$((PASS + 1))
printf " ${GREEN}PASS${NC} %s\n" "$name"
else
FAIL=$((FAIL + 1))
FAILURES+=("$name")
printf " ${RED}FAIL${NC} %s\n" "$name"
printf " cmd: %s\n" "$*"
printf " out: %s\n" "$(echo "$output" | head -3)"
fi
}
assert_contains() {
local name="$1"
local needle="$2"
shift 2
local output
if output=$("$@" 2>&1) && echo "$output" | grep -q "$needle"; then
PASS=$((PASS + 1))
printf " ${GREEN}PASS${NC} %s\n" "$name"
else
FAIL=$((FAIL + 1))
FAILURES+=("$name")
printf " ${RED}FAIL${NC} %s\n" "$name"
printf " expected: '%s'\n" "$needle"
printf " got: %s\n" "$(echo "$output" | head -3)"
fi
}
assert_exit_ok() {
local name="$1"
shift
if "$@" >/dev/null 2>&1; then
PASS=$((PASS + 1))
printf " ${GREEN}PASS${NC} %s\n" "$name"
else
FAIL=$((FAIL + 1))
FAILURES+=("$name")
printf " ${RED}FAIL${NC} %s\n" "$name"
printf " cmd: %s\n" "$*"
fi
}
assert_fails() {
local name="$1"
shift
if "$@" >/dev/null 2>&1; then
FAIL=$((FAIL + 1))
FAILURES+=("$name (expected failure, got success)")
printf " ${RED}FAIL${NC} %s (expected failure)\n" "$name"
else
PASS=$((PASS + 1))
printf " ${GREEN}PASS${NC} %s\n" "$name"
fi
}
assert_help() {
local name="$1"
shift
assert_contains "$name --help" "Usage:" "$@" --help
}
skip_test() {
local name="$1"
local reason="$2"
SKIP=$((SKIP + 1))
printf " ${YELLOW}SKIP${NC} %s (%s)\n" "$name" "$reason"
}
section() {
printf "\n${BOLD}${CYAN}── %s ──${NC}\n" "$1"
}
# ── Preamble ─────────────────────────────────────────
RTK=$(command -v rtk || echo "")
if [[ -z "$RTK" ]]; then
echo "rtk not found in PATH. Run: cargo install --path ."
exit 1
fi
printf "${BOLD}RTK Smoke Test Suite${NC}\n"
printf "Binary: %s\n" "$RTK"
printf "Version: %s\n" "$(rtk --version)"
printf "Date: %s\n" "$(date '+%Y-%m-%d %H:%M')"
# Need a git repo to test git commands
if ! git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
echo "Must run from inside a git repository."
exit 1
fi
REPO_ROOT=$(git rev-parse --show-toplevel)
# ── 1. Version & Help ───────────────────────────────
section "Version & Help"
assert_contains "rtk --version" "rtk" rtk --version
assert_contains "rtk --help" "Usage:" rtk --help
# ── 2. Ls ────────────────────────────────────────────
section "Ls"
assert_ok "rtk ls ." rtk ls .
assert_ok "rtk ls -la ." rtk ls -la .
assert_ok "rtk ls -lh ." rtk ls -lh .
assert_ok "rtk ls -l src/" rtk ls -l src/
assert_ok "rtk ls src/ -l (flag after)" rtk ls src/ -l
assert_ok "rtk ls multi paths" rtk ls src/ scripts/
assert_contains "rtk ls -a shows hidden" ".git" rtk ls -a .
assert_contains "rtk ls shows sizes" "K" rtk ls src/
assert_contains "rtk ls shows dirs with /" "/" rtk ls .
# ── 2b. Tree ─────────────────────────────────────────
section "Tree"
if command -v tree >/dev/null 2>&1; then
assert_ok "rtk tree ." rtk tree .
assert_ok "rtk tree -L 2 ." rtk tree -L 2 .
assert_ok "rtk tree -d -L 1 ." rtk tree -d -L 1 .
assert_contains "rtk tree shows src/" "src" rtk tree -L 1 .
else
skip_test "rtk tree" "tree not installed"
fi
# ── 3. Read ──────────────────────────────────────────
section "Read"
assert_ok "rtk read Cargo.toml" rtk read Cargo.toml
assert_ok "rtk read --level none Cargo.toml" rtk read --level none Cargo.toml
assert_ok "rtk read --level aggressive Cargo.toml" rtk read --level aggressive Cargo.toml
assert_ok "rtk read -n Cargo.toml" rtk read -n Cargo.toml
assert_ok "rtk read --max-lines 5 Cargo.toml" rtk read --max-lines 5 Cargo.toml
section "Read (stdin support)"
assert_ok "rtk read stdin pipe" bash -c 'echo "fn main() {}" | rtk read -'
# ── 4. Git ───────────────────────────────────────────
section "Git (existing)"
assert_ok "rtk git status" rtk git status
assert_ok "rtk git status --short" rtk git status --short
assert_ok "rtk git status -s" rtk git status -s
assert_ok "rtk git status --porcelain" rtk git status --porcelain
assert_ok "rtk git log" rtk git log
assert_ok "rtk git log -5" rtk git log -- -5
assert_ok "rtk git diff" rtk git diff
assert_ok "rtk git diff --stat" rtk git diff --stat
section "Git (new: branch, fetch, stash, worktree)"
assert_ok "rtk git branch" rtk git branch
assert_ok "rtk git fetch" rtk git fetch
assert_ok "rtk git stash list" rtk git stash list
assert_ok "rtk git worktree" rtk git worktree
section "Git (passthrough: unsupported subcommands)"
assert_ok "rtk git tag --list" rtk git tag --list
assert_ok "rtk git remote -v" rtk git remote -v
assert_ok "rtk git rev-parse HEAD" rtk git rev-parse HEAD
# ── 5. GitHub CLI ────────────────────────────────────
section "GitHub CLI"
if command -v gh >/dev/null 2>&1 && gh auth status >/dev/null 2>&1; then
assert_ok "rtk gh pr list" rtk gh pr list
assert_ok "rtk gh run list" rtk gh run list
assert_ok "rtk gh issue list" rtk gh issue list
# pr create/merge/diff/comment/edit are write ops, test help only
assert_help "rtk gh" rtk gh
else
skip_test "gh commands" "gh not authenticated"
fi
# ── 6. Cargo ─────────────────────────────────────────
section "Cargo (new)"
assert_ok "rtk cargo build" rtk cargo build
assert_ok "rtk cargo clippy" rtk cargo clippy
# cargo test exits non-zero due to pre-existing failures; check output ignoring exit code
output_cargo_test=$(rtk cargo test 2>&1 || true)
if echo "$output_cargo_test" | grep -q "FAILURES\|test result:\|passed"; then
PASS=$((PASS + 1))
printf " ${GREEN}PASS${NC} %s\n" "rtk cargo test"
else
FAIL=$((FAIL + 1))
FAILURES+=("rtk cargo test")
printf " ${RED}FAIL${NC} %s\n" "rtk cargo test"
printf " got: %s\n" "$(echo "$output_cargo_test" | head -3)"
fi
assert_help "rtk cargo" rtk cargo
# ── 7. Curl ──────────────────────────────────────────
section "Curl (new)"
assert_contains "rtk curl JSON detect" "string" rtk curl https://httpbin.org/json
assert_ok "rtk curl plain text" rtk curl https://httpbin.org/robots.txt
assert_help "rtk curl" rtk curl
# ── 8. Npm / Npx ────────────────────────────────────
section "Npm / Npx (new)"
assert_help "rtk npm" rtk npm
assert_help "rtk npx" rtk npx
# ── 9. Pnpm ─────────────────────────────────────────
section "Pnpm"
assert_help "rtk pnpm" rtk pnpm
assert_help "rtk pnpm build" rtk pnpm build
assert_help "rtk pnpm typecheck" rtk pnpm typecheck
if command -v pnpm >/dev/null 2>&1; then
assert_ok "rtk pnpm help" rtk pnpm help
fi
# ── 10. Grep ─────────────────────────────────────────
section "Grep"
assert_ok "rtk grep pattern" rtk grep "pub fn" src/
assert_contains "rtk grep finds results" "pub fn" rtk grep "pub fn" src/
assert_ok "rtk grep with file type" rtk grep "pub fn" src/ -t rust
section "Grep (extra args passthrough)"
assert_ok "rtk grep -i case insensitive" rtk grep "fn" src/ -i
assert_ok "rtk grep -A context lines" rtk grep "fn run" src/ -A 2
# ── 11. Find ─────────────────────────────────────────
section "Find"
assert_ok "rtk find *.rs" rtk find "*.rs" src/
assert_contains "rtk find shows files" ".rs" rtk find "*.rs" src/
# ── 12. Json ─────────────────────────────────────────
section "Json"
# Create temp JSON file for testing
TMPJSON=$(mktemp /tmp/rtk-test-XXXXX.json)
echo '{"name":"test","count":42,"items":[1,2,3]}' > "$TMPJSON"
assert_ok "rtk json file" rtk json "$TMPJSON"
assert_contains "rtk json shows schema" "string" rtk json "$TMPJSON"
rm -f "$TMPJSON"
# ── 13. Deps ─────────────────────────────────────────
section "Deps"
assert_ok "rtk deps ." rtk deps .
assert_contains "rtk deps shows Cargo" "Cargo" rtk deps .
# ── 14. Env ──────────────────────────────────────────
section "Env"
assert_ok "rtk env" rtk env
assert_ok "rtk env --filter PATH" rtk env --filter PATH
# ── 16. Log ──────────────────────────────────────────
section "Log"
TMPLOG=$(mktemp /tmp/rtk-log-XXXXX.log)
for i in $(seq 1 20); do
echo "[2025-01-01 12:00:00] INFO: repeated message" >> "$TMPLOG"
done
echo "[2025-01-01 12:00:01] ERROR: something failed" >> "$TMPLOG"
assert_ok "rtk log file" rtk log "$TMPLOG"
rm -f "$TMPLOG"
# ── 17. Summary ──────────────────────────────────────
section "Summary"
assert_ok "rtk summary echo hello" rtk summary echo hello
# ── 18. Err ──────────────────────────────────────────
section "Err"
assert_ok "rtk err echo ok" rtk err echo ok
# ── 19. Test runner ──────────────────────────────────
section "Test runner"
assert_ok "rtk test echo ok" rtk test echo ok
# ── 20. Gain ─────────────────────────────────────────
section "Gain"
assert_ok "rtk gain" rtk gain
assert_ok "rtk gain --history" rtk gain --history
# ── 21. Config & Init ────────────────────────────────
section "Config & Init"
assert_ok "rtk config" rtk config
assert_ok "rtk init --show" rtk init --show
# ── 22. Wget ─────────────────────────────────────────
section "Wget"
if command -v wget >/dev/null 2>&1; then
assert_ok "rtk wget stdout" rtk wget https://httpbin.org/robots.txt -O
else
skip_test "rtk wget" "wget not installed"
fi
# ── 23. Tsc / Lint / Prettier / Next / Playwright ───
section "JS Tooling (help only, no project context)"
assert_help "rtk tsc" rtk tsc
assert_help "rtk lint" rtk lint
assert_help "rtk prettier" rtk prettier
assert_help "rtk next" rtk next
assert_help "rtk playwright" rtk playwright
# ── 24. Prisma ───────────────────────────────────────
section "Prisma (help only)"
assert_help "rtk prisma" rtk prisma
# ── 25. Vitest ───────────────────────────────────────
section "Vitest (help only)"
assert_help "rtk vitest" rtk vitest
# ── 26. Docker / Kubectl (help only) ────────────────
section "Docker / Kubectl (help only)"
assert_help "rtk docker" rtk docker
assert_help "rtk kubectl" rtk kubectl
# ── 27. Python (conditional) ────────────────────────
section "Python (conditional)"
if command -v pytest &>/dev/null; then
assert_help "rtk pytest" rtk pytest --help
else
skip_test "rtk pytest" "pytest not installed"
fi
if command -v ruff &>/dev/null; then
assert_help "rtk ruff" rtk ruff --help
else
skip_test "rtk ruff" "ruff not installed"
fi
if command -v pip &>/dev/null; then
assert_help "rtk pip" rtk pip --help
else
skip_test "rtk pip" "pip not installed"
fi
# ── 28. Go (conditional) ────────────────────────────
section "Go (conditional)"
if command -v go &>/dev/null; then
assert_help "rtk go" rtk go --help
assert_help "rtk go test" rtk go test -h
assert_help "rtk go build" rtk go build -h
assert_help "rtk go vet" rtk go vet -h
else
skip_test "rtk go" "go not installed"
fi
if command -v golangci-lint &>/dev/null; then
assert_help "rtk golangci-lint" rtk golangci-lint --help
else
skip_test "rtk golangci-lint" "golangci-lint not installed"
fi
# ── 29. Graphite (conditional) ─────────────────────
section "Graphite (conditional)"
if command -v gt &>/dev/null; then
assert_help "rtk gt" rtk gt --help
assert_ok "rtk gt log short" rtk gt log short
else
skip_test "rtk gt" "gt not installed"
fi
# ── 30. Ruby (conditional) ──────────────────────────
section "Ruby (conditional)"
if command -v rspec &>/dev/null; then
assert_help "rtk rspec" rtk rspec --help
else
skip_test "rtk rspec" "rspec not installed"
fi
if command -v rubocop &>/dev/null; then
assert_help "rtk rubocop" rtk rubocop --help
else
skip_test "rtk rubocop" "rubocop not installed"
fi
if command -v rake &>/dev/null; then
assert_help "rtk rake" rtk rake --help
else
skip_test "rtk rake" "rake not installed"
fi
# ── 31. Global flags ────────────────────────────────
section "Global flags"
assert_ok "rtk -u ls ." rtk -u ls .
assert_ok "rtk --skip-env npm --help" rtk --skip-env npm --help
# ── 32. CcEconomics ─────────────────────────────────
section "CcEconomics"
assert_ok "rtk cc-economics" rtk cc-economics
# ── 33. Learn ───────────────────────────────────────
section "Learn"
assert_ok "rtk learn --help" rtk learn --help
assert_ok "rtk learn (no sessions)" rtk learn --since 0 2>&1 || true
# ── 32. Rewrite ───────────────────────────────────────
section "Rewrite"
assert_contains "rewrite git status" "rtk git status" rtk rewrite "git status"
assert_contains "rewrite cargo test" "rtk cargo test" rtk rewrite "cargo test"
assert_contains "rewrite compound &&" "rtk git status" rtk rewrite "git status && cargo test"
assert_contains "rewrite pipe preserves" "| head" rtk rewrite "git log | head"
section "Rewrite (#345: RTK_DISABLED skip)"
assert_fails "rewrite RTK_DISABLED=1 skip" rtk rewrite "RTK_DISABLED=1 git status"
assert_fails "rewrite env RTK_DISABLED skip" rtk rewrite "FOO=1 RTK_DISABLED=1 cargo test"
section "Rewrite (#346: 2>&1 preserved)"
assert_contains "rewrite 2>&1 preserved" "2>&1" rtk rewrite "cargo test 2>&1 | head"
section "Rewrite (#196: gh --json skip)"
assert_fails "rewrite gh --json skip" rtk rewrite "gh pr list --json number"
assert_fails "rewrite gh --jq skip" rtk rewrite "gh api /repos --jq .name"
assert_fails "rewrite gh --template skip" rtk rewrite "gh pr view 1 --template '{{.title}}'"
assert_contains "rewrite gh normal works" "rtk gh pr list" rtk rewrite "gh pr list"
# ── 33. Verify ────────────────────────────────────────
section "Verify"
assert_ok "rtk verify" rtk verify
# ── 34. Proxy ─────────────────────────────────────────
section "Proxy"
assert_ok "rtk proxy echo hello" rtk proxy echo hello
assert_contains "rtk proxy passthrough" "hello" rtk proxy echo hello
# ── 35. Discover ──────────────────────────────────────
section "Discover"
assert_ok "rtk discover" rtk discover
# ── 36. Diff ──────────────────────────────────────────
section "Diff"
assert_ok "rtk diff two files" rtk diff Cargo.toml LICENSE
# ── 37. Wc ────────────────────────────────────────────
section "Wc"
assert_ok "rtk wc Cargo.toml" rtk wc Cargo.toml
# ── 38. Smart ─────────────────────────────────────────
section "Smart"
assert_ok "rtk smart src/main.rs" rtk smart src/main.rs
# ── 39. Json edge cases ──────────────────────────────
section "Json (edge cases)"
assert_fails "rtk json on TOML (#347)" rtk json Cargo.toml
# ── 40. Docker (conditional) ─────────────────────────
section "Docker (conditional)"
if command -v docker >/dev/null 2>&1 && docker info >/dev/null 2>&1; then
assert_ok "rtk docker ps" rtk docker ps
assert_ok "rtk docker images" rtk docker images
else
skip_test "rtk docker" "docker not running"
fi
# ── 41. Hook check ───────────────────────────────────
section "Hook check (#344)"
assert_contains "rtk init --show hook version" "version" rtk init --show
# ══════════════════════════════════════════════════════
# Report
# ══════════════════════════════════════════════════════
printf "\n${BOLD}══════════════════════════════════════${NC}\n"
printf "${BOLD}Results: ${GREEN}%d passed${NC}, ${RED}%d failed${NC}, ${YELLOW}%d skipped${NC}\n" "$PASS" "$FAIL" "$SKIP"
if [[ ${#FAILURES[@]} -gt 0 ]]; then
printf "\n${RED}Failures:${NC}\n"
for f in "${FAILURES[@]}"; do
printf " - %s\n" "$f"
done
fi
printf "${BOLD}══════════════════════════════════════${NC}\n"
exit "$FAIL"