feat(config): add support for excluding modules during installation and updates (#22793)

This commit is contained in:
Yehonal
2025-09-06 11:22:22 +02:00
committed by GitHub
parent 725b475dd4
commit d3a6c09b31
4 changed files with 785 additions and 76 deletions

View File

@@ -146,6 +146,27 @@ teardown() {
[ "$output" = "myorg/mymodule" ]
}
@test "inst_extract_owner_name should handle URLs with ports correctly" {
cd "$TEST_DIR"
source "$TEST_DIR/apps/installer/includes/includes.sh"
# Test HTTPS URL with port
run inst_extract_owner_name "https://example.com:8080/user/repo.git"
[ "$output" = "user/repo" ]
# Test SSH URL with port
run inst_extract_owner_name "ssh://git@example.com:2222/owner/module"
[ "$output" = "owner/module" ]
# Test URL with port and custom directory (should ignore the directory part)
run inst_extract_owner_name "https://gitlab.internal:9443/team/project.git:custom-dir"
[ "$output" = "team/project" ]
# Test complex URL with port (should extract owner/name correctly)
run inst_extract_owner_name "https://git.company.com:8443/department/awesome-module.git"
[ "$output" = "department/awesome-module" ]
}
@test "duplicate module entries should be prevented across different formats" {
cd "$TEST_DIR"
source "$TEST_DIR/apps/installer/includes/includes.sh"
@@ -189,6 +210,30 @@ teardown() {
[ "$status" -ne 0 ]
}
@test "module installed via URL with port should be recognized correctly" {
cd "$TEST_DIR"
source "$TEST_DIR/apps/installer/includes/includes.sh"
# Install via URL with port
inst_mod_list_upsert "https://gitlab.internal:9443/myorg/my-module.git" "master" "abc123"
# Should be detected as installed using normalized owner/name
run inst_mod_is_installed "myorg/my-module"
[ "$status" -eq 0 ]
# Should be detected when checking with different URL format
run inst_mod_is_installed "ssh://git@gitlab.internal:9443/myorg/my-module"
[ "$status" -eq 0 ]
# Should be detected when checking with custom directory syntax
run inst_mod_is_installed "myorg/my-module:custom-dir"
[ "$status" -eq 0 ]
# Different module should not be detected
run inst_mod_is_installed "myorg/different-module"
[ "$status" -ne 0 ]
}
@test "cross-format module removal should work" {
cd "$TEST_DIR"
source "$TEST_DIR/apps/installer/includes/includes.sh"
@@ -355,3 +400,356 @@ EOF
[ "$owner_name_format" = "azerothcore/mod-transmog" ]
[ "$simple_format" = "azerothcore/mod-transmog" ]
}
# Tests for module exclusion functionality
@test "module exclusion should work with MODULES_EXCLUDE_LIST" {
cd "$TEST_DIR"
source "$TEST_DIR/apps/installer/includes/includes.sh"
# Test exclusion with simple name
export MODULES_EXCLUDE_LIST="mod-test-module"
run inst_mod_is_excluded "mod-test-module"
[ "$status" -eq 0 ]
# Test exclusion with owner/name format
export MODULES_EXCLUDE_LIST="azerothcore/mod-test"
run inst_mod_is_excluded "mod-test"
[ "$status" -eq 0 ]
# Test exclusion with space-separated list
export MODULES_EXCLUDE_LIST="mod-one mod-two mod-three"
run inst_mod_is_excluded "mod-two"
[ "$status" -eq 0 ]
# Test exclusion with newline-separated list
export MODULES_EXCLUDE_LIST="
mod-alpha
mod-beta
mod-gamma
"
run inst_mod_is_excluded "mod-beta"
[ "$status" -eq 0 ]
# Test exclusion with URL format
export MODULES_EXCLUDE_LIST="https://github.com/azerothcore/mod-transmog.git"
run inst_mod_is_excluded "mod-transmog"
[ "$status" -eq 0 ]
# Test non-excluded module
export MODULES_EXCLUDE_LIST="mod-other"
run inst_mod_is_excluded "mod-transmog"
[ "$status" -eq 1 ]
# Test empty exclusion list
unset MODULES_EXCLUDE_LIST
run inst_mod_is_excluded "mod-transmog"
[ "$status" -eq 1 ]
}
@test "install --all should skip excluded modules" {
cd "$TEST_DIR"
source "$TEST_DIR/apps/installer/includes/includes.sh"
# Setup modules list with excluded module
mkdir -p "$TEST_DIR/conf"
cat > "$TEST_DIR/conf/modules.list" << 'EOF'
azerothcore/mod-transmog master abc123
azerothcore/mod-excluded master def456
EOF
# Set exclusion list
export MODULES_EXCLUDE_LIST="mod-excluded"
# Mock the install process to capture output
run bash -c "source '$TEST_DIR/apps/installer/includes/includes.sh' && inst_module_install --all 2>&1"
# Should show that excluded module was skipped
[[ "$output" == *"azerothcore/mod-excluded"* && "$output" == *"Excluded by MODULES_EXCLUDE_LIST"* && "$output" == *"skipping"* ]]
}
@test "exclusion should work with multiple formats in same list" {
cd "$TEST_DIR"
source "$TEST_DIR/apps/installer/includes/includes.sh"
# Test multiple exclusion formats
export MODULES_EXCLUDE_LIST="mod-test https://github.com/azerothcore/mod-transmog.git custom/mod-other"
run inst_mod_is_excluded "mod-test"
[ "$status" -eq 0 ]
run inst_mod_is_excluded "azerothcore/mod-transmog"
[ "$status" -eq 0 ]
run inst_mod_is_excluded "custom/mod-other"
[ "$status" -eq 0 ]
run inst_mod_is_excluded "mod-allowed"
[ "$status" -eq 1 ]
}
# Tests for color support functionality
@test "color functions should work correctly" {
cd "$TEST_DIR"
source "$TEST_DIR/apps/installer/includes/includes.sh"
# Test that print functions exist and work
run print_info "test message"
[ "$status" -eq 0 ]
run print_warn "test warning"
[ "$status" -eq 0 ]
run print_error "test error"
[ "$status" -eq 0 ]
run print_success "test success"
[ "$status" -eq 0 ]
run print_skip "test skip"
[ "$status" -eq 0 ]
run print_header "test header"
[ "$status" -eq 0 ]
}
@test "color support should respect NO_COLOR environment variable" {
cd "$TEST_DIR"
# Test with NO_COLOR set
export NO_COLOR=1
source "$TEST_DIR/apps/installer/includes/includes.sh"
# Colors should be empty when NO_COLOR is set
[ -z "$C_RED" ]
[ -z "$C_GREEN" ]
[ -z "$C_RESET" ]
}
# Tests for interactive menu system
@test "module help should display comprehensive help" {
cd "$TEST_DIR"
source "$TEST_DIR/apps/installer/includes/includes.sh"
run inst_module_help
[ "$status" -eq 0 ]
# Should contain key sections
[[ "$output" =~ "Module Manager Help" ]]
[[ "$output" =~ "Usage:" ]]
[[ "$output" =~ "Module Specification Syntax:" ]]
[[ "$output" =~ "Examples:" ]]
}
@test "module list should show installed modules correctly" {
cd "$TEST_DIR"
source "$TEST_DIR/apps/installer/includes/includes.sh"
# Setup modules list
mkdir -p "$TEST_DIR/conf"
cat > "$TEST_DIR/conf/modules.list" << 'EOF'
azerothcore/mod-transmog master abc123
custom/mod-test develop def456
EOF
run inst_module_list
[ "$status" -eq 0 ]
# Should show both modules
[[ "$output" =~ "mod-transmog" ]]
[[ "$output" =~ "custom/mod-test" ]]
[[ "$output" =~ "master" ]]
[[ "$output" =~ "develop" ]]
}
@test "module list should handle empty list gracefully" {
cd "$TEST_DIR"
source "$TEST_DIR/apps/installer/includes/includes.sh"
# Ensure empty modules list
mkdir -p "$TEST_DIR/conf"
touch "$TEST_DIR/conf/modules.list"
run inst_module_list
[ "$status" -eq 0 ]
[[ "$output" =~ "No modules installed" ]]
}
# Tests for advanced parsing edge cases
@test "parsing should handle complex URL formats" {
cd "$TEST_DIR"
source "$TEST_DIR/apps/installer/includes/includes.sh"
# Test GitLab URL with custom directory and branch
run inst_parse_module_spec "https://gitlab.com/myorg/mymodule.git:custom-dir@develop:abc123"
[ "$status" -eq 0 ]
IFS=' ' read -r repo_ref owner name branch commit url dirname <<< "$output"
[ "$repo_ref" = "https://gitlab.com/myorg/mymodule.git" ]
[ "$owner" = "myorg" ]
[ "$name" = "mymodule" ]
[ "$branch" = "develop" ]
[ "$commit" = "abc123" ]
[ "$dirname" = "custom-dir" ]
}
@test "parsing should handle URLs with ports correctly (fix for port/dirname confusion)" {
cd "$TEST_DIR"
source "$TEST_DIR/apps/installer/includes/includes.sh"
# Test HTTPS URL with port - should NOT treat port as dirname
run inst_parse_module_spec "https://example.com:8080/user/repo.git"
[ "$status" -eq 0 ]
IFS=' ' read -r repo_ref owner name branch commit url dirname <<< "$output"
[ "$repo_ref" = "https://example.com:8080/user/repo.git" ]
[ "$owner" = "user" ]
[ "$name" = "repo" ]
[ "$branch" = "-" ]
[ "$commit" = "-" ]
[ "$url" = "https://example.com:8080/user/repo.git" ]
[ "$dirname" = "repo" ] # Should default to repo name, NOT port number
}
@test "parsing should handle URLs with ports and custom directory correctly" {
cd "$TEST_DIR"
source "$TEST_DIR/apps/installer/includes/includes.sh"
# Test URL with port AND custom directory - should parse custom directory correctly
run inst_parse_module_spec "https://example.com:8080/user/repo.git:custom-dir"
[ "$status" -eq 0 ]
IFS=' ' read -r repo_ref owner name branch commit url dirname <<< "$output"
[ "$repo_ref" = "https://example.com:8080/user/repo.git" ]
[ "$owner" = "user" ]
[ "$name" = "repo" ]
[ "$branch" = "-" ]
[ "$commit" = "-" ]
[ "$url" = "https://example.com:8080/user/repo.git" ]
[ "$dirname" = "custom-dir" ] # Should be custom-dir, not port number
}
@test "parsing should handle SSH URLs with ports correctly" {
cd "$TEST_DIR"
source "$TEST_DIR/apps/installer/includes/includes.sh"
# Test SSH URL with port
run inst_parse_module_spec "ssh://git@example.com:2222/user/repo"
[ "$status" -eq 0 ]
IFS=' ' read -r repo_ref owner name branch commit url dirname <<< "$output"
[ "$repo_ref" = "ssh://git@example.com:2222/user/repo" ]
[ "$owner" = "user" ]
[ "$name" = "repo" ]
[ "$dirname" = "repo" ] # Should be repo name, not port number
}
@test "parsing should handle SSH URLs with ports and custom directory" {
cd "$TEST_DIR"
source "$TEST_DIR/apps/installer/includes/includes.sh"
# Test SSH URL with port and custom directory
run inst_parse_module_spec "ssh://git@example.com:2222/user/repo:my-custom-dir@develop"
[ "$status" -eq 0 ]
IFS=' ' read -r repo_ref owner name branch commit url dirname <<< "$output"
[ "$repo_ref" = "ssh://git@example.com:2222/user/repo" ]
[ "$owner" = "user" ]
[ "$name" = "repo" ]
[ "$branch" = "develop" ]
[ "$dirname" = "my-custom-dir" ]
}
@test "parsing should handle complex URLs with ports, custom dirs, and branches" {
cd "$TEST_DIR"
source "$TEST_DIR/apps/installer/includes/includes.sh"
# Test comprehensive URL with port, custom directory, branch, and commit
run inst_parse_module_spec "https://gitlab.example.com:9443/myorg/myrepo.git:custom-name@feature-branch:abc123def"
[ "$status" -eq 0 ]
IFS=' ' read -r repo_ref owner name branch commit url dirname <<< "$output"
[ "$repo_ref" = "https://gitlab.example.com:9443/myorg/myrepo.git" ]
[ "$owner" = "myorg" ]
[ "$name" = "myrepo" ]
[ "$branch" = "feature-branch" ]
[ "$commit" = "abc123def" ]
[ "$url" = "https://gitlab.example.com:9443/myorg/myrepo.git" ]
[ "$dirname" = "custom-name" ]
}
@test "URL port parsing regression test - ensure ports are not confused with directory names" {
cd "$TEST_DIR"
source "$TEST_DIR/apps/installer/includes/includes.sh"
# These are the problematic cases that the fix addresses
local test_cases=(
"https://example.com:8080/repo.git"
"https://gitlab.internal:9443/group/project.git"
"ssh://git@server.com:2222/owner/repo"
"https://git.company.com:8443/team/module.git"
)
for spec in "${test_cases[@]}"; do
run inst_parse_module_spec "$spec"
[ "$status" -eq 0 ]
IFS=' ' read -r repo_ref owner name branch commit url dirname <<< "$output"
# Critical: dirname should NEVER be a port number
[[ ! "$dirname" =~ ^[0-9]+$ ]] || {
echo "FAIL: Port number '$dirname' incorrectly parsed as directory name for spec: $spec"
return 1
}
# dirname should be the repository name by default
local expected_name
if [[ "$spec" =~ /([^/]+)(\.git)?$ ]]; then
expected_name="${BASH_REMATCH[1]}"
expected_name="${expected_name%.git}"
fi
[ "$dirname" = "$expected_name" ] || {
echo "FAIL: Expected dirname '$expected_name' but got '$dirname' for spec: $spec"
return 1
}
done
}
@test "parsing should handle URL with custom directory but no branch" {
cd "$TEST_DIR"
source "$TEST_DIR/apps/installer/includes/includes.sh"
run inst_parse_module_spec "https://github.com/owner/repo.git:my-dir"
[ "$status" -eq 0 ]
IFS=' ' read -r repo_ref owner name branch commit url dirname <<< "$output"
[ "$repo_ref" = "https://github.com/owner/repo.git" ]
[ "$dirname" = "my-dir" ]
[ "$branch" = "-" ]
}
@test "modules list should maintain alphabetical order" {
cd "$TEST_DIR"
source "$TEST_DIR/apps/installer/includes/includes.sh"
# Add modules in random order
inst_mod_list_upsert "zeta/mod-z" "master" "abc"
inst_mod_list_upsert "alpha/mod-a" "master" "def"
inst_mod_list_upsert "beta/mod-b" "master" "ghi"
# Read the list and verify alphabetical order
local entries=()
while read -r repo_ref branch commit; do
[[ -z "$repo_ref" ]] && continue
entries+=("$repo_ref")
done < <(inst_mod_list_read)
# Should be in alphabetical order by owner/name
[ "${entries[0]}" = "alpha/mod-a" ]
[ "${entries[1]}" = "beta/mod-b" ]
[ "${entries[2]}" = "zeta/mod-z" ]
}
@test "module dispatcher should handle unknown commands gracefully" {
cd "$TEST_DIR"
source "$TEST_DIR/apps/installer/includes/includes.sh"
run inst_module "unknown-command"
[ "$status" -eq 1 ]
[[ "$output" =~ "Unknown module command" ]]
}