wip
This commit is contained in:
@@ -186,6 +186,92 @@ def validate_constants(zip_path: Path, config: Dict, version_type: str) -> Valid
|
||||
|
||||
return result
|
||||
|
||||
def validate_version_differences(zip_path: Path, config: Dict, version_type: str) -> ValidationResult:
|
||||
"""Validate version-specific content and file exclusions."""
|
||||
result = ValidationResult()
|
||||
addon_id = config['project']['id']
|
||||
|
||||
# Load exclusions configuration
|
||||
exclusions_path = get_project_root() / "build" / "file_exclusions.json"
|
||||
try:
|
||||
with open(exclusions_path, 'r') as f:
|
||||
exclusions_config = json.load(f)
|
||||
except Exception as e:
|
||||
result.add_error(f"Could not load file exclusions config: {e}")
|
||||
return result
|
||||
|
||||
version_config = exclusions_config['version_configs'].get(version_type, {})
|
||||
excluded_files = version_config.get('exclude_files', [])
|
||||
excluded_patterns = version_config.get('exclude_patterns', [])
|
||||
|
||||
try:
|
||||
with zipfile.ZipFile(zip_path, 'r') as zip_file:
|
||||
file_list = zip_file.namelist()
|
||||
|
||||
# Check that excluded files are actually excluded in free version
|
||||
if version_type == "free":
|
||||
excluded_found = []
|
||||
for excluded_file in excluded_files:
|
||||
full_path = f"{addon_id}/{excluded_file}"
|
||||
if full_path in file_list or any(f.startswith(full_path) for f in file_list):
|
||||
excluded_found.append(excluded_file)
|
||||
|
||||
if excluded_found:
|
||||
result.add_error(f"Free version contains excluded files: {excluded_found}")
|
||||
else:
|
||||
result.add_info(f"Correctly excluded {len(excluded_files)} premium files from free version")
|
||||
|
||||
# Check for excluded patterns
|
||||
pattern_violations = []
|
||||
for file_path in file_list:
|
||||
for pattern in excluded_patterns:
|
||||
if pattern.strip('*').lower() in file_path.lower():
|
||||
pattern_violations.append((file_path, pattern))
|
||||
|
||||
if pattern_violations:
|
||||
result.add_warning(f"Files matching excluded patterns found: {pattern_violations}")
|
||||
|
||||
elif version_type == "full":
|
||||
# Full version should contain premium files
|
||||
missing_premium = []
|
||||
for premium_file in excluded_files:
|
||||
full_path = f"{addon_id}/{premium_file}"
|
||||
if full_path not in file_list and not any(f.startswith(full_path) for f in file_list):
|
||||
missing_premium.append(premium_file)
|
||||
|
||||
if missing_premium:
|
||||
result.add_error(f"Full version missing premium files: {missing_premium}")
|
||||
else:
|
||||
result.add_info(f"Full version correctly includes all {len(excluded_files)} premium features")
|
||||
|
||||
# Validate UI helper functions are present in constants.py
|
||||
constants_path = f"{addon_id}/utils/constants.py"
|
||||
if constants_path in file_list:
|
||||
constants_content = zip_file.read(constants_path).decode('utf-8')
|
||||
ui_functions = [
|
||||
'get_version_badge_text',
|
||||
'get_version_badge_icon',
|
||||
'get_upgrade_hint_text',
|
||||
'should_show_feature_lock',
|
||||
'get_feature_availability_text',
|
||||
'get_version_info_details'
|
||||
]
|
||||
|
||||
missing_ui_functions = []
|
||||
for func in ui_functions:
|
||||
if func not in constants_content:
|
||||
missing_ui_functions.append(func)
|
||||
|
||||
if missing_ui_functions:
|
||||
result.add_error(f"Missing UI helper functions in constants.py: {missing_ui_functions}")
|
||||
else:
|
||||
result.add_info("All UI helper functions present in constants.py")
|
||||
|
||||
except Exception as e:
|
||||
result.add_error(f"Error validating version differences: {e}")
|
||||
|
||||
return result
|
||||
|
||||
def validate_feature_flags(zip_path: Path, config: Dict) -> ValidationResult:
|
||||
"""Validate the feature flags system."""
|
||||
result = ValidationResult()
|
||||
@@ -278,6 +364,14 @@ def validate_package(zip_path: Path, version_type: Optional[str] = None) -> bool
|
||||
features_result.print_results()
|
||||
overall_valid &= features_result.is_valid
|
||||
|
||||
print("\n" + "─" * 60)
|
||||
|
||||
# Version differences validation
|
||||
print("Validating version-specific content and exclusions...")
|
||||
version_diff_result = validate_version_differences(zip_path, config, version_type)
|
||||
version_diff_result.print_results()
|
||||
overall_valid &= version_diff_result.is_valid
|
||||
|
||||
print("\n" + "=" * 60)
|
||||
print(f"Overall Validation: {'✅ PASS' if overall_valid else '❌ FAIL'}")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user