mirror of
https://github.com/coollabsio/coolify.git
synced 2026-09-28 02:06:37 -04:00
feat(logs): accept all for log lines and keep -1
API log endpoints and the GetLogs UI now treat `all` as unbounded output, with `-1` remaining as a compatibility alias. MCP still falls back to a positive default. Traefik version checks run from CheckForUpdatesJob instead of a weekly schedule.
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
use App\Jobs\CheckForUpdatesJob;
|
||||
use App\Jobs\CheckTraefikVersionJob;
|
||||
use App\Models\InstanceSettings;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Bus;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
it('checks installed Traefik versions after refreshing available versions', function () {
|
||||
Bus::fake();
|
||||
Http::fake([
|
||||
'*' => Http::response([
|
||||
'coolify' => ['v4' => ['version' => '4.0.10']],
|
||||
'traefik' => ['v3.7' => '3.7.13'],
|
||||
]),
|
||||
]);
|
||||
File::shouldReceive('exists')->andReturn(false);
|
||||
File::shouldReceive('put')->once();
|
||||
|
||||
InstanceSettings::forceCreate(['id' => 0]);
|
||||
|
||||
config([
|
||||
'app.env' => 'production',
|
||||
'constants.coolify.self_hosted' => true,
|
||||
'constants.coolify.version' => '4.0.10',
|
||||
]);
|
||||
|
||||
(new CheckForUpdatesJob)->handle();
|
||||
|
||||
Bus::assertDispatched(CheckTraefikVersionJob::class);
|
||||
});
|
||||
@@ -74,6 +74,29 @@ describe('GetLogs locked properties', function () {
|
||||
});
|
||||
|
||||
describe('GetLogs Livewire action validation', function () {
|
||||
test('getLogs requests all logs when the line count is minus one', function () {
|
||||
$this->server->settings->fill([
|
||||
'is_reachable' => true,
|
||||
'is_usable' => true,
|
||||
'force_disabled' => false,
|
||||
])->save();
|
||||
$server = Server::with('settings')->findOrFail($this->server->id);
|
||||
|
||||
Process::fake(['*' => Process::result(output: 'all logs')]);
|
||||
|
||||
Livewire::test(GetLogs::class, [
|
||||
'server' => $server,
|
||||
'resource' => $this->application,
|
||||
'container' => 'test-container',
|
||||
])
|
||||
->assertSee('All')
|
||||
->assertSeeHtml('title="Show all logs"')
|
||||
->call('showAllLogs')
|
||||
->assertSet('numberOfLines', -1);
|
||||
|
||||
Process::assertRan(fn ($process) => str_contains($process->command, 'docker logs -n all'));
|
||||
});
|
||||
|
||||
test('getLogs marks ANSI-colored output truncated based on raw bytes', function () {
|
||||
$this->server->settings->fill([
|
||||
'is_reachable' => true,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
use App\Mcp\Concerns\ResolvesResource;
|
||||
use App\Models\Server;
|
||||
|
||||
it('normalizes requested log line counts', function () {
|
||||
@@ -12,12 +13,44 @@ it('normalizes requested log line counts', function () {
|
||||
expect(normalizeLogLines(null))->toBe(100)
|
||||
->and(normalizeLogLines(''))->toBe(100)
|
||||
->and(normalizeLogLines('abc'))->toBe(100)
|
||||
->and(normalizeLogLines('0'))->toBe(100)
|
||||
->and(normalizeLogLines('all'))->toBe('all')
|
||||
->and(normalizeLogLines('ALL'))->toBe(100)
|
||||
->and(normalizeLogLines('-1'))->toBe('all')
|
||||
->and(normalizeLogLines('0'))->toBe(0)
|
||||
->and(normalizeLogLines('-5'))->toBe(100)
|
||||
->and(normalizeLogLines('50'))->toBe(50)
|
||||
->and(normalizeLogLines('50000'))->toBe(10000);
|
||||
});
|
||||
|
||||
it('keeps MCP log requests bounded', function () {
|
||||
$normalizer = new class
|
||||
{
|
||||
use ResolvesResource;
|
||||
|
||||
public function normalize(mixed $lines): int
|
||||
{
|
||||
return $this->normalizeMcpLogLines($lines);
|
||||
}
|
||||
};
|
||||
|
||||
expect($normalizer->normalize('all'))->toBe(100)
|
||||
->and($normalizer->normalize('-1'))->toBe(100)
|
||||
->and($normalizer->normalize('0'))->toBe(100)
|
||||
->and($normalizer->normalize('501'))->toBe(500);
|
||||
});
|
||||
|
||||
it('documents the named all logs option on every REST log endpoint', function (string $controller) {
|
||||
$source = file_get_contents(__DIR__."/../../../app/Http/Controllers/Api/{$controller}.php");
|
||||
|
||||
expect($source)->toContain('Use `all` to return all logs. `-1` remains available as a compatibility alias.');
|
||||
})->with([
|
||||
'applications' => 'ApplicationsController',
|
||||
'databases' => 'DatabasesController',
|
||||
'services' => 'ServicesController',
|
||||
'service applications' => 'ServiceApplicationsController',
|
||||
'service databases' => 'ServiceDatabasesController',
|
||||
]);
|
||||
|
||||
it('normalizes service resource log line counts before invoking Docker', function (string $controller, mixed $lines, int $expectedLines) {
|
||||
$source = file_get_contents(__DIR__."/../../../app/Http/Controllers/Api/{$controller}.php");
|
||||
|
||||
@@ -63,6 +96,16 @@ it('builds docker log commands with options before an escaped container id', fun
|
||||
->toBe("docker logs -n 25 --timestamps 'container-1' 2>&1");
|
||||
});
|
||||
|
||||
it('builds docker log commands for all and zero lines', function () {
|
||||
$server = new Server;
|
||||
$server->settings = ['is_swarm_manager' => false];
|
||||
|
||||
expect(buildContainerLogsCommand($server, 'container-1', 'all'))
|
||||
->toBe("docker logs -n all 'container-1' 2>&1")
|
||||
->and(buildContainerLogsCommand($server, 'container-1', 0))
|
||||
->toBe("docker logs -n 0 'container-1' 2>&1");
|
||||
});
|
||||
|
||||
it('builds swarm service log commands with options before an escaped service id', function () {
|
||||
if (! function_exists('buildContainerLogsCommand')) {
|
||||
expect(function_exists('buildContainerLogsCommand'))->toBeTrue();
|
||||
|
||||
Reference in New Issue
Block a user