-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathjustfile
More file actions
1239 lines (1064 loc) · 47.9 KB
/
Copy pathjustfile
File metadata and controls
1239 lines (1064 loc) · 47.9 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
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
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# rust-expect Justfile
# https://just.systems/man/en/
#
# Usage: just [recipe] [arguments...]
# Run `just help` for available recipes
# ============================================================================
# PROJECT CONFIGURATION
# ============================================================================
# Project metadata (from Cargo.toml)
project_name := "rust-expect"
version := `grep -m1 '^version = ' Cargo.toml | sed -E 's/.*"([^"]+)".*/\1/'`
msrv := "1.88"
edition := "2024"
# Main crate for default operations
main_crate := "rust-expect"
# Parallel job count (use all available cores)
jobs := `nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 4`
# ============================================================================
# FEATURE CONFIGURATION
# ============================================================================
# Control feature flags via environment variable:
# just test # all features (default, comprehensive)
# FEATURES=none just test # default features only (fast)
# FEATURES=ssh,screen just test # specific features
features := env_var_or_default("FEATURES", "all")
_ff := if features == "all" { "--all-features" } else if features == "none" { "" } else { "--features " + features }
# ============================================================================
# PLATFORM DETECTION
# ============================================================================
# Detect platform for platform-specific commands
platform := if os() == "macos" { "macos" } else if os() == "windows" { "windows" } else { "linux" }
# Open command varies by platform
open_cmd := if os() == "macos" { "open" } else if os() == "windows" { "start" } else { "xdg-open" }
# Docker command (podman compatibility)
docker := if `command -v podman 2>/dev/null || echo ""` != "" { "podman" } else { "docker" }
# Cargo command (allow override for cross-compilation)
cargo := env_var_or_default("CARGO", "cargo")
# ============================================================================
# TERMINAL COLORS
# ============================================================================
# ANSI color codes for pretty output
reset := '\033[0m'
bold := '\033[1m'
red := '\033[31m'
green := '\033[32m'
yellow := '\033[33m'
blue := '\033[34m'
cyan := '\033[36m'
# ============================================================================
# DEFAULT RECIPE
# ============================================================================
# Default recipe: show help
@_default:
just help
# ============================================================================
# SETUP RECIPES
# ============================================================================
[group('setup')]
[doc("Full development environment bootstrap (system packages + tools + hooks)")]
bootstrap: setup-system setup-tools setup-hooks
@printf '{{green}}[OK]{{reset}} Development environment bootstrapped\n'
[group('setup')]
[doc("Install system packages (platform-specific)")]
setup-system:
#!/usr/bin/env bash
set -euo pipefail
printf '{{cyan}}[INFO]{{reset}} Installing system packages for {{platform}}...\n'
case "{{platform}}" in
linux)
if command -v apt-get &> /dev/null; then
printf '{{cyan}}[INFO]{{reset}} Debian/Ubuntu detected\n'
# SSH feature requires OpenSSL dev headers
sudo apt-get update
sudo apt-get install -y build-essential pkg-config libssl-dev
elif command -v dnf &> /dev/null; then
printf '{{cyan}}[INFO]{{reset}} Fedora/RHEL detected\n'
sudo dnf install -y gcc openssl-devel
elif command -v pacman &> /dev/null; then
printf '{{cyan}}[INFO]{{reset}} Arch Linux detected\n'
sudo pacman -S --noconfirm base-devel openssl
else
printf '{{yellow}}[WARN]{{reset}} Unknown Linux distribution, skipping system packages\n'
fi
;;
macos)
printf '{{cyan}}[INFO]{{reset}} macOS detected\n'
if ! command -v brew &> /dev/null; then
printf '{{yellow}}[WARN]{{reset}} Homebrew not installed, skipping system packages\n'
else
brew install openssl pkg-config || true
fi
;;
windows)
printf '{{cyan}}[INFO]{{reset}} Windows detected\n'
printf '{{yellow}}[WARN]{{reset}} Install Visual Studio Build Tools manually if needed\n'
;;
esac
printf '{{green}}[OK]{{reset}} System packages ready\n'
[group('setup')]
[doc("Install Rust development tools")]
setup-tools:
#!/usr/bin/env bash
set -euo pipefail
printf '{{cyan}}[INFO]{{reset}} Installing Rust development tools...\n'
# Core tools (nightly rustfmt for unstable options like imports_granularity)
rustup component add clippy
rustup toolchain install nightly --component rustfmt --profile minimal
printf '{{cyan}}[INFO]{{reset}} Using nightly rustfmt for import grouping support\n'
# Optional but recommended tools
TOOLS=(
"cargo-nextest" # Faster test runner
"cargo-watch" # File watcher
"cargo-audit" # Security audit
"cargo-deny" # License/advisory checks
"cargo-outdated" # Dependency updates
"cargo-machete" # Unused dependency detection
"cargo-semver-checks" # Semver verification
"typos-cli" # Spell checker
"git-cliff" # Changelog generator
)
for tool in "${TOOLS[@]}"; do
if ! command -v "${tool//-/_}" &> /dev/null && ! cargo install --list | grep -q "^$tool "; then
printf '{{cyan}}[INFO]{{reset}} Installing %s...\n' "$tool"
cargo install "$tool" --locked 2>/dev/null || printf '{{yellow}}[WARN]{{reset}} Failed to install %s (optional)\n' "$tool"
fi
done
printf '{{green}}[OK]{{reset}} Development tools installed\n'
[group('setup')]
[doc("Install Git hooks for pre-commit checks")]
setup-hooks:
#!/usr/bin/env bash
set -euo pipefail
printf '{{cyan}}[INFO]{{reset}} Installing Git hooks...\n'
# Create hooks directory if needed
mkdir -p .git/hooks
# Pre-commit hook
printf '#!/bin/bash\nset -e\njust pre-commit\n' > .git/hooks/pre-commit
chmod +x .git/hooks/pre-commit
# Pre-push hook
printf '#!/bin/bash\nset -e\njust pre-push\n' > .git/hooks/pre-push
chmod +x .git/hooks/pre-push
printf '{{green}}[OK]{{reset}} Git hooks installed\n'
[group('setup')]
[doc("Check development environment and installed tools")]
setup:
#!/usr/bin/env bash
set -euo pipefail
printf '\n{{bold}}{{blue}}══════ Development Environment ══════{{reset}}\n\n'
# Required tools
printf '{{bold}}Required:{{reset}}\n'
printf ' Rust: %s\n' "$(rustc --version 2>/dev/null || echo '❌ not found')"
printf ' Cargo: %s\n' "$(cargo --version 2>/dev/null || echo '❌ not found')"
printf ' Rustfmt: %s\n' "$(rustfmt --version 2>/dev/null || echo '❌ not found')"
printf ' Clippy: %s\n' "$(cargo clippy --version 2>/dev/null || echo '❌ not found')"
# Optional tools
printf '\n{{bold}}Optional:{{reset}}\n'
for tool in cargo-nextest cargo-watch cargo-audit cargo-deny cargo-outdated cargo-machete cargo-semver-checks typos git-cliff; do
if command -v "$tool" &> /dev/null || cargo install --list | grep -q "^$tool "; then
printf ' ✅ %s\n' "$tool"
else
printf ' ⬚ %s (install with: cargo install %s)\n' "$tool" "$tool"
fi
done
printf '\n{{green}}[OK]{{reset}} Environment check complete\n'
# ============================================================================
# BUILD RECIPES
# ============================================================================
[group('build')]
[doc("Build workspace (use FEATURES=none for fast builds)")]
build:
#!/usr/bin/env bash
set -euo pipefail
printf '{{cyan}}[INFO]{{reset}} Building workspace (features={{features}})...\n'
{{cargo}} build --workspace {{_ff}} -j {{jobs}}
printf '{{green}}[OK]{{reset}} Build complete\n'
[group('build')]
[doc("Check workspace compiles (use FEATURES=none for fast checks)")]
check:
#!/usr/bin/env bash
set -euo pipefail
printf '{{cyan}}[INFO]{{reset}} Checking workspace (features={{features}})...\n'
{{cargo}} check --workspace {{_ff}} -j {{jobs}}
printf '{{green}}[OK]{{reset}} Check complete\n'
[group('build')]
[doc("Build in release mode")]
build-release:
#!/usr/bin/env bash
set -euo pipefail
printf '{{cyan}}[INFO]{{reset}} Building workspace (release, features={{features}})...\n'
{{cargo}} build --workspace --release {{_ff}} -j {{jobs}}
printf '{{green}}[OK]{{reset}} Release build complete\n'
[group('build')]
[doc("Check MSRV compliance")]
msrv-check:
#!/usr/bin/env bash
set -euo pipefail
printf '{{cyan}}[INFO]{{reset}} Checking MSRV ({{msrv}}) compliance (features={{features}})...\n'
# Check if MSRV toolchain is installed
if ! rustup run {{msrv}} cargo --version &> /dev/null; then
printf '{{yellow}}[WARN]{{reset}} Installing Rust {{msrv}}...\n'
rustup install {{msrv}}
fi
rustup run {{msrv}} cargo check --workspace {{_ff}}
printf '{{green}}[OK]{{reset}} MSRV check passed ({{msrv}})\n'
# ============================================================================
# TEST RECIPES
# ============================================================================
[group('test')]
[doc("Run tests")]
test:
#!/usr/bin/env bash
set -euo pipefail
printf '{{cyan}}[INFO]{{reset}} Running tests (features={{features}})...\n'
{{cargo}} test --workspace {{_ff}} -j {{jobs}}
printf '{{green}}[OK]{{reset}} Tests passed\n'
[group('test')]
[doc("Run tests with nextest (faster, better output)")]
nextest:
#!/usr/bin/env bash
set -euo pipefail
printf '{{cyan}}[INFO]{{reset}} Running tests with nextest (features={{features}})...\n'
{{cargo}} nextest run --workspace {{_ff}} -j {{jobs}}
printf '{{green}}[OK]{{reset}} Tests passed\n'
[group('test')]
[doc("Run tests with nextest using locked deps (CI mode)")]
nextest-locked:
#!/usr/bin/env bash
set -euo pipefail
printf '{{cyan}}[INFO]{{reset}} Running tests with nextest (locked, features={{features}})...\n'
{{cargo}} nextest run --workspace {{_ff}} --locked -j {{jobs}}
printf '{{green}}[OK]{{reset}} Tests passed\n'
[group('test')]
[doc("Run a specific test by name")]
test-one name:
#!/usr/bin/env bash
set -euo pipefail
printf '{{cyan}}[INFO]{{reset}} Running test: {{name}}\n'
{{cargo}} test --workspace {{_ff}} -- "{{name}}" --nocapture
printf '{{green}}[OK]{{reset}} Test passed\n'
[group('test')]
[doc("Run tests for specific feature")]
test-feature feature:
#!/usr/bin/env bash
set -euo pipefail
printf '{{cyan}}[INFO]{{reset}} Running tests for feature: {{feature}}\n'
{{cargo}} test -p {{main_crate}} --features "{{feature}}" -j {{jobs}}
printf '{{green}}[OK]{{reset}} Tests passed\n'
[group('test')]
[doc("Test all feature combinations")]
test-features:
#!/usr/bin/env bash
set -euo pipefail
printf '{{cyan}}[INFO]{{reset}} Testing feature combinations...\n'
# Individual features
for feature in ssh mock screen pii-redaction metrics test-utils; do
printf '{{cyan}}[INFO]{{reset}} Testing feature: %s\n' "$feature"
{{cargo}} test -p {{main_crate}} --features "$feature" --no-fail-fast || exit 1
done
# Combined features
printf '{{cyan}}[INFO]{{reset}} Testing: ssh + screen\n'
{{cargo}} test -p {{main_crate}} --features "ssh screen" --no-fail-fast
printf '{{cyan}}[INFO]{{reset}} Testing: full\n'
{{cargo}} test -p {{main_crate}} --features full --no-fail-fast
printf '{{green}}[OK]{{reset}} All feature combinations passed\n'
[group('test')]
[doc("Check feature flag configuration")]
check-feature-flags:
#!/usr/bin/env bash
set -euo pipefail
printf '{{cyan}}[INFO]{{reset}} Checking feature flags...\n'
# Check each feature compiles independently
for feature in ssh mock screen pii-redaction metrics test-utils legacy-encoding; do
printf '{{cyan}}[INFO]{{reset}} Checking feature: %s\n' "$feature"
{{cargo}} check -p {{main_crate}} --features "$feature" || exit 1
done
# Check full feature set
printf '{{cyan}}[INFO]{{reset}} Checking feature: full\n'
{{cargo}} check -p {{main_crate}} --features full
# Check dangerous feature (insecure-skip-verify)
printf '{{cyan}}[INFO]{{reset}} Checking feature: ssh + insecure-skip-verify\n'
{{cargo}} check -p {{main_crate}} --features "ssh insecure-skip-verify"
printf '{{green}}[OK]{{reset}} All feature flags valid\n'
# ============================================================================
# LINT RECIPES
# ============================================================================
[group('lint')]
[doc("Format code with rustfmt (uses nightly for import grouping)")]
fmt:
#!/usr/bin/env bash
set -euo pipefail
printf '{{cyan}}[INFO]{{reset}} Formatting code (nightly rustfmt)...\n'
cargo +nightly fmt --all
printf '{{green}}[OK]{{reset}} Code formatted\n'
[group('lint')]
[doc("Check formatting without modifying files (uses nightly for import grouping)")]
fmt-check:
#!/usr/bin/env bash
set -euo pipefail
printf '{{cyan}}[INFO]{{reset}} Checking code formatting (nightly rustfmt)...\n'
cargo +nightly fmt --all -- --check
printf '{{green}}[OK]{{reset}} Formatting check passed\n'
[group('lint')]
[doc("Run clippy lints")]
clippy:
#!/usr/bin/env bash
set -euo pipefail
printf '{{cyan}}[INFO]{{reset}} Running clippy (features={{features}})...\n'
{{cargo}} clippy --workspace --all-targets {{_ff}} -- -D warnings
printf '{{green}}[OK]{{reset}} Clippy passed\n'
[group('lint')]
[doc("Run clippy and automatically fix issues")]
clippy-fix:
#!/usr/bin/env bash
set -euo pipefail
printf '{{cyan}}[INFO]{{reset}} Running clippy with auto-fix (features={{features}})...\n'
{{cargo}} clippy --workspace --all-targets {{_ff}} --fix --allow-dirty --allow-staged
printf '{{green}}[OK]{{reset}} Clippy fixes applied\n'
[group('lint')]
[doc("Run security audit on dependencies")]
audit:
#!/usr/bin/env bash
set -euo pipefail
printf '{{cyan}}[INFO]{{reset}} Running security audit...\n'
{{cargo}} audit
printf '{{green}}[OK]{{reset}} Security audit passed\n'
[group('lint')]
[doc("Run cargo-deny checks (licenses, advisories, sources)")]
deny:
#!/usr/bin/env bash
set -euo pipefail
printf '{{cyan}}[INFO]{{reset}} Running cargo-deny checks...\n'
{{cargo}} deny check
printf '{{green}}[OK]{{reset}} Cargo-deny passed\n'
[group('lint')]
[doc("Detect unused dependencies")]
machete:
#!/usr/bin/env bash
set -euo pipefail
printf '{{cyan}}[INFO]{{reset}} Checking for unused dependencies...\n'
{{cargo}} machete
printf '{{green}}[OK]{{reset}} No unused dependencies found\n'
[group('lint')]
[doc("Run semver compatibility check")]
semver:
#!/usr/bin/env bash
set -euo pipefail
printf '{{cyan}}[INFO]{{reset}} Checking semver compatibility...\n'
# `cargo semver-checks` enforces strict semver, treating any API break as
# requiring a major bump. RELEASING.md §Version Numbering allows breaking
# changes in MINOR pre-1.0 bumps, matching Cargo's pre-1.0 carve-out. When
# the workspace version is 0.x.y, this recipe surfaces detected breaks but
# treats them as advisory rather than a release blocker — operators are
# responsible for confirming the CHANGELOG documents them. Once the project
# ships 1.0.0, strict semver applies and any detected break is a hard fail.
pre_one=$(grep -E '^version = "0\.' Cargo.toml >/dev/null && echo 1 || echo 0)
if [ "$pre_one" = "1" ]; then
{{cargo}} semver-checks check-release --release-type minor --only-explicit-features || {
printf '{{yellow}}[WARN]{{reset}} semver-checks reported API breaks; pre-1.0 minor bumps allow these.\n'
printf '{{yellow}}[WARN]{{reset}} Confirm each break is documented under the new version in CHANGELOG.md before releasing.\n'
exit 0
}
else
{{cargo}} semver-checks check-release
fi
printf '{{green}}[OK]{{reset}} Semver check passed\n'
[group('lint')]
[doc("Run all lints (fmt + clippy)")]
lint: fmt-check clippy
@printf '{{green}}[OK]{{reset}} All lints passed\n'
# ============================================================================
# DOCUMENTATION RECIPES
# ============================================================================
[group('docs')]
[doc("Build documentation")]
doc:
#!/usr/bin/env bash
set -euo pipefail
printf '{{cyan}}[INFO]{{reset}} Building documentation (features={{features}})...\n'
{{cargo}} doc --workspace --no-deps {{_ff}}
printf '{{green}}[OK]{{reset}} Documentation built: target/doc/{{main_crate}}/index.html\n'
[group('docs')]
[doc("Build documentation and check for warnings")]
doc-check:
#!/usr/bin/env bash
set -euo pipefail
printf '{{cyan}}[INFO]{{reset}} Checking documentation (features={{features}})...\n'
RUSTDOCFLAGS="-D warnings" {{cargo}} doc --workspace --no-deps {{_ff}}
printf '{{green}}[OK]{{reset}} Documentation check passed\n'
[group('docs')]
[doc("Build and open documentation in browser")]
doc-open: doc
#!/usr/bin/env bash
set -euo pipefail
printf '{{cyan}}[INFO]{{reset}} Opening documentation in browser...\n'
{{open_cmd}} target/doc/{{main_crate}}/index.html
# ============================================================================
# COVERAGE RECIPES
# ============================================================================
[group('coverage')]
[doc("Generate test coverage report (HTML)")]
coverage:
#!/usr/bin/env bash
set -euo pipefail
printf '{{cyan}}[INFO]{{reset}} Generating coverage report (features={{features}})...\n'
{{cargo}} llvm-cov --workspace {{_ff}} --html
printf '{{green}}[OK]{{reset}} Coverage report: target/llvm-cov/html/index.html\n'
[group('coverage')]
[doc("Generate coverage in LCOV format (for CI)")]
coverage-lcov:
#!/usr/bin/env bash
set -euo pipefail
printf '{{cyan}}[INFO]{{reset}} Generating coverage report (LCOV, features={{features}})...\n'
{{cargo}} llvm-cov --workspace {{_ff}} --lcov --output-path lcov.info
printf '{{green}}[OK]{{reset}} Coverage report: lcov.info\n'
[group('coverage')]
[doc("Open coverage report in browser")]
coverage-open: coverage
#!/usr/bin/env bash
set -euo pipefail
printf '{{cyan}}[INFO]{{reset}} Opening coverage report in browser...\n'
{{open_cmd}} target/llvm-cov/html/index.html
# ============================================================================
# BENCHMARK RECIPES
# ============================================================================
[group('bench')]
[doc("Run all benchmarks")]
bench:
#!/usr/bin/env bash
set -euo pipefail
printf '{{cyan}}[INFO]{{reset}} Running benchmarks...\n'
{{cargo}} bench -p {{main_crate}} --features full
printf '{{green}}[OK]{{reset}} Benchmarks complete\n'
[group('bench')]
[doc("Run pattern matching benchmarks")]
bench-patterns:
#!/usr/bin/env bash
set -euo pipefail
printf '{{cyan}}[INFO]{{reset}} Running pattern matching benchmarks...\n'
{{cargo}} bench -p {{main_crate}} --bench pattern_matching
printf '{{green}}[OK]{{reset}} Pattern benchmarks complete\n'
[group('bench')]
[doc("Run screen buffer benchmarks")]
bench-screen:
#!/usr/bin/env bash
set -euo pipefail
printf '{{cyan}}[INFO]{{reset}} Running screen buffer benchmarks...\n'
{{cargo}} bench -p {{main_crate}} --features screen --bench screen_buffer
printf '{{green}}[OK]{{reset}} Screen benchmarks complete\n'
[group('bench')]
[doc("Run comparative benchmarks (vs expectrl)")]
bench-compare:
#!/usr/bin/env bash
set -euo pipefail
printf '{{cyan}}[INFO]{{reset}} Running comparative benchmarks...\n'
{{cargo}} bench -p {{main_crate}} --bench comparative
printf '{{green}}[OK]{{reset}} Comparative benchmarks complete\n'
# ============================================================================
# EXAMPLES
# ============================================================================
[group('examples')]
[doc("Run a specific example")]
example name:
#!/usr/bin/env bash
set -euo pipefail
printf '{{cyan}}[INFO]{{reset}} Running example: {{name}} (features={{features}})\n'
{{cargo}} run -p {{main_crate}} --example "{{name}}" {{_ff}}
printf '{{green}}[OK]{{reset}} Example complete\n'
[group('examples')]
[doc("Build all examples")]
examples:
#!/usr/bin/env bash
set -euo pipefail
printf '{{cyan}}[INFO]{{reset}} Building examples (features={{features}})...\n'
{{cargo}} build -p {{main_crate}} --examples {{_ff}}
printf '{{green}}[OK]{{reset}} Examples built\n'
[group('examples')]
[doc("List available examples")]
examples-list:
#!/usr/bin/env bash
set -euo pipefail
printf '{{bold}}Available Examples:{{reset}}\n\n'
printf '{{cyan}}Default Features:{{reset}}\n'
printf ' basic - Core spawn/expect workflow\n'
printf ' dialog - Dialog-based automation\n'
printf ' patterns - Pattern matching capabilities\n'
printf ' transcript - Recording and playback\n'
printf ' interactive - Interactive terminal mode\n'
printf ' multi_session - Managing multiple sessions\n'
printf ' sync_api - Synchronous API usage\n'
printf '\n{{cyan}}Feature-Gated:{{reset}}\n'
printf ' screen_buffer - VT100 emulation (screen)\n'
printf ' pii_redaction - Sensitive data masking (pii-redaction)\n'
printf ' ssh - SSH session concepts (ssh)\n'
printf ' mock_testing - Mock backend for testing (mock)\n'
printf ' metrics - Prometheus/OpenTelemetry (metrics)\n'
printf '\n{{cyan}}Usage:{{reset}} just example <name>\n'
# ============================================================================
# DEVELOPMENT WORKFLOW RECIPES
# ============================================================================
[group('dev')]
[doc("Full development check (build + test + lint)")]
dev: build test lint
@printf '{{green}}[OK]{{reset}} Development checks passed\n'
[group('dev')]
[no-exit-message]
[doc("Watch mode: re-run tests on file changes")]
watch:
#!/usr/bin/env bash
set -euo pipefail
printf '{{cyan}}[INFO]{{reset}} Watching for changes (tests, features={{features}})...\n'
{{cargo}} watch -x "test --workspace {{_ff}}"
[group('dev')]
[no-exit-message]
[doc("Watch mode: re-run check on file changes")]
watch-check:
#!/usr/bin/env bash
set -euo pipefail
printf '{{cyan}}[INFO]{{reset}} Watching for changes (check, features={{features}})...\n'
{{cargo}} watch -x "check --workspace {{_ff}}"
[group('dev')]
[no-exit-message]
[doc("Watch mode: re-run clippy on file changes")]
watch-clippy:
#!/usr/bin/env bash
set -euo pipefail
printf '{{cyan}}[INFO]{{reset}} Watching for changes (clippy, features={{features}})...\n'
{{cargo}} watch -x "clippy --workspace --all-targets {{_ff}}"
# ============================================================================
# CI/CD RECIPES
# ============================================================================
[group('ci')]
[doc("Check documentation versions match Cargo.toml")]
version-sync:
#!/usr/bin/env bash
set -euo pipefail
printf '{{cyan}}[INFO]{{reset}} Checking version sync...\n'
VERSION=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[] | select(.name == "{{main_crate}}") | .version')
MAJOR_MINOR=$(echo "$VERSION" | cut -d. -f1,2)
# Check README.md
if ! grep -q "rust-expect = \"$MAJOR_MINOR\"" README.md 2>/dev/null; then
printf '{{yellow}}[WARN]{{reset}} README.md may need version update (expected %s)\n' "$MAJOR_MINOR"
fi
printf '{{green}}[OK]{{reset}} Version sync check complete (v%s)\n' "$VERSION"
[group('ci')]
[doc("Standard CI pipeline (fmt + clippy + test + doc + examples)")]
ci: fmt-check clippy nextest-locked doc-check examples
#!/usr/bin/env bash
set -euo pipefail
printf '\n{{bold}}{{blue}}══════ CI Pipeline Complete (features={{features}}) ══════{{reset}}\n\n'
printf '{{green}}[OK]{{reset}} All CI checks passed\n'
[group('ci')]
[doc("Quick verification: fmt + clippy + check (no tests, fastest feedback)")]
quick: fmt-check clippy check
@printf '{{green}}[OK]{{reset}} Quick checks passed\n'
[group('ci')]
[doc("Fast CI checks (no tests)")]
ci-fast: fmt-check clippy check
@printf '{{green}}[OK]{{reset}} Fast CI checks passed\n'
[group('ci')]
[doc("Full CI with coverage and security audit")]
ci-full: ci coverage-lcov audit deny
@printf '{{green}}[OK]{{reset}} Full CI pipeline passed\n'
[group('ci')]
[doc("Complete CI with all checks (for releases)")]
ci-release: ci-full semver msrv-check test-features
@printf '{{green}}[OK]{{reset}} Release CI pipeline passed\n'
[group('ci')]
[doc("Check if CI passed on the main branch (use before tagging)")]
ci-status:
#!/usr/bin/env bash
set -euo pipefail
printf '{{cyan}}[INFO]{{reset}} Checking CI status on main branch...\n'
if ! command -v gh &> /dev/null; then
printf '{{red}}[ERR]{{reset}} GitHub CLI (gh) is required for this check\n'
printf '{{cyan}}[INFO]{{reset}} Install: https://cli.github.com/\n'
exit 1
fi
STATUS=$(gh run list --branch main --limit 1 --json status,conclusion,headSha,displayTitle --jq '.[0]')
if [ -z "$STATUS" ]; then
printf '{{red}}[ERR]{{reset}} No workflow runs found on main branch\n'
exit 1
fi
RUN_STATUS=$(echo "$STATUS" | jq -r '.status')
CONCLUSION=$(echo "$STATUS" | jq -r '.conclusion')
SHA=$(echo "$STATUS" | jq -r '.headSha' | cut -c1-7)
TITLE=$(echo "$STATUS" | jq -r '.displayTitle')
printf '{{cyan}}[INFO]{{reset}} Latest run: %s (%s)\n' "$TITLE" "$SHA"
if [ "$RUN_STATUS" != "completed" ]; then
printf '{{yellow}}[WARN]{{reset}} CI is still running (status: %s)\n' "$RUN_STATUS"
printf '{{cyan}}[INFO]{{reset}} Wait for CI to complete: gh run watch\n'
exit 1
fi
if [ "$CONCLUSION" != "success" ]; then
printf '{{red}}[ERR]{{reset}} CI failed (conclusion: %s)\n' "$CONCLUSION"
printf '{{cyan}}[INFO]{{reset}} Check the workflow: gh run view\n'
exit 1
fi
HEAD_SHA=$(git rev-parse HEAD | cut -c1-7)
if [ "$SHA" != "$HEAD_SHA" ]; then
printf '{{yellow}}[WARN]{{reset}} Latest CI run (%s) does not match HEAD (%s)\n' "$SHA" "$HEAD_SHA"
printf '{{cyan}}[INFO]{{reset}} Push your commits and wait for CI to pass\n'
exit 1
fi
printf '{{green}}[OK]{{reset}} CI passed on main (commit %s)\n' "$SHA"
[group('ci')]
[doc("Check if ALL CI workflows passed on main (REQUIRED before tagging)")]
ci-status-all:
#!/usr/bin/env bash
set -euo pipefail
printf '{{cyan}}[INFO]{{reset}} Checking ALL workflow statuses on main branch...\n'
if ! command -v gh &> /dev/null; then
printf '{{red}}[ERR]{{reset}} GitHub CLI (gh) is required for this check\n'
exit 1
fi
HEAD_SHA=$(git rev-parse HEAD | cut -c1-7)
FAILED=0
for WORKFLOW in "CI" "Security Audit"; do
STATUS=$(gh run list --branch main --workflow="${WORKFLOW}" --limit 1 --json status,conclusion,headSha --jq '.[0]' 2>/dev/null || echo "{}")
if [ -z "$STATUS" ] || [ "$STATUS" = "{}" ]; then
printf '{{yellow}}[WARN]{{reset}} No runs found for workflow: %s\n' "$WORKFLOW"
continue
fi
RUN_STATUS=$(echo "$STATUS" | jq -r '.status // "unknown"')
CONCLUSION=$(echo "$STATUS" | jq -r '.conclusion // "unknown"')
SHA=$(echo "$STATUS" | jq -r '.headSha // "unknown"' | cut -c1-7)
if [ "$RUN_STATUS" != "completed" ]; then
printf '{{red}}[ERR]{{reset}} %s: still running\n' "$WORKFLOW"
FAILED=1
elif [ "$CONCLUSION" != "success" ]; then
printf '{{red}}[ERR]{{reset}} %s: %s (commit %s)\n' "$WORKFLOW" "$CONCLUSION" "$SHA"
FAILED=1
elif [ "$SHA" != "$HEAD_SHA" ]; then
printf '{{yellow}}[WARN]{{reset}} %s: passed but on different commit (%s vs HEAD %s)\n' "$WORKFLOW" "$SHA" "$HEAD_SHA"
FAILED=1
else
printf '{{green}}[OK]{{reset}} %s: passed (commit %s)\n' "$WORKFLOW" "$SHA"
fi
done
if [ $FAILED -ne 0 ]; then
printf '\n{{red}}[ERR]{{reset}} Not all workflows passed. Fix issues before tagging.\n'
printf '{{cyan}}[INFO]{{reset}} Run: gh run list --branch main\n'
exit 1
fi
printf '\n{{green}}[OK]{{reset}} All workflows passed on HEAD (%s)\n' "$HEAD_SHA"
[group('ci')]
[doc("Pre-commit hook checks")]
pre-commit: fmt-check clippy check
@printf '{{green}}[OK]{{reset}} Pre-commit checks passed\n'
[group('ci')]
[doc("Pre-push hook checks")]
pre-push: ci
@printf '{{green}}[OK]{{reset}} Pre-push checks passed\n'
# ============================================================================
# DEPENDENCY MANAGEMENT
# ============================================================================
[group('deps')]
[doc("Check for outdated dependencies")]
outdated:
#!/usr/bin/env bash
set -euo pipefail
printf '{{cyan}}[INFO]{{reset}} Checking for outdated dependencies...\n'
{{cargo}} outdated -R
[group('deps')]
[doc("Update Cargo.lock to latest compatible versions")]
update:
#!/usr/bin/env bash
set -euo pipefail
printf '{{cyan}}[INFO]{{reset}} Updating dependencies...\n'
{{cargo}} update
printf '{{green}}[OK]{{reset}} Dependencies updated\n'
[group('deps')]
[doc("Show dependency tree")]
tree:
#!/usr/bin/env bash
set -euo pipefail
printf '{{cyan}}[INFO]{{reset}} Dependency tree:\n'
{{cargo}} tree --workspace
[group('deps')]
[doc("Show duplicate dependencies")]
tree-duplicates:
#!/usr/bin/env bash
set -euo pipefail
printf '{{cyan}}[INFO]{{reset}} Duplicate dependencies:\n'
{{cargo}} tree --workspace --duplicates
# ============================================================================
# RELEASE CHECKLIST RECIPES
# ============================================================================
[group('release')]
[doc("Check for WIP markers (TODO, FIXME, XXX, HACK, todo!, unimplemented!)")]
wip-check:
#!/usr/bin/env bash
set -euo pipefail
printf '{{cyan}}[INFO]{{reset}} Checking for WIP markers...\n'
COMMENTS=$(grep -rn "TODO\|FIXME\|XXX\|HACK" --include="*.rs" crates/ 2>/dev/null || true)
if [ -n "$COMMENTS" ]; then
printf '{{yellow}}[WARN]{{reset}} Found WIP comments:\n'
echo "$COMMENTS" | head -20
COMMENT_COUNT=$(echo "$COMMENTS" | wc -l)
if [ "$COMMENT_COUNT" -gt 20 ]; then
printf '{{yellow}}[WARN]{{reset}} ... and %d more\n' "$((COMMENT_COUNT - 20))"
fi
fi
MACROS=$(grep -rn "todo!\|unimplemented!" --include="*.rs" crates/*/src/ 2>/dev/null || true)
if [ -n "$MACROS" ]; then
printf '{{red}}[ERR]{{reset}} Found incomplete macros in production code:\n'
echo "$MACROS"
exit 1
fi
printf '{{green}}[OK]{{reset}} WIP check passed (no blocking issues)\n'
[group('release')]
[doc("Audit panic paths (.unwrap(), .expect()) in production code")]
panic-audit:
#!/usr/bin/env bash
set -euo pipefail
printf '{{cyan}}[INFO]{{reset}} Auditing panic paths in production code...\n'
UNWRAPS=$(grep -rn "\.unwrap()" crates/*/src/ --include="*.rs" 2>/dev/null || true)
EXPECTS=$(grep -rn "\.expect(" crates/*/src/ --include="*.rs" 2>/dev/null || true)
if [ -n "$UNWRAPS" ] || [ -n "$EXPECTS" ]; then
printf '{{yellow}}[WARN]{{reset}} Found potential panic paths:\n'
if [ -n "$UNWRAPS" ]; then
echo "$UNWRAPS" | head -15
UNWRAP_COUNT=$(echo "$UNWRAPS" | wc -l)
printf '{{cyan}}[INFO]{{reset}} Total .unwrap() calls: %d\n' "$UNWRAP_COUNT"
fi
if [ -n "$EXPECTS" ]; then
echo "$EXPECTS" | head -10
EXPECT_COUNT=$(echo "$EXPECTS" | wc -l)
printf '{{cyan}}[INFO]{{reset}} Total .expect() calls: %d\n' "$EXPECT_COUNT"
fi
printf '{{yellow}}[NOTE]{{reset}} Review each for production safety.\n'
else
printf '{{green}}[OK]{{reset}} No panic paths found in production code\n'
fi
[group('release')]
[doc("Verify Cargo.toml metadata for crates.io publishing")]
metadata-check:
#!/usr/bin/env bash
set -euo pipefail
printf '{{cyan}}[INFO]{{reset}} Checking Cargo.toml metadata...\n'
METADATA=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[] | select(.name == "{{main_crate}}")')
DESC=$(echo "$METADATA" | jq -r '.description // empty')
LICENSE=$(echo "$METADATA" | jq -r '.license // empty')
REPO=$(echo "$METADATA" | jq -r '.repository // empty')
MISSING=""
[ -z "$DESC" ] && MISSING="$MISSING description"
[ -z "$LICENSE" ] && MISSING="$MISSING license"
[ -z "$REPO" ] && MISSING="$MISSING repository"
if [ -n "$MISSING" ]; then
printf '{{red}}[ERR]{{reset}} Missing required fields:%s\n' "$MISSING"
exit 1
fi
KEYWORDS=$(echo "$METADATA" | jq -r '.keywords // [] | length')
CATEGORIES=$(echo "$METADATA" | jq -r '.categories // [] | length')
[ "$KEYWORDS" -eq 0 ] && printf '{{yellow}}[WARN]{{reset}} No keywords defined\n'
[ "$CATEGORIES" -eq 0 ] && printf '{{yellow}}[WARN]{{reset}} No categories defined\n'
printf '{{cyan}}[INFO]{{reset}} Package metadata:\n'
printf ' description: %s\n' "$DESC"
printf ' license: %s\n' "$LICENSE"
printf ' repository: %s\n' "$REPO"
printf ' keywords: %d defined\n' "$KEYWORDS"
printf ' categories: %d defined\n' "$CATEGORIES"
printf '{{green}}[OK]{{reset}} Metadata check passed\n'
[group('release')]
[doc("Run typos spell checker")]
typos:
#!/usr/bin/env bash
set -euo pipefail
printf '{{cyan}}[INFO]{{reset}} Running typos spell checker...\n'
if ! command -v typos &> /dev/null; then
printf '{{yellow}}[WARN]{{reset}} typos not installed (cargo install typos-cli)\n'
exit 0
fi
typos crates/ README.md CHANGELOG.md RELEASING.md ROADMAP.md
printf '{{green}}[OK]{{reset}} Typos check passed\n'
[group('release')]
[doc("Prepare for release (runs full CI with all features)")]
release-check: ci-release check-feature-flags wip-check panic-audit version-sync typos machete metadata-check url-check
#!/usr/bin/env bash
set -euo pipefail
printf '\n{{bold}}{{blue}}══════ Release Validation ══════{{reset}}\n\n'
printf '{{cyan}}[INFO]{{reset}} Checking for uncommitted changes...\n'
if ! git diff-index --quiet HEAD --; then
printf '{{red}}[ERR]{{reset}} Uncommitted changes detected\n'
exit 1
fi
printf '{{cyan}}[INFO]{{reset}} Checking for unpushed commits...\n'
if [ -n "$(git log @{u}.. 2>/dev/null)" ]; then
printf '{{yellow}}[WARN]{{reset}} Unpushed commits detected\n'
fi
printf '{{green}}[OK]{{reset}} Ready for release\n'
printf '\n{{cyan}}[NEXT]{{reset}} Run: just ci-status-all && just tag\n'
[group('release')]
[doc("Publish all crates to crates.io (dry run)")]
publish-dry:
#!/usr/bin/env bash
set -euo pipefail
printf '{{cyan}}[INFO]{{reset}} Publishing (dry run) in dependency order...\n'
# Tier 0: Independent PTY crate
{{cargo}} publish --dry-run -p rust-pty
# Tier 1: Proc-macro crate
{{cargo}} publish --dry-run -p rust-expect-macros
# Tier 2: Main library
{{cargo}} publish --dry-run -p rust-expect
printf '{{green}}[OK]{{reset}} Dry run complete\n'
[group('release')]
[confirm("⚠️ MANUAL PUBLISHING IS A LAST RESORT! Use the automated GitHub Actions workflow instead. Type 'yes' to acknowledge this is IRREVERSIBLE:")]
[doc("Publish all crates to crates.io (LAST RESORT - prefer automated release)")]
publish:
#!/usr/bin/env bash
set -euo pipefail
printf '\n{{bold}}{{red}}════════════════════════════════════════════════════════════════{{reset}}\n'
printf '{{bold}}{{red}} ⚠️ WARNING: MANUAL PUBLISHING IS A LAST RESORT! {{reset}}\n'
printf '{{bold}}{{red}}════════════════════════════════════════════════════════════════{{reset}}\n\n'
printf '{{yellow}}You should almost NEVER use this command.{{reset}}\n\n'
printf 'The correct release workflow is:\n'
printf ' 1. just release-check\n'
printf ' 2. just ci-status-all\n'
printf ' 3. just tag\n'
printf ' 4. git push origin vX.Y.Z (triggers automated publish)\n\n'
printf '{{cyan}}[INFO]{{reset}} Publishing to crates.io in dependency order...\n'
printf '{{cyan}}[INFO]{{reset}} Note: 30s delays between tiers for index propagation\n\n'
# Tier 0: Independent PTY crate
printf '{{bold}}Tier 0: PTY Layer{{reset}}\n'
{{cargo}} publish -p rust-pty
printf '{{cyan}}[INFO]{{reset}} Waiting 30s for index propagation...\n'
sleep 30
# Tier 1: Proc-macro crate
printf '{{bold}}Tier 1: Proc-macro{{reset}}\n'
{{cargo}} publish -p rust-expect-macros
printf '{{cyan}}[INFO]{{reset}} Waiting 30s for index propagation...\n'
sleep 30
# Tier 2: Main library
printf '{{bold}}Tier 2: Main Library{{reset}}\n'
{{cargo}} publish -p rust-expect
printf '\n{{green}}[OK]{{reset}} All crates published successfully\n'
[group('release')]
[doc("Validate dependency graph for publishing")]
dep-graph:
#!/usr/bin/env bash
set -euo pipefail
printf '{{cyan}}[INFO]{{reset}} Dependency graph for publishing:\n\n'
printf '{{bold}}Tier 0 (Independent):{{reset}}\n'
printf ' rust-pty Cross-platform PTY abstraction\n\n'
printf '{{bold}}Tier 1 (Proc-macro):{{reset}}\n'
printf ' rust-expect-macros Compile-time pattern validation\n\n'
printf '{{bold}}Tier 2 (Main library):{{reset}}\n'
printf ' rust-expect → rust-pty, rust-expect-macros\n\n'
printf '{{yellow}}[NOTE]{{reset}} Publish in tier order with 30s delays between tiers\n'
[group('release')]
[doc("Check repository URLs are correct")]