|
3 | 3 | use App\Livewire\Project\Shared\GetLogs; |
4 | 4 | use App\Models\Application; |
5 | 5 | use App\Models\Environment; |
| 6 | +use App\Models\PrivateKey; |
6 | 7 | use App\Models\Project; |
7 | 8 | use App\Models\Server; |
8 | 9 | use App\Models\StandaloneDocker; |
9 | 10 | use App\Models\Team; |
10 | 11 | use App\Models\User; |
11 | 12 | use App\Support\ValidationPatterns; |
12 | 13 | use Illuminate\Foundation\Testing\RefreshDatabase; |
| 14 | +use Illuminate\Process\FakeProcessResult; |
| 15 | +use Illuminate\Support\Facades\Process; |
13 | 16 | use Livewire\Attributes\Locked; |
14 | 17 | use Livewire\Livewire; |
15 | 18 |
|
|
20 | 23 | $this->team = Team::factory()->create(); |
21 | 24 | $this->user->teams()->attach($this->team, ['role' => 'owner']); |
22 | 25 |
|
23 | | - $this->server = Server::factory()->create(['team_id' => $this->team->id]); |
| 26 | + $privateKey = PrivateKey::factory()->create(['team_id' => $this->team->id]); |
| 27 | + $this->server = Server::factory()->create([ |
| 28 | + 'team_id' => $this->team->id, |
| 29 | + 'private_key_id' => $privateKey->id, |
| 30 | + ]); |
24 | 31 | // Server::created auto-creates a StandaloneDocker, reuse it |
25 | 32 | $this->destination = StandaloneDocker::where('server_id', $this->server->id)->first(); |
26 | 33 | $this->project = Project::factory()->create(['team_id' => $this->team->id]); |
|
67 | 74 | }); |
68 | 75 |
|
69 | 76 | describe('GetLogs Livewire action validation', function () { |
| 77 | + test('getLogs marks ANSI-colored output truncated based on raw bytes', function () { |
| 78 | + $this->server->settings->fill([ |
| 79 | + 'is_reachable' => true, |
| 80 | + 'is_usable' => true, |
| 81 | + 'force_disabled' => false, |
| 82 | + ])->save(); |
| 83 | + $server = Server::with('settings')->find($this->server->id); |
| 84 | + $output = "\e[31m".str_repeat('a', GetLogs::MAX_DISPLAY_SIZE_BYTES - 4); |
| 85 | + |
| 86 | + expect(strlen($output))->toBe(GetLogs::MAX_DISPLAY_SIZE_BYTES + 1); |
| 87 | + |
| 88 | + Process::shouldReceive('timeout')->once()->andReturnSelf(); |
| 89 | + Process::shouldReceive('run')->andReturnUsing(function (string $command, ?callable $callback = null) use ($output): FakeProcessResult { |
| 90 | + if ($callback) { |
| 91 | + $callback('out', $output); |
| 92 | + } |
| 93 | + |
| 94 | + return new FakeProcessResult(command: $command); |
| 95 | + }); |
| 96 | + |
| 97 | + $component = new GetLogs; |
| 98 | + $component->server = $server; |
| 99 | + $component->resource = $this->application; |
| 100 | + $component->container = 'test-container'; |
| 101 | + $component->showTimeStamps = false; |
| 102 | + $component->getLogs(true); |
| 103 | + |
| 104 | + expect($component->outputs) |
| 105 | + ->toContain('[... Output truncated at 5MB limit ...]') |
| 106 | + ->not->toContain("\e[31m"); |
| 107 | + }); |
| 108 | + |
70 | 109 | test('getLogs rejects invalid container name', function () { |
71 | 110 | // Make server functional by setting settings directly |
72 | 111 | $this->server->settings->fill([ |
|
0 commit comments