Merge branch 'next' into fix-traefik-startup

This commit is contained in:
Andras Bacsai
2025-11-28 17:54:48 +01:00
committed by GitHub
12 changed files with 290 additions and 50 deletions

View File

@@ -48,6 +48,7 @@ it('uses max of CDN and cache versions', function () {
->once()
->with(base_path('versions.json'), Mockery::on(function ($json) {
$data = json_decode($json, true);
// Should use cached version (4.0.10), not CDN version (4.0.0)
return $data['coolify']['v4']['version'] === '4.0.10';
}));
@@ -61,7 +62,7 @@ it('uses max of CDN and cache versions', function () {
return $this->settings;
});
$job = new CheckForUpdatesJob();
$job = new CheckForUpdatesJob;
$job->handle();
});
@@ -87,6 +88,7 @@ it('never downgrades from current running version', function () {
->once()
->with(base_path('versions.json'), Mockery::on(function ($json) {
$data = json_decode($json, true);
// Should use running version (4.0.10), not CDN (4.0.0) or cache (4.0.5)
return $data['coolify']['v4']['version'] === '4.0.10';
}));
@@ -104,7 +106,7 @@ it('never downgrades from current running version', function () {
return $this->settings;
});
$job = new CheckForUpdatesJob();
$job = new CheckForUpdatesJob;
$job->handle();
});
@@ -125,7 +127,7 @@ it('uses data_set for safe version mutation', function () {
return $this->settings;
});
$job = new CheckForUpdatesJob();
$job = new CheckForUpdatesJob;
// Should not throw even if structure is unexpected
// data_set() handles nested path creation
@@ -159,6 +161,7 @@ it('preserves other component versions when preventing Coolify downgrade', funct
expect($data['traefik']['v3.6'])->toBe('3.6.2');
// Sentinel should use CDN version
expect($data['sentinel']['version'])->toBe('1.0.5');
return true;
}));
@@ -178,6 +181,6 @@ it('preserves other component versions when preventing Coolify downgrade', funct
return $this->settings;
});
$job = new CheckForUpdatesJob();
$job = new CheckForUpdatesJob;
$job->handle();
});

View File

@@ -0,0 +1,149 @@
<?php
use App\Models\Service;
use Illuminate\Support\Facades\Log;
beforeEach(function () {
Log::shouldReceive('error')->andReturn(null);
});
it('applies beszel gzip prerequisite correctly', function () {
// Create a simple object to track the property change
$application = new class
{
public $is_gzip_enabled = true;
public function save() {}
};
$query = Mockery::mock();
$query->shouldReceive('whereName')
->with('beszel')
->once()
->andReturnSelf();
$query->shouldReceive('first')
->once()
->andReturn($application);
$service = Mockery::mock(Service::class)->makePartial();
$service->name = 'beszel-clx1ab2cd3ef4g5hi6jk7l8m9n0o1p2q3'; // CUID2 format
$service->id = 1;
$service->shouldReceive('applications')
->once()
->andReturn($query);
applyServiceApplicationPrerequisites($service);
expect($application->is_gzip_enabled)->toBeFalse();
});
it('applies appwrite stripprefix prerequisite correctly', function () {
$applications = [];
foreach (['appwrite', 'appwrite-console', 'appwrite-realtime'] as $name) {
$app = new class
{
public $is_stripprefix_enabled = true;
public function save() {}
};
$applications[$name] = $app;
}
$service = Mockery::mock(Service::class)->makePartial();
$service->name = 'appwrite-clx1ab2cd3ef4g5hi6jk7l8m9n0o1p2q3'; // CUID2 format
$service->id = 1;
$service->shouldReceive('applications')->times(3)->andReturnUsing(function () use (&$applications) {
static $callCount = 0;
$names = ['appwrite', 'appwrite-console', 'appwrite-realtime'];
$currentName = $names[$callCount++];
$query = Mockery::mock();
$query->shouldReceive('whereName')
->with($currentName)
->once()
->andReturnSelf();
$query->shouldReceive('first')
->once()
->andReturn($applications[$currentName]);
return $query;
});
applyServiceApplicationPrerequisites($service);
foreach ($applications as $app) {
expect($app->is_stripprefix_enabled)->toBeFalse();
}
});
it('handles missing applications gracefully', function () {
$query = Mockery::mock();
$query->shouldReceive('whereName')
->with('beszel')
->once()
->andReturnSelf();
$query->shouldReceive('first')
->once()
->andReturn(null);
$service = Mockery::mock(Service::class)->makePartial();
$service->name = 'beszel-clx1ab2cd3ef4g5hi6jk7l8m9n0o1p2q3'; // CUID2 format
$service->id = 1;
$service->shouldReceive('applications')
->once()
->andReturn($query);
// Should not throw exception
applyServiceApplicationPrerequisites($service);
expect(true)->toBeTrue();
});
it('skips services without prerequisites', function () {
$service = Mockery::mock(Service::class)->makePartial();
$service->name = 'unknown-clx1ab2cd3ef4g5hi6jk7l8m9n0o1p2q3'; // CUID2 format
$service->id = 1;
$service->shouldNotReceive('applications');
applyServiceApplicationPrerequisites($service);
expect(true)->toBeTrue();
});
it('correctly parses service name with single hyphen', function () {
$service = Mockery::mock(Service::class)->makePartial();
$service->name = 'docker-registry-clx1ab2cd3ef4g5hi6jk7l8m9n0o1p2q3'; // CUID2 format
$service->id = 1;
$service->shouldNotReceive('applications');
// Should not throw exception - validates that 'docker-registry' is correctly parsed
applyServiceApplicationPrerequisites($service);
expect(true)->toBeTrue();
});
it('correctly parses service name with multiple hyphens', function () {
$service = Mockery::mock(Service::class)->makePartial();
$service->name = 'elasticsearch-with-kibana-clx1ab2cd3ef4g5hi6jk7l8m9n0o1p2q3'; // CUID2 format
$service->id = 1;
$service->shouldNotReceive('applications');
// Should not throw exception - validates that 'elasticsearch-with-kibana' is correctly parsed
applyServiceApplicationPrerequisites($service);
expect(true)->toBeTrue();
});
it('correctly parses service name with hyphens in template name', function () {
$service = Mockery::mock(Service::class)->makePartial();
$service->name = 'apprise-api-clx1ab2cd3ef4g5hi6jk7l8m9n0o1p2q3'; // CUID2 format
$service->id = 1;
$service->shouldNotReceive('applications');
// Should not throw exception - validates that 'apprise-api' is correctly parsed
applyServiceApplicationPrerequisites($service);
expect(true)->toBeTrue();
});

View File

@@ -4,7 +4,6 @@ use App\Actions\Server\UpdateCoolify;
use App\Models\InstanceSettings;
use App\Models\Server;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Http;
beforeEach(function () {
@@ -46,7 +45,7 @@ it('validates cache against running version before fallback', function () {
config(['constants.coolify.version' => '4.0.10']);
$action = new UpdateCoolify();
$action = new UpdateCoolify;
// Should throw exception - cache is older than running
try {
@@ -115,7 +114,7 @@ it('prevents downgrade even with manual update', function () {
// Current version is newer
config(['constants.coolify.version' => '4.0.10']);
$action = new UpdateCoolify();
$action = new UpdateCoolify;
\Illuminate\Support\Facades\Log::shouldReceive('error')
->once()