@@ -11,63 +11,60 @@ ENGINE_DIR="$REPO_ROOT/coprocessor/fhevm-engine"
1111
1212cd " $ENGINE_DIR "
1313
14- # Get changed files relative to the engine directory
15- CHANGED_FILES=$( git diff --name-only " $BASE_BRANCH " ...HEAD -- " $ENGINE_DIR " 2> /dev/null | \
16- sed " s|^coprocessor/fhevm-engine/||" || true)
14+ # Fetch latest remote to ensure accurate comparison
15+ git fetch origin " $BASE_BRANCH " --quiet 2> /dev/null || true
1716
18- if [ -z " $CHANGED_FILES " ]; then
19- # Fallback: compare working tree if no commits ahead
20- CHANGED_FILES=$( git diff --name-only " $BASE_BRANCH " -- " $ENGINE_DIR " 2> /dev/null | \
21- sed " s|^coprocessor/fhevm-engine/||" || true)
22- fi
17+ # Compare only your branch's changes against the remote base branch
18+ # Uses three-dot diff against origin/ to exclude changes already on main
19+ CHANGED_FILES=$( git diff --name-only " origin/$BASE_BRANCH " ...HEAD -- " $ENGINE_DIR " 2> /dev/null | \
20+ sed " s|^coprocessor/fhevm-engine/||" || true)
2321
2422if [ -z " $CHANGED_FILES " ]; then
2523 echo " No changes detected vs $BASE_BRANCH . Nothing to cover."
2624 exit 0
2725fi
2826
29- # Extract unique crate names from changed file paths
30- # e.g. "host-listener/src/cmd/mod.rs" → "host-listener"
31- # Root-level files (Cargo.toml, etc.) don't match and are skipped
32- CHANGED_CRATES =$( echo " $CHANGED_FILES " | sed -n ' s|^\([^/]*\)/.*|\1|p' | sort -u)
27+ # Extract unique directory names from changed file paths, filtered to actual crates
28+ # e.g. "host-listener/src/cmd/mod.rs" → "host-listener" (only if host-listener/Cargo.toml exists)
29+ # Root-level files (Cargo.toml, Makefile, etc.) are skipped by the sed filter
30+ ALL_DIRS =$( echo " $CHANGED_FILES " | sed -n ' s|^\([^/]*\)/.*|\1|p' | sort -u)
3331
34- # Check for root-level changes that affect all crates (e.g. Cargo.lock)
35- # Cargo.toml profile/toolchain changes don't require full workspace coverage
36- ROOT_CRITICAL=$( echo " $CHANGED_FILES " | grep -v ' /' | grep -v ' \.toml$' || true)
32+ # Only Cargo.lock affects all crates — other root-level files are ignored
3733if echo " $CHANGED_FILES " | grep -q ' ^Cargo\.lock$' ; then
38- ROOT_CRITICAL=" Cargo.lock"
39- fi
40- if [ -n " $ROOT_CRITICAL " ]; then
41- echo " Workspace config changed ($ROOT_CRITICAL ) — running full workspace coverage."
34+ echo " Cargo.lock changed — running full workspace coverage."
4235 echo " "
4336 exec make coverage
4437fi
4538
39+ # Filter to actual crates (directories with Cargo.toml)
40+ CHANGED_CRATES=" "
41+ for dir in $ALL_DIRS ; do
42+ if [ -f " $dir /Cargo.toml" ]; then
43+ CHANGED_CRATES=" $CHANGED_CRATES $dir "
44+ fi
45+ done
46+ CHANGED_CRATES=$( echo " $CHANGED_CRATES " | xargs)
47+
4648if [ -z " $CHANGED_CRATES " ]; then
4749 echo " No crate-level changes detected. Nothing to cover."
4850 exit 0
4951fi
5052
5153echo " Changed crates:"
52- echo " $CHANGED_CRATES " | sed ' s/^/ - /'
54+ echo " $CHANGED_CRATES " | tr ' ' ' \n ' | sed ' s/^/ - /'
5355echo " "
5456
5557# If fhevm-engine-common changed, run full workspace (all crates depend on it)
56- if echo " $CHANGED_CRATES " | grep -q " ^ fhevm-engine-common$ " ; then
58+ if echo " $CHANGED_CRATES " | grep -q " fhevm-engine-common" ; then
5759 echo " fhevm-engine-common changed — running full workspace coverage."
5860 echo " "
5961 exec make coverage
6062fi
6163
62- # Build --package flags for each changed crate
64+ # Build --package flags
6365PKG_FLAGS=" "
6466for crate in $CHANGED_CRATES ; do
65- # Skip non-crate directories (e.g. db-migration, scripts)
66- if [ -f " $crate /Cargo.toml" ]; then
67- PKG_FLAGS=" $PKG_FLAGS --package $crate "
68- else
69- echo " Skipping $crate (not a Cargo crate)"
70- fi
67+ PKG_FLAGS=" $PKG_FLAGS --package $crate "
7168done
7269
7370if [ -z " $PKG_FLAGS " ]; then
@@ -85,7 +82,8 @@ TEST_GLOBAL_LOCALSTACK=1 \
8582cargo llvm-cov --no-report $PKG_FLAGS --profile coverage -- --test-threads=1
8683
8784cargo llvm-cov report --profile coverage 2>&1 | tee coverage-report.txt
85+ echo " # commit: $( git rev-parse HEAD) " >> coverage-report.txt
8886
8987echo " "
9088echo " Coverage report saved to coverage-report.txt"
91- tail -1 coverage-report.txt
89+ tail -2 coverage-report.txt
0 commit comments