Skip to content

Commit 8ab9bec

Browse files
authored
Add testkit commit validation to prevent version drift (#288)
1 parent 1084918 commit 8ab9bec

4 files changed

Lines changed: 114 additions & 7 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,7 @@ composer.lock
1414
/docs/_build
1515
cachegrind.out.*
1616
.phpunit.cache/
17+
# Note: /testkit/ (root) is the ONLY testkit version - tracked as a Git submodule
18+
# /testkit-backend/testkit/ is NOT a testkit copy, but a placeholder to prevent
19+
# developers from accidentally committing temporary test artifacts or debug copies
1720
/testkit-backend/testkit/

.gitmodules

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[submodule "testkit"]
2+
path = testkit
3+
url = https://github.com/neo4j-drivers/testkit.git
4+
branch = 5.0
5+

testkit-backend/testkit.sh

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,25 @@ if [ "$1" == "--clean" ]; then
1717
fi
1818
fi
1919

20+
# Initialize and update the testkit submodule
21+
if [ ! -d testkit/.git ]; then
22+
# Initialize submodules (handles .gitmodules configuration)
23+
git submodule init
24+
git submodule update
25+
fi
26+
27+
# Verify testkit is at the correct commit (in CI this happens automatically)
28+
# In local dev, this will fail if submodule is out of sync, guiding user to update
2029
if [ ! -d testkit ]; then
21-
git clone https://github.com/neo4j-drivers/testkit.git
22-
if [ "$(cd testkit && git branch --show-current)" != "${TESTKIT_VERSION}" ]; then
23-
(cd testkit && git checkout ${TESTKIT_VERSION})
24-
fi
30+
echo " ERROR: testkit submodule not initialized"
31+
echo " Run: git submodule init && git submodule update"
32+
exit 1
2533
fi
26-
#else
27-
# (cd testkit && git pull)
28-
#fi
34+
35+
# Validate testkit version before proceeding
36+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
37+
"$SCRIPT_DIR/validate-testkit-version.sh" || exit 1
38+
echo ""
2939

3040
cd testkit || (echo 'cannot cd into testkit' && exit 1)
3141
python3 -m venv venv
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#!/bin/bash
2+
3+
# Validate that testkit is a git submodule with correct commit
4+
# This prevents running tests with mismatched testkit versions
5+
6+
set -e
7+
8+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
9+
PROJECT_ROOT="$SCRIPT_DIR/.."
10+
11+
# Docker environment: configure git safe directory
12+
if [ -f "/.dockerenv" ]; then
13+
git config --global --add safe.directory "$PROJECT_ROOT" 2>/dev/null || true
14+
git config --global --add safe.directory "$PROJECT_ROOT/testkit" 2>/dev/null || true
15+
fi
16+
17+
if [ ! -d "$PROJECT_ROOT/testkit" ]; then
18+
echo " ERROR: testkit directory not found"
19+
echo " Initialize with: cd testkit-backend && ./testkit.sh"
20+
exit 1
21+
fi
22+
23+
EXPECTED_COMMIT=$(cd "$PROJECT_ROOT" && git ls-tree HEAD testkit 2>/dev/null | awk '{print $3}' || echo "")
24+
25+
if [ -z "$EXPECTED_COMMIT" ]; then
26+
echo " ERROR: Could not determine expected testkit commit"
27+
echo " testkit must be configured as a git submodule"
28+
echo " Ensure .gitmodules is properly configured and run:"
29+
echo " cd $PROJECT_ROOT && git submodule add https://github.com/neo4j-drivers/testkit.git testkit"
30+
exit 1
31+
fi
32+
33+
ACTUAL_COMMIT=$(cd "$PROJECT_ROOT/testkit" && git rev-parse HEAD 2>/dev/null || echo "UNKNOWN")
34+
35+
if [ "$ACTUAL_COMMIT" = "UNKNOWN" ]; then
36+
echo " ERROR: Could not read testkit commit (git rev-parse failed)"
37+
echo " Testkit may be corrupted. Try re-initializing:"
38+
echo " cd testkit-backend && ./testkit.sh --clean"
39+
exit 1
40+
fi
41+
42+
TESTKIT_STATUS=$(cd "$PROJECT_ROOT/testkit" && git status --porcelain 2>/dev/null | wc -l)
43+
if [ "$TESTKIT_STATUS" -gt 0 ]; then
44+
echo " WARNING: testkit has uncommitted changes!"
45+
echo ""
46+
echo " Status of testkit:"
47+
cd "$PROJECT_ROOT/testkit" && git status --short | sed 's/^/ /'
48+
echo ""
49+
echo " This may cause inconsistent test results. Consider:"
50+
echo " 1. Committing changes if they're intentional:"
51+
echo " cd $PROJECT_ROOT/testkit && git add . && git commit -m 'message'"
52+
echo " 2. Discarding changes if they're temporary:"
53+
echo " cd $PROJECT_ROOT/testkit && git checkout . && git clean -fd"
54+
echo ""
55+
fi
56+
57+
if [ "$EXPECTED_COMMIT" != "$ACTUAL_COMMIT" ]; then
58+
echo " ERROR: Testkit commit mismatch!"
59+
echo " Expected commit: $EXPECTED_COMMIT"
60+
echo " Actual commit: $ACTUAL_COMMIT"
61+
echo ""
62+
63+
if [ -n "$CI" ] || [ -n "$GITHUB_ACTIONS" ] || [ -n "$GITLAB_CI" ] || [ -n "$CIRCLECI" ]; then
64+
echo " Running in CI environment - attempting automatic submodule update..."
65+
git submodule update --checkout 2>/dev/null || true
66+
67+
ACTUAL_COMMIT=$(cd "$PROJECT_ROOT/testkit" && git rev-parse HEAD 2>/dev/null || echo "UNKNOWN")
68+
if [ "$EXPECTED_COMMIT" = "$ACTUAL_COMMIT" ]; then
69+
echo " Submodule updated successfully!"
70+
echo " Testkit is now at: ${ACTUAL_COMMIT:0:7}"
71+
exit 0
72+
fi
73+
fi
74+
75+
echo " Fix this by running one of:"
76+
echo ""
77+
echo " 1. Update the submodule to the pinned commit:"
78+
echo " cd $PROJECT_ROOT && git submodule update --checkout"
79+
echo ""
80+
echo " 2. Re-initialize testkit completely:"
81+
echo " cd testkit-backend && ./testkit.sh --clean"
82+
echo ""
83+
echo " 3. Manually update to the expected commit:"
84+
echo " cd $PROJECT_ROOT/testkit && git fetch && git checkout $EXPECTED_COMMIT && cd -"
85+
exit 1
86+
fi
87+
88+
echo " Testkit commit validated (${ACTUAL_COMMIT:0:7})"
89+
exit 0

0 commit comments

Comments
 (0)