Skip to content

Commit 546ecdb

Browse files
committed
feat(tests): enhance pre-commit configuration and testing scripts for Rust
- Added new pre-commit hooks for Rust projects, including `cargo-clippy` for core and CLI, and `cargo-warm-build` to pre-compile test binaries, improving code quality checks and build efficiency. - Introduced multiple unit test shard scripts (`cargo-test-unit-shard-0` to `cargo-test-unit-shard-7`) to facilitate parallel test execution, optimizing test distribution and reducing overall test time. - Updated `chunk-worktree.sh` to conditionally heal the Cargo lock file based on a new environment variable, enhancing flexibility in managing dependencies. - Created `cargo-unit-shard-update-weights.py` to regenerate test weights from timing logs, improving the accuracy of test execution time estimates. - Enhanced existing test scripts to support better organization and execution of unit and integration tests, ensuring a more robust testing framework. This update significantly improves the Rust testing workflow, enabling faster feedback and more efficient test management.
1 parent b517062 commit 546ecdb

20 files changed

Lines changed: 2137 additions & 113 deletions

‎.pre-commit-config.yaml‎

Lines changed: 105 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -713,12 +713,34 @@ repos:
713713
files: ^(src/|pyproject\.toml)$
714714
pass_filenames: false
715715

716+
- id: cargo-clippy-cyt-indexer-core
717+
name: cargo clippy (cyt-indexer core)
718+
entry: bash scripts/pre-commit-hooks/prek-hook.sh
719+
args:
720+
[
721+
'cd "$(git rev-parse --show-toplevel)" && rtk bash scripts/local/dev/cargo-clippy-cyt-indexer.sh core',
722+
]
723+
language: system
724+
files: ^(Cargo\.(toml|lock)|sdk/rust/cyt-indexer/|sdk/c/|sdk/go/)
725+
pass_filenames: false
726+
727+
- id: cargo-clippy-cyt-indexer-cli
728+
name: cargo clippy (cyt-indexer cli)
729+
entry: bash scripts/pre-commit-hooks/prek-hook.sh
730+
args:
731+
[
732+
'cd "$(git rev-parse --show-toplevel)" && rtk bash scripts/local/dev/cargo-clippy-cyt-indexer.sh cli',
733+
]
734+
language: system
735+
files: ^(Cargo\.(toml|lock)|sdk/rust/cyt-indexer/|sdk/c/|sdk/go/)
736+
pass_filenames: false
737+
716738
- id: cargo-clippy-cyt-indexer
717-
name: cargo clippy (cyt-indexer)
739+
name: cargo clippy (cyt-indexer all)
718740
entry: bash scripts/pre-commit-hooks/prek-hook.sh
719741
args:
720742
[
721-
'cd "$(git rev-parse --show-toplevel)" && rtk bash scripts/local/dev/cargo-locked.sh clippy -p cyt-indexer --all-targets --all-features --locked -- -D warnings -W clippy::all -W clippy::pedantic -W clippy::nursery -W clippy::cargo -W clippy::perf -W clippy::unwrap_used -W clippy::expect_used -W clippy::panic -W clippy::todo -W clippy::unimplemented -W clippy::dbg_macro -W clippy::missing_const_for_fn -W clippy::missing_panics_doc -W clippy::missing_errors_doc -W clippy::missing_safety_doc -W clippy::wildcard_imports -W clippy::enum_glob_use -W clippy::module_name_repetitions -W clippy::pub_use -W clippy::bool_comparison -W clippy::match_bool -W clippy::match_same_arms -W clippy::match_wild_err_arm -W clippy::needless_borrow -W clippy::needless_lifetimes -W clippy::inefficient_to_string -W clippy::large_enum_variant -W clippy::large_stack_arrays -W clippy::map_clone -W unused -W dead_code',
743+
'cd "$(git rev-parse --show-toplevel)" && rtk bash scripts/local/dev/cargo-clippy-cyt-indexer.sh all',
722744
]
723745
language: system
724746
files: ^(Cargo\.(toml|lock)|sdk/rust/cyt-indexer/|sdk/c/|sdk/go/)
@@ -800,6 +822,87 @@ repos:
800822
files: ^sdk/rust/cyt-indexer/(src/|tests/unit/)
801823
pass_filenames: false
802824

825+
- id: cargo-warm-build
826+
name: cargo warm build (cyt-indexer tests)
827+
entry: bash scripts/pre-commit-hooks/prek-hook.sh
828+
args:
829+
- rtk bash scripts/local/tests/cargo-warm-build.sh
830+
language: system
831+
files: ^(Cargo\.(toml|lock)|sdk/rust/cyt-indexer/)
832+
pass_filenames: false
833+
834+
- id: cargo-test-unit-shard-0
835+
name: cargo test (unit shard 0)
836+
entry: bash scripts/pre-commit-hooks/prek-hook.sh
837+
args:
838+
- 'cd "$(git rev-parse --show-toplevel)" && rtk bash scripts/local/tests/cargo-test-category.sh unit-shard 0 "${PREK_RUST_UNIT_SHARDS:-4}"'
839+
language: system
840+
files: ^sdk/rust/cyt-indexer/(src/|tests/unit/)
841+
pass_filenames: false
842+
843+
- id: cargo-test-unit-shard-1
844+
name: cargo test (unit shard 1)
845+
entry: bash scripts/pre-commit-hooks/prek-hook.sh
846+
args:
847+
- 'cd "$(git rev-parse --show-toplevel)" && rtk bash scripts/local/tests/cargo-test-category.sh unit-shard 1 "${PREK_RUST_UNIT_SHARDS:-4}"'
848+
language: system
849+
files: ^sdk/rust/cyt-indexer/(src/|tests/unit/)
850+
pass_filenames: false
851+
852+
- id: cargo-test-unit-shard-2
853+
name: cargo test (unit shard 2)
854+
entry: bash scripts/pre-commit-hooks/prek-hook.sh
855+
args:
856+
- 'cd "$(git rev-parse --show-toplevel)" && rtk bash scripts/local/tests/cargo-test-category.sh unit-shard 2 "${PREK_RUST_UNIT_SHARDS:-4}"'
857+
language: system
858+
files: ^sdk/rust/cyt-indexer/(src/|tests/unit/)
859+
pass_filenames: false
860+
861+
- id: cargo-test-unit-shard-3
862+
name: cargo test (unit shard 3)
863+
entry: bash scripts/pre-commit-hooks/prek-hook.sh
864+
args:
865+
- 'cd "$(git rev-parse --show-toplevel)" && rtk bash scripts/local/tests/cargo-test-category.sh unit-shard 3 "${PREK_RUST_UNIT_SHARDS:-4}"'
866+
language: system
867+
files: ^sdk/rust/cyt-indexer/(src/|tests/unit/)
868+
pass_filenames: false
869+
870+
- id: cargo-test-unit-shard-4
871+
name: cargo test (unit shard 4)
872+
entry: bash scripts/pre-commit-hooks/prek-hook.sh
873+
args:
874+
- 'cd "$(git rev-parse --show-toplevel)" && rtk bash scripts/local/tests/cargo-test-category.sh unit-shard 4 "${PREK_RUST_UNIT_SHARDS:-4}"'
875+
language: system
876+
files: ^sdk/rust/cyt-indexer/(src/|tests/unit/)
877+
pass_filenames: false
878+
879+
- id: cargo-test-unit-shard-5
880+
name: cargo test (unit shard 5)
881+
entry: bash scripts/pre-commit-hooks/prek-hook.sh
882+
args:
883+
- 'cd "$(git rev-parse --show-toplevel)" && rtk bash scripts/local/tests/cargo-test-category.sh unit-shard 5 "${PREK_RUST_UNIT_SHARDS:-4}"'
884+
language: system
885+
files: ^sdk/rust/cyt-indexer/(src/|tests/unit/)
886+
pass_filenames: false
887+
888+
- id: cargo-test-unit-shard-6
889+
name: cargo test (unit shard 6)
890+
entry: bash scripts/pre-commit-hooks/prek-hook.sh
891+
args:
892+
- 'cd "$(git rev-parse --show-toplevel)" && rtk bash scripts/local/tests/cargo-test-category.sh unit-shard 6 "${PREK_RUST_UNIT_SHARDS:-4}"'
893+
language: system
894+
files: ^sdk/rust/cyt-indexer/(src/|tests/unit/)
895+
pass_filenames: false
896+
897+
- id: cargo-test-unit-shard-7
898+
name: cargo test (unit shard 7)
899+
entry: bash scripts/pre-commit-hooks/prek-hook.sh
900+
args:
901+
- 'cd "$(git rev-parse --show-toplevel)" && rtk bash scripts/local/tests/cargo-test-category.sh unit-shard 7 "${PREK_RUST_UNIT_SHARDS:-4}"'
902+
language: system
903+
files: ^sdk/rust/cyt-indexer/(src/|tests/unit/)
904+
pass_filenames: false
905+
803906
- id: cargo-test-integration
804907
name: cargo test (integration)
805908
entry: bash scripts/pre-commit-hooks/prek-hook.sh

‎scripts/lib/chunk-worktree.sh‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,9 @@ if [[ -z "${CHUNK_WORKTREE_LIB_SOURCED:-}" ]]; then
621621
chunk_repair_cargo_advisory_db
622622
fi
623623
_chunk_cargo_exec_raw "${root}" "$@" || rc=$?
624-
chunk_ensure_workspace_cargo_lock "${root}" || heal_rc=$?
624+
if [[ "${CYT_DEFER_HEAL_CARGO_LOCK:-}" != 1 ]]; then
625+
chunk_ensure_workspace_cargo_lock "${root}" || heal_rc=$?
626+
fi
625627

626628
if ((rc != 0)); then
627629
return "${rc}"
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
#!/usr/bin/env bash
2+
# Run cyt-indexer clippy in focused scopes (faster than --all-targets --all-features).
3+
#
4+
# Usage:
5+
# ./scripts/local/dev/cargo-clippy-cyt-indexer.sh core|cli|all
6+
#
7+
# core — lib + integration/unit test targets (testing,ffi); main pre-commit path
8+
# cli — cyt-indexer binary (cli feature)
9+
# all — core then cli (legacy full gate)
10+
set -euo pipefail
11+
12+
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../../.." && pwd)"
13+
14+
# shellcheck source=scripts/lib/chunk-worktree.sh
15+
source "${ROOT}/scripts/lib/chunk-worktree.sh"
16+
17+
mode="${1:?usage: $0 core|cli|all}"
18+
19+
mapfile -t CLIPPY_LINT_ARGS <<'EOF'
20+
-D
21+
warnings
22+
-W
23+
clippy::all
24+
-W
25+
clippy::pedantic
26+
-W
27+
clippy::nursery
28+
-W
29+
clippy::cargo
30+
-W
31+
clippy::perf
32+
-W
33+
clippy::unwrap_used
34+
-W
35+
clippy::expect_used
36+
-W
37+
clippy::panic
38+
-W
39+
clippy::todo
40+
-W
41+
clippy::unimplemented
42+
-W
43+
clippy::dbg_macro
44+
-W
45+
clippy::missing_const_for_fn
46+
-W
47+
clippy::missing_panics_doc
48+
-W
49+
clippy::missing_errors_doc
50+
-W
51+
clippy::missing_safety_doc
52+
-W
53+
clippy::wildcard_imports
54+
-W
55+
clippy::enum_glob_use
56+
-W
57+
clippy::module_name_repetitions
58+
-W
59+
clippy::pub_use
60+
-W
61+
clippy::bool_comparison
62+
-W
63+
clippy::match_bool
64+
-W
65+
clippy::match_same_arms
66+
-W
67+
clippy::match_wild_err_arm
68+
-W
69+
clippy::needless_borrow
70+
-W
71+
clippy::needless_lifetimes
72+
-W
73+
clippy::inefficient_to_string
74+
-W
75+
clippy::large_enum_variant
76+
-W
77+
clippy::large_stack_arrays
78+
-W
79+
clippy::map_clone
80+
-W
81+
unused
82+
-W
83+
dead_code
84+
EOF
85+
86+
_run_core() {
87+
chunk_cargo_locked "${ROOT}" clippy -p cyt-indexer --lib --tests \
88+
--no-default-features --features "testing,ffi" --locked -- "${CLIPPY_LINT_ARGS[@]}"
89+
}
90+
91+
_run_cli() {
92+
chunk_cargo_locked "${ROOT}" clippy -p cyt-indexer --bins \
93+
--no-default-features --features cli --locked -- "${CLIPPY_LINT_ARGS[@]}"
94+
}
95+
96+
case "${mode}" in
97+
core) _run_core ;;
98+
cli) _run_cli ;;
99+
all)
100+
_run_core
101+
_run_cli
102+
;;
103+
*)
104+
echo "unknown mode: ${mode} (expected core|cli|all)" >&2
105+
exit 1
106+
;;
107+
esac

0 commit comments

Comments
 (0)