coolify/tests/Unit
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
..
Actions/User Changes auto-committed by Conductor 2025-10-16 17:13:47 +02:00
Livewire fix: normalize preview paths and use BUILD_TIME_ENV_PATH constant 2025-11-18 13:48:06 +01:00
Notifications/Channels feat(EmailChannel): enhance error handling with user-friendly messages for Resend API errors 2025-11-11 13:23:45 +01:00
Policies feat: Implement required port validation for service applications 2025-11-06 14:32:36 +01:00
Rules feat: add YAML validation for cloud-init scripts 2025-10-11 13:56:55 +02:00
AllExcludedContainersConsistencyTest.php feat(tests): add comprehensive tests for ContainerStatusAggregator and serverStatus accessor 2025-11-20 17:31:07 +01:00
ApplicationComposeEditorLoadTest.php fix: Monaco editor empty for docker compose applications 2025-10-27 12:48:20 +01:00
ApplicationConfigurationChangeTest.php fix: Remove duplicate custom_labels from config hash calculation 2025-11-01 13:28:56 +01:00
ApplicationDeploymentCustomBuildCommandTest.php fix: improve -f flag detection to prevent false positives 2025-11-18 13:49:46 +01:00
ApplicationDeploymentEmptyEnvTest.php Changes auto-committed by Conductor 2025-10-21 20:39:39 +02:00
ApplicationDeploymentErrorLoggingTest.php fix(deployment): improve error logging with exception types and hidden technical details 2025-11-17 14:44:39 +01:00
ApplicationGitSecurityTest.php fix: prevent command injection in git ls-remote operations 2025-10-15 14:53:50 +02:00
ApplicationHealthcheckRemovalTest.php Changes auto-committed by Conductor 2025-10-22 12:41:17 +02:00
ApplicationNetworkAliasesSyncTest.php refactor: Improve handling of custom network aliases 2025-11-01 13:13:14 +01:00
ApplicationPortDetectionTest.php feat: add automated PORT environment variable detection and UI warnings 2025-11-10 13:43:27 +01:00
ApplicationSettingStaticCastTest.php feat: Update ApplicationSetting model to include additional boolean casts 2025-11-04 08:43:33 +01:00
ApplicationWatchPathsTest.php refactor(tests): simplify matchWatchPaths tests and update implementation for better clarity 2025-09-26 14:33:18 +02:00
BashEnvEscapingTest.php fix: handle null environment variable values in bash escaping 2025-10-15 13:35:58 +02:00
CheckTraefikVersionForServerJobTest.php feat(proxy): enhance Traefik version notifications to show patch and minor upgrades 2025-11-17 09:59:17 +01:00
CheckTraefikVersionJobTest.php refactor: send immediate Traefik version notifications instead of delayed aggregation 2025-11-18 12:30:50 +01:00
CloudInitScriptValidationTest.php feat: add cloud-init script support for Hetzner server creation 2025-10-10 19:37:16 +02:00
ContainerHealthStatusTest.php feat(tests): add comprehensive tests for ContainerStatusAggregator and serverStatus accessor 2025-11-20 17:31:07 +01:00
ContainerStatusAggregatorTest.php feat: add validation for YAML parsing, integer parameters, and Docker Compose custom fields 2025-11-20 18:34:49 +01:00
DatalistComponentTest.php feat: add support for selecting additional SSH keys from Hetzner in server creation form 2025-10-10 12:17:05 +02:00
DeploymentExceptionTest.php feat(DeploymentException): add custom exception for deployment errors and update handler to exclude from reporting 2025-11-11 15:08:26 +01:00
DockerComposeEmptyStringPreservationTest.php feat: Implement required port validation for service applications 2025-11-06 14:32:36 +01:00
DockerComposeEmptyTopLevelSectionsTest.php fix: preserve empty strings and remove empty sections in docker-compose 2025-11-06 12:30:03 +01:00
DockerComposeLabelParsingTest.php Changes auto-committed by Conductor 2025-10-16 08:51:15 +02:00
DockerComposeRawContentRemovalTest.php Fix: Preserve clean docker_compose_raw without Coolify additions 2025-10-23 19:07:12 +02:00
DockerComposeRawSeparationTest.php Fix: Preserve clean docker_compose_raw without Coolify additions 2025-10-23 19:07:12 +02:00
DockerfileArgInsertionTest.php test: add unit tests for Dockerfile ARG insertion logic 2025-11-06 08:54:40 +01:00
DockerImageAutoParseTest.php fix: improve Docker image digest handling and add auto-parse feature 2025-10-15 10:19:01 +02:00
DockerImageParserTest.php fix: improve Docker image digest handling and add auto-parse feature 2025-10-15 10:19:01 +02:00
ExcludeFromHealthCheckTest.php feat: add validation for YAML parsing, integer parameters, and Docker Compose custom fields 2025-11-20 18:34:49 +01:00
GetContainersStatusServiceAggregationTest.php fix: correct Sentinel default health status and remove debug logging 2025-11-20 11:10:34 +01:00
GitLsRemoteParsingTest.php test: improve Git ls-remote parsing tests with uppercase SHA and negative cases 2025-10-14 17:34:26 +02:00
GlobalSearchNewImageQuickActionTest.php fix: 'new image' quick action not progressing to resource selection 2025-10-15 10:49:07 +02:00
HetznerDeletionFailedNotificationTest.php feat: implement Hetzner deletion failure notification system with email and messaging support 2025-10-10 09:35:58 +02:00
HetznerSshKeysTest.php feat: add support for selecting additional SSH keys from Hetzner in server creation form 2025-10-10 12:17:05 +02:00
NotifyOutdatedTraefikServersJobTest.php feat(proxy): enhance Traefik version notifications to show patch and minor upgrades 2025-11-17 09:59:17 +01:00
ParseCommandsByLineForSudoTest.php fix(server): wrap complex piped commands in bash -c for sudo execution 2025-11-13 14:39:55 +01:00
ParseDockerVolumeStringTest.php fix(parsers): enhance volume string handling by preserving mode in application and service parsers. Update related unit tests for validation. 2025-08-27 16:54:49 +02:00
PreSaveValidationTest.php fix: prevent command injection in Docker Compose parsing - add pre-save validation 2025-10-16 09:51:37 +02:00
PrivateKeyStorageTest.php fix(private-key): implement transaction handling and error verification for private key storage operations 2025-09-09 16:46:38 +02:00
ProxyCustomCommandsTest.php feat(proxy): enhance proxy configuration regeneration by extracting custom commands 2025-10-07 11:11:13 +02:00
ProxyHelperTest.php feat(proxy): add Traefik version tracking with notifications and dismissible UI warnings 2025-11-14 11:35:22 +01:00
RestartCountTrackingTest.php feat: add container restart tracking and crash loop detection 2025-11-10 13:04:31 +01:00
ScheduledJobManagerLockTest.php Fix stale lock issue causing scheduled tasks to stop (#4539) 2025-10-23 10:07:33 +02:00
ScheduledJobsRetryConfigTest.php feat(DatabaseBackupJob, ScheduledTaskJob): enforce minimum timeout and add execution ID for timeout handling 2025-11-11 12:07:39 +01:00
ScheduledTaskJobTimeoutTest.php feat(DatabaseBackupJob, ScheduledTaskJob): enforce minimum timeout and add execution ID for timeout handling 2025-11-11 12:07:39 +01:00
ServerQueryScopeTest.php fix(performance): eliminate N+1 query in CheckTraefikVersionJob 2025-11-14 11:35:22 +01:00
ServerStatusAccessorTest.php feat(tests): add comprehensive tests for ContainerStatusAggregator and serverStatus accessor 2025-11-20 17:31:07 +01:00
ServiceConfigurationRefreshTest.php fix: prevent duplicate services on image change and enable real-time UI refresh 2025-10-14 10:12:36 +02:00
ServiceExcludedStatusTest.php refactor: standardize Service model status aggregation to use ContainerStatusAggregator 2025-11-20 15:03:18 +01:00
ServiceNameSecurityTest.php fix: prevent command injection in Docker Compose parsing - add pre-save validation 2025-10-16 09:51:37 +02:00
ServiceParserImageUpdateTest.php fix: prevent duplicate services on image change and enable real-time UI refresh 2025-10-14 10:12:36 +02:00
ServiceParserPortDetectionLogicTest.php feat: implement service environment variable parsing and add unit tests for port detection logic 2025-11-11 11:19:33 +01:00
ServicePortSpecificVariablesTest.php feat: implement service environment variable parsing and add unit tests for port detection logic 2025-11-11 11:19:33 +01:00
ServiceRequiredPortTest.php feat: Implement required port validation for service applications 2025-11-06 14:32:36 +01:00
SshRetryMechanismTest.php fix(ssh): introduce SshRetryHandler and SshRetryable trait for enhanced SSH command retry logic with exponential backoff and error handling 2025-09-07 17:17:35 +02:00
StartProxyTest.php fix(proxy): prevent "container name already in use" error during proxy restart 2025-11-14 11:35:22 +01:00
StartupExecutionCleanupTest.php feat(Cleanup): implement failure marking for stuck scheduled tasks and database backups during startup 2025-11-11 12:32:52 +01:00
StopProxyTest.php fix(proxy): prevent "container name already in use" error during proxy restart 2025-11-14 11:35:22 +01:00
StripCoolifyCustomFieldsTest.php feat: add validation for YAML parsing, integer parameters, and Docker Compose custom fields 2025-11-20 18:34:49 +01:00
TimescaleDbDetectionTest.php feat(ServiceDatabase): add support for TimescaleDB detection and database type identification 2025-11-12 00:36:38 +01:00
ValidateShellSafePathTest.php refactor: harden and deduplicate validateShellSafePath 2025-10-16 09:51:37 +02:00
ValidGitRepositoryUrlTest.php fix(validation): update git:// URL validation to support port numbers and tilde characters in paths 2025-09-29 12:21:15 +02:00
ValidHostnameTest.php feat: implement ValidHostname validation rule and integrate it into server creation process 2025-10-10 11:03:13 +02:00
VolumeArrayFormatSecurityTest.php refactor: improve docker compose validation and transaction handling in StackForm 2025-11-07 14:03:19 +01:00
VolumeSecurityTest.php refactor: improve docker compose validation and transaction handling in StackForm 2025-11-07 14:03:19 +01:00
WindowsPathVolumeTest.php fix: use canonical parser for Windows path validation 2025-10-16 09:51:37 +02:00