coolify/app/Traits
Andras Bacsai 7ceb124e9b feat: add validation for YAML parsing, integer parameters, and Docker Compose custom fields
This commit adds comprehensive validation improvements and DRY principles for handling Coolify's custom Docker Compose extensions.

## Changes

### 1. Created Reusable stripCoolifyCustomFields() Function
- Added shared helper in bootstrap/helpers/docker.php
- Removes all Coolify custom fields (exclude_from_hc, content, isDirectory, is_directory)
- Handles both long syntax (arrays) and short syntax (strings) for volumes
- Well-documented with comprehensive docblock
- Follows DRY principle for consistent field stripping

### 2. Fixed Docker Compose Modal Validation
- Updated validateComposeFile() to use stripCoolifyCustomFields()
- Now removes ALL custom fields before Docker validation (previously only removed content)
- Fixes validation errors when using templates with custom fields (e.g., traccar.yaml)
- Users can now validate compose files with Coolify extensions in UI

### 3. Enhanced YAML Validation in CalculatesExcludedStatus
- Added proper exception handling with ParseException vs generic Exception
- Added structure validation (checks if parsed result and services are arrays)
- Comprehensive logging with context (error message, line number, snippet)
- Maintains safe fallback behavior (returns empty collection on error)

### 4. Added Integer Validation to ContainerStatusAggregator
- Validates maxRestartCount parameter in both aggregateFromStrings() and aggregateFromContainers()
- Corrects negative values to 0 with warning log
- Logs warnings for suspiciously high values (> 1000)
- Prevents logic errors in crash loop detection

### 5. Comprehensive Unit Tests
- tests/Unit/StripCoolifyCustomFieldsTest.php (NEW) - 9 tests, 43 assertions
- tests/Unit/ContainerStatusAggregatorTest.php - Added 6 tests for integer validation
- tests/Unit/ExcludeFromHealthCheckTest.php - Added 4 tests for YAML validation
- All tests passing with proper Log facade mocking

### 6. Documentation
- Added comprehensive Docker Compose extensions documentation to .ai/core/deployment-architecture.md
- Documents all custom fields: exclude_from_hc, content, isDirectory/is_directory
- Includes examples, use cases, implementation details, and test references
- Updated .ai/README.md with navigation links to new documentation

## Benefits
- Better UX: Users can validate compose files with custom fields
- Better Debugging: Comprehensive logging for errors
- Better Code Quality: DRY principle with reusable validation
- Better Reliability: Prevents logic errors from invalid parameters
- Better Maintainability: Easy to add new custom fields in future

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-20 18:34:49 +01:00
..
AuthorizesResourceCreation.php feat(auth): introduce resource creation authorization middleware and policies for enhanced access control 2025-08-26 10:27:38 +02:00
CalculatesExcludedStatus.php feat: add validation for YAML parsing, integer parameters, and Docker Compose custom fields 2025-11-20 18:34:49 +01:00
ClearsGlobalSearchCache.php feat(global-search): integrate projects and environments into global search functionality 2025-09-30 13:37:03 +02:00
DeletesUserSessions.php Changes auto-committed by Conductor 2025-10-16 09:51:37 +02:00
EnvironmentVariableAnalyzer.php fix(environment-variables): correct method call syntax in analyzeBuildVariable function 2025-09-23 11:40:56 +02:00
EnvironmentVariableProtection.php feat(deployment): add SERVICE_NAME variables for service discovery 2025-09-08 15:22:44 +02:00
ExecuteRemoteCommand.php fix(deployment): prevent base deployments from being killed when PRs close (#7113) 2025-11-09 14:41:35 +01:00
HasConfiguration.php feat(core): wip version of coolify.json 2025-01-21 14:09:12 +01:00
HasNotificationSettings.php Merge pull request #6837 from coollabsio/andrasbacsai/custom-webhooks 2025-10-12 10:57:47 +02:00
HasSafeStringAttribute.php feat(validation): centralize validation patterns for names and descriptions 2025-08-19 12:14:48 +02:00
SaveFromRedirect.php Revert "rector: arrrrr" 2025-01-07 15:31:43 +01:00
SshRetryable.php feat(ssh): add Sentry tracking for SSH retry events to enhance error monitoring 2025-09-07 18:57:20 +02:00