From c23d3363f274a7d691dcf5f69fafedd167283532 Mon Sep 17 00:00:00 2001 From: Andras Bacsai <5845193+andrasbacsai@users.noreply.github.com> Date: Wed, 28 Oct 2026 22:53:30 +0100 Subject: [PATCH] fix(deployments): load only commit details for the application heading Co-Authored-By: Claude Opus 5.5 --- app/Livewire/Project/Application/Heading.php | 2 +- app/Models/Application.php | 4 +- tests/Feature/DashboardDeploymentsTest.php | 21 ++- .../Feature/DeploymentHistoryPayloadTest.php | 166 +++++++++++++++--- tests/Feature/DeploymentsIndicatorTest.php | 28 +++ 5 files changed, 191 insertions(+), 30 deletions(-) diff --git a/app/Livewire/Project/Application/Heading.php b/app/Livewire/Project/Application/Heading.php index 9b40240c19..182f96ae75 100644 --- a/app/Livewire/Project/Application/Heading.php +++ b/app/Livewire/Project/Application/Heading.php @@ -61,7 +61,7 @@ class Heading extends Component 'environment_uuid' => $this->application->environment->uuid, 'application_uuid' => $this->application->uuid, ]; - $lastDeployment = $this->application->get_last_successful_deployment(); + $lastDeployment = $this->application->get_last_successful_deployment(['commit', 'commit_message']); $this->lastDeploymentInfo = data_get_str($lastDeployment, 'commit')->limit(7).' '.data_get($lastDeployment, 'commit_message'); $this->lastDeploymentLink = $this->application->gitCommitLink(data_get($lastDeployment, 'commit')); $this->loadComposeOnOpen = $this->activeRouteName === 'project.application.configuration' diff --git a/app/Models/Application.php b/app/Models/Application.php index 93fd9d695f..084eb0fb25 100644 --- a/app/Models/Application.php +++ b/app/Models/Application.php @@ -1293,9 +1293,9 @@ class Application extends BaseModel return false; } - public function get_last_successful_deployment() + public function get_last_successful_deployment(array $columns = ['*']) { - return ApplicationDeploymentQueue::where('application_id', $this->id)->where('status', ApplicationDeploymentStatus::FINISHED->value)->where('pull_request_id', 0)->orderBy('created_at', 'desc')->first(); + return ApplicationDeploymentQueue::where('application_id', $this->id)->where('status', ApplicationDeploymentStatus::FINISHED->value)->where('pull_request_id', 0)->orderBy('created_at', 'desc')->first($columns); } public function get_last_days_deployments() diff --git a/tests/Feature/DashboardDeploymentsTest.php b/tests/Feature/DashboardDeploymentsTest.php index e35d3a07c3..bec45a4985 100644 --- a/tests/Feature/DashboardDeploymentsTest.php +++ b/tests/Feature/DashboardDeploymentsTest.php @@ -178,7 +178,16 @@ it('only includes deployments of applications owned by the current team', functi }); it('does not load deployment payload columns when the dashboard list polls', function () { - createDashboardDeployment(['logs' => '[{"output":"large deployment log"}]']); + createDashboardDeployment([ + 'logs' => json_encode([['output' => str_repeat('large deployment log ', 20000)]]), + 'configuration_snapshot' => ['docker_compose_raw' => str_repeat('x', 100000)], + 'configuration_diff' => ['fqdn' => ['old' => null, 'new' => 'https://example.com']], + ]); + createDashboardDeployment([ + 'application_name' => 'Dashboard App', + 'status' => ApplicationDeploymentStatus::IN_PROGRESS->value, + 'logs' => json_encode([['output' => str_repeat('large deployment log ', 20000)]]), + ]); $deploymentQueries = []; DB::listen(function ($query) use (&$deploymentQueries) { @@ -190,10 +199,16 @@ it('does not load deployment payload columns when the dashboard list polls', fun Livewire::test(ActiveDeployments::class) ->assertSee('Dashboard App') ->call('refreshDeployments') - ->assertSee('Dashboard App'); + ->assertSee('Dashboard App') + ->call('$refresh') + ->assertSee('Running or queued right now') + ->assertSee('Recent deployments'); expect($deploymentQueries)->not->toBeEmpty(); foreach ($deploymentQueries as $sql) { - expect($sql)->not->toMatch('/select\s+("?\w+"?\.)?\*/i')->not->toContain('logs'); + expect($sql)->not->toMatch('/select\s+("?\w+"?\.)?\*/i') + ->not->toContain('logs') + ->not->toContain('configuration_snapshot') + ->not->toContain('configuration_diff'); } }); diff --git a/tests/Feature/DeploymentHistoryPayloadTest.php b/tests/Feature/DeploymentHistoryPayloadTest.php index 76a96006ee..f5ac14a185 100644 --- a/tests/Feature/DeploymentHistoryPayloadTest.php +++ b/tests/Feature/DeploymentHistoryPayloadTest.php @@ -2,6 +2,8 @@ use App\Enums\ApplicationDeploymentStatus; use App\Livewire\Project\Application\Deployment\Index; +use App\Livewire\Project\Application\Deployment\Show; +use App\Livewire\Project\Application\Heading; use App\Models\Application; use App\Models\ApplicationDeploymentQueue; use App\Models\Environment; @@ -37,7 +39,16 @@ beforeEach(function () { 'destination_type' => $destination->getMorphClass(), ]); - $this->createDeployment = fn (string $uuid, string $createdAt) => ApplicationDeploymentQueue::query()->forceCreate([ + $this->largeLog = json_encode([[ + 'command' => null, + 'output' => str_repeat('large deployment log ', 20000), + 'type' => 'stdout', + 'timestamp' => '2026-10-01T10:00:00.000000Z', + 'hidden' => false, + 'batch' => 1, + 'order' => 1, + ]]); + $this->createDeployment = fn (string $uuid, string $createdAt, array $overrides = []) => ApplicationDeploymentQueue::query()->forceCreate([ 'application_id' => $this->application->id, 'deployment_uuid' => $uuid, 'server_id' => $server->id, @@ -45,23 +56,67 @@ beforeEach(function () { 'status' => ApplicationDeploymentStatus::FINISHED->value, 'commit' => 'abcdef1234567890', 'commit_message' => "Message of {$uuid}", - 'logs' => '[{"output":"large deployment log"}]', - 'configuration_snapshot' => ['fqdn' => 'https://example.com'], + 'logs' => $this->largeLog, + 'configuration_snapshot' => ['fqdn' => 'https://example.com', 'docker_compose_raw' => str_repeat('x', 100000)], 'configuration_diff' => ['fqdn' => ['old' => null, 'new' => 'https://example.com']], 'created_at' => $createdAt, 'updated_at' => $createdAt, + ...$overrides, ]); -}); -it('does not load deployment payload columns for the history list on any Livewire request', function () { - ($this->createDeployment)('deployment-history-row', '2026-10-01 10:00:00'); - - $historyQueries = []; - DB::listen(function ($query) use (&$historyQueries) { + $this->deploymentQueries = collect(); + $this->recordDeploymentQueries = fn () => DB::listen(function ($query) { if (str_contains($query->sql, 'application_deployment_queues')) { - $historyQueries[] = $query->sql; + $this->deploymentQueries->push($query->sql); } }); + $this->assertNoPayloadQueries = function () { + expect($this->deploymentQueries)->not->toBeEmpty(); + $this->deploymentQueries->each(fn (string $sql) => expect($sql) + ->not->toMatch('/select\s+("?\w+"?\.)?\*/i') + ->not->toContain('logs') + ->not->toContain('configuration_snapshot') + ->not->toContain('configuration_diff')); + }; +}); + +function otherTeamDeployment(): array +{ + $team = Team::factory()->create(); + $server = Server::factory()->create(['team_id' => $team->id]); + $destination = StandaloneDocker::query()->where('server_id', $server->id)->firstOrFail(); + $project = Project::factory()->create(['team_id' => $team->id]); + $environment = Environment::factory()->create(['project_id' => $project->id]); + $application = Application::factory()->create([ + 'environment_id' => $environment->id, + 'destination_id' => $destination->id, + 'destination_type' => $destination->getMorphClass(), + ]); + $deployment = ApplicationDeploymentQueue::query()->forceCreate([ + 'application_id' => $application->id, + 'deployment_uuid' => 'other-team-deployment', + 'server_id' => $server->id, + 'status' => ApplicationDeploymentStatus::FINISHED->value, + 'logs' => '[{"output":"other team log"}]', + ]); + + return [ + 'project_uuid' => $project->uuid, + 'environment_uuid' => $environment->uuid, + 'application_uuid' => $application->uuid, + 'deployment_uuid' => $deployment->deployment_uuid, + ]; +} + +it('does not load deployment payload columns for the history list on any Livewire request', function () { + foreach (range(1, 4) as $number) { + ($this->createDeployment)("history-d{$number}", "2026-10-0{$number} 10:00:00"); + } + ($this->createDeployment)('history-d5', '2026-10-05 10:00:00', [ + 'status' => ApplicationDeploymentStatus::FAILED->value, + 'pull_request_id' => 7, + ]); + ($this->recordDeploymentQueries)(); Livewire::test(Index::class, [ 'project_uuid' => $this->project->uuid, @@ -69,21 +124,84 @@ it('does not load deployment payload columns for the history list on any Livewir 'application_uuid' => $this->application->uuid, 'embedded' => true, ]) - ->assertSee('deployment-history-row') - ->assertSee('Message of deployment-history-row') + ->assertSeeInOrder(['history-d5', 'history-d4', 'history-d3']) + ->assertSee('Message of history-d5') + ->assertDontSee('history-d2') ->call('reloadDeployments') - ->assertSee('deployment-history-row') + ->assertSee('history-d5') + ->call('nextPage') + ->assertSeeInOrder(['history-d2', 'history-d1']) + ->assertDontSee('history-d5') + ->call('previousPage') + ->assertSee('history-d5') + ->assertDontSee('history-d2') + ->call('goToPage', 2) + ->assertSee('history-d1') + ->call('toggleDeploymentFilter', 'status:failed') + ->assertSee('history-d5') + ->assertDontSee('history-d4') + ->call('toggleDeploymentFilter', 'status:failed') + ->call('setPullRequestFilter', '7') + ->assertSee('history-d5') + ->assertDontSee('history-d4') + ->call('clearFilter') + ->set('search', 'history-d3') + ->assertSee('history-d3') + ->assertDontSee('history-d4') + ->set('search', '') ->call('setDeploymentSort', 'oldest') - ->assertSee('deployment-history-row'); + ->assertSeeInOrder(['history-d1', 'history-d2', 'history-d3']) + ->assertDontSee('history-d5') + ->set('defaultTake', 10) + ->assertSee('history-d5') + ->assertSee('history-d1') + ->call('$refresh') + ->assertSee('history-d5') + ->dispatch('deploymentSelected', deploymentUuid: 'history-d2') + ->assertSet('selectedDeploymentUuid', 'history-d2') + ->assertSee('history-d2'); - expect($historyQueries)->not->toBeEmpty(); - foreach ($historyQueries as $sql) { - expect($sql) - ->not->toMatch('/select\s+("?\w+"?\.)?\*/i') - ->not->toContain('logs') - ->not->toContain('configuration_snapshot') - ->not->toContain('configuration_diff'); - } + ($this->assertNoPayloadQueries)(); +}); + +it('does not show the deployment history of another team', function () { + $otherTeam = otherTeamDeployment(); + unset($otherTeam['deployment_uuid']); + + Livewire::test(Index::class, $otherTeam) + ->assertRedirect(route('dashboard')) + ->assertDontSee('other-team-deployment'); +}); + +it('loads the full logs and configuration when an authorized user opens a deployment', function () { + ($this->createDeployment)('full-detail', '2026-10-01 10:00:00'); + + $component = Livewire::test(Show::class, [ + 'project_uuid' => $this->project->uuid, + 'environment_uuid' => $this->environment->uuid, + 'application_uuid' => $this->application->uuid, + 'deployment_uuid' => 'full-detail', + ])->call('polling'); + + $deployment = $component->get('application_deployment_queue'); + expect($deployment->logs)->toBe($this->largeLog) + ->and($deployment->configuration_snapshot['docker_compose_raw'])->toBe(str_repeat('x', 100000)); +}); + +it('does not open a deployment of another team', function () { + Livewire::test(Show::class, otherTeamDeployment()) + ->assertRedirect(route('dashboard')) + ->assertDontSee('other team log'); +}); + +it('loads only the commit of the last successful deployment for the application heading', function () { + ($this->createDeployment)('heading-deployment', '2026-10-01 10:00:00', ['commit_message' => 'Heading commit']); + ($this->recordDeploymentQueries)(); + + Livewire::test(Heading::class, ['application' => $this->application]) + ->assertSet('lastDeploymentInfo', 'abcdef1... Heading commit'); + + ($this->assertNoPayloadQueries)(); }); it('orders and pages deployments with equal timestamps by id in both directions', function () { @@ -106,6 +224,6 @@ it('keeps the full deployment payload for callers that do not restrict the colum $full = $this->application->deployments()['deployments']->sole(); expect($listed->getAttributes())->not->toHaveKeys(['logs', 'configuration_snapshot', 'configuration_diff']) - ->and($full->logs)->toBe('[{"output":"large deployment log"}]') - ->and($full->configuration_snapshot)->toBe(['fqdn' => 'https://example.com']); + ->and($full->logs)->toBe($this->largeLog) + ->and($full->configuration_snapshot['fqdn'])->toBe('https://example.com'); }); diff --git a/tests/Feature/DeploymentsIndicatorTest.php b/tests/Feature/DeploymentsIndicatorTest.php index c89ce6c12d..f0b54a9e26 100644 --- a/tests/Feature/DeploymentsIndicatorTest.php +++ b/tests/Feature/DeploymentsIndicatorTest.php @@ -12,6 +12,7 @@ use App\Models\StandaloneDocker; use App\Models\Team; use App\Models\User; use Illuminate\Foundation\Testing\RefreshDatabase; +use Illuminate\Support\Facades\DB; use Livewire\Livewire; uses(RefreshDatabase::class); @@ -113,3 +114,30 @@ it('keeps the indicator on an application page when another application is deplo ->assertSee('2 deployments', false) ->assertSee('aria-label="Active deployments"', false); }); + +it('does not load deployment payload columns when the indicator refreshes', function () { + ApplicationDeploymentQueue::query()->update([ + 'logs' => json_encode([['output' => str_repeat('large deployment log ', 20000)]]), + 'configuration_snapshot' => json_encode(['docker_compose_raw' => str_repeat('x', 100000)]), + ]); + + $deploymentQueries = []; + DB::listen(function ($query) use (&$deploymentQueries) { + if (str_contains($query->sql, 'application_deployment_queues')) { + $deploymentQueries[] = $query->sql; + } + }); + + Livewire::test(DeploymentsIndicator::class) + ->assertSee('Indicator App') + ->call('$refresh') + ->assertSee('Indicator App'); + + expect($deploymentQueries)->not->toBeEmpty(); + foreach ($deploymentQueries as $sql) { + expect($sql)->not->toMatch('/select\s+("?\w+"?\.)?\*/i') + ->not->toContain('logs') + ->not->toContain('configuration_snapshot') + ->not->toContain('configuration_diff'); + } +});