fix(deployments): load only commit details for the application heading

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Andras Bacsai
2026-10-28 22:53:30 +01:00
co-authored by Claude Opus 5.5
parent 68a08170e7
commit c23d3363f2
5 changed files with 191 additions and 30 deletions
+1 -1
View File
@@ -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'
+2 -2
View File
@@ -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()
+18 -3
View File
@@ -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');
}
});
+142 -24
View File
@@ -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');
});
@@ -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');
}
});