Skip to content

Commit 6199ae1

Browse files
committed
fix: Fix E2E tests
1 parent 91627d7 commit 6199ae1

File tree

2 files changed

+50
-63
lines changed

2 files changed

+50
-63
lines changed

tests/e2e/test-config-merge.sh

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -70,30 +70,23 @@ test_config_merge_with_yq() {
7070

7171
local test_dir="$TEST_DIR/test-yq"
7272
mkdir -p "$test_dir"
73-
export PROJECT_DIR="$test_dir"
74-
export TEMP_DIR="$test_dir/tmp"
75-
mkdir -p "$TEMP_DIR"
76-
77-
# Source required libraries
78-
# shellcheck source=/dev/null
79-
source "$PROJECT_ROOT/scripts/lib/ui.sh"
80-
# shellcheck source=/dev/null
81-
source "$PROJECT_ROOT/scripts/lib/utils.sh"
82-
83-
# Re-define print functions to restore counter functionality
84-
print_success() {
85-
echo -e "${GREEN}$1${NC}"
86-
((PASSED_TESTS++))
87-
}
8873

89-
print_error() {
90-
echo -e "${RED}$1${NC}"
91-
((FAILED_TESTS++))
74+
# Helper function to merge configs using Python
75+
merge_rules_config() {
76+
local new_config=$1
77+
local existing_config=$2
78+
python3 -c "
79+
import sys
80+
from pathlib import Path
81+
sys.path.insert(0, '$PROJECT_ROOT/scripts')
82+
from lib import files
83+
84+
result = files.merge_yaml_config(Path('$new_config'), Path('$existing_config'))
85+
sys.exit(0 if result else 1)
86+
"
87+
return $?
9288
}
9389

94-
# Extract just the merge_rules_config function from install.sh
95-
eval "$(sed -n '/^merge_rules_config() {/,/^}/p' "$PROJECT_ROOT/scripts/install.sh")"
96-
9790
# Create existing config with custom rules
9891
print_test "Creating existing config with custom rules"
9992
cat >"$test_dir/existing-config.yaml" <<'EOF'
@@ -146,11 +139,10 @@ EOF
146139

147140
# Run merge
148141
print_test "Running config merge"
149-
if merge_rules_config "$test_dir/new-config.yaml" "$test_dir/existing-config.yaml" >merge.log 2>&1 && grep -q "preserved custom rules" merge.log; then
142+
if merge_rules_config "$test_dir/new-config.yaml" "$test_dir/existing-config.yaml"; then
150143
print_success "Merge completed successfully"
151144
else
152145
print_error "Merge did not complete"
153-
cat merge.log
154146
return 1
155147
fi
156148

tests/e2e/test-migration.sh

Lines changed: 35 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -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
108114
EOF
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: []
132136
EOF
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
155157
EOF
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"
@@ -168,9 +168,7 @@ EOF
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"
@@ -206,12 +204,9 @@ EOF
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

Comments
 (0)