@@ -60,30 +60,36 @@ print_info() {
6060 echo -e " ${BLUE} ℹ $1 ${NC} "
6161}
6262
63- # Source migration functions
64- source_migration () {
63+ # Helper function to check migration using Python
64+ needs_migration () {
6565 local test_dir=$1
66- export PROJECT_DIR=" $test_dir "
67- export TEMP_DIR=" $test_dir /tmp"
68- mkdir -p " $TEMP_DIR "
69-
70- # Source the libraries
71- # shellcheck source=/dev/null
72- source " $PROJECT_ROOT /scripts/lib/ui.sh"
73- # shellcheck source=/dev/null
74- source " $PROJECT_ROOT /scripts/lib/migration.sh"
75-
76- # Re-define our test print functions to restore counter functionality
77- # (ui.sh overwrites them with non-counting versions)
78- print_success () {
79- echo -e " ${GREEN} ✓ $1 ${NC} "
80- (( PASSED_TESTS++ ))
81- }
82-
83- print_error () {
84- echo -e " ${RED} ✗ $1 ${NC} "
85- (( FAILED_TESTS++ ))
86- }
66+ python3 -c "
67+ import sys
68+ from pathlib import Path
69+ sys.path.insert(0, '$PROJECT_ROOT /scripts')
70+ from lib import migration
71+
72+ if migration.needs_migration(Path('$test_dir ')):
73+ sys.exit(0)
74+ else:
75+ sys.exit(1)
76+ "
77+ return $?
78+ }
79+
80+ # Helper function to run migration using Python
81+ run_migration () {
82+ local test_dir=$1
83+ local non_interactive=$2
84+ python3 -c "
85+ import sys
86+ from pathlib import Path
87+ sys.path.insert(0, '$PROJECT_ROOT /scripts')
88+ from lib import migration
89+
90+ migration.run_migration(Path('$test_dir '), $non_interactive )
91+ "
92+ return $?
8793}
8894
8995# =============================================================================
@@ -107,9 +113,7 @@ commands:
107113 - git-operations
108114EOF
109115
110- source_migration " $test_dir "
111-
112- if needs_migration; then
116+ if needs_migration " $test_dir " ; then
113117 print_success " Old format correctly detected as needing migration"
114118 else
115119 print_error " Old format should need migration"
@@ -131,9 +135,7 @@ commands:
131135 custom: []
132136EOF
133137
134- source_migration " $test_dir "
135-
136- if ! needs_migration; then
138+ if ! needs_migration " $test_dir " ; then
137139 print_success " New format (standard:) correctly detected as NOT needing migration"
138140 else
139141 print_error " New format should NOT need migration"
@@ -154,9 +156,7 @@ commands:
154156 - my-rule
155157EOF
156158
157- source_migration " $test_dir "
158-
159- if ! needs_migration; then
159+ if ! needs_migration " $test_dir " ; then
160160 print_success " New format (custom:) correctly detected as NOT needing migration"
161161 else
162162 print_error " New format should NOT need migration"
168168 test_dir=" $TEST_DIR /test-no-config"
169169 mkdir -p " $test_dir /.claude/rules"
170170
171- source_migration " $test_dir "
172-
173- if ! needs_migration; then
171+ if ! needs_migration " $test_dir " ; then
174172 print_success " Missing config correctly detected as NOT needing migration"
175173 else
176174 print_error " Missing config should NOT need migration"
206204
207205 print_success " Test files created"
208206
209- # Source migration and run it (simulating non-interactive mode)
210- source_migration " $test_dir "
211-
212- # Override the interactive prompt by providing Y input
207+ # Run migration in non-interactive mode
213208 print_test " Running migration with auto-accept"
214- if printf " Y\n " | run_migration > migration.log 2>&1 && grep -q " Migration complete " migration.log ; then
209+ if run_migration " $test_dir " " True " > migration.log 2>&1 ; then
215210 print_success " Migration executed successfully"
216211 else
217212 print_error " Migration did not complete successfully"
0 commit comments