feat(service): warn when required environment variables are missing

Surface unset required service env vars in the configuration checker
popup and sidebar, refresh on env updates, and keep the env table
horizontally scrollable with correct managed/hardcoded pagination order.
This commit is contained in:
Andras Bacsai
2026-08-07 12:24:09 +02:00
parent 64d73b6922
commit fd6dbd5863
12 changed files with 209 additions and 66 deletions
@@ -211,6 +211,48 @@ it('searches service environment variables without requiring preview variables',
->and($component->instance()->showPreview)->toBeFalse();
});
it('pins required service environment variables only while their values are missing', function () {
$service = Service::factory()->create([
'environment_id' => $this->environment->id,
'docker_compose_raw' => <<<'YAML'
services:
app:
image: nginx
environment:
HARDCODED_FIRST: configured
YAML,
]);
EnvironmentVariable::create([
'key' => 'OPTIONAL_FIRST',
'value' => 'configured',
'order' => 1,
'resourceable_type' => Service::class,
'resourceable_id' => $service->id,
]);
$required = EnvironmentVariable::create([
'key' => 'REQUIRED_SECOND',
'value' => '',
'order' => 2,
'is_required' => true,
'resourceable_type' => Service::class,
'resourceable_id' => $service->id,
]);
$component = Livewire::test(All::class, ['resource' => $service])
->call('loadEnvironmentVariables');
expect($component->instance()->environmentVariablePageRows->pluck('environmentVariable.key')->all())
->toBe(['REQUIRED_SECOND', 'OPTIONAL_FIRST', 'HARDCODED_FIRST']);
$required->update(['value' => 'configured']);
$component->call('$refresh');
expect($component->instance()->environmentVariablePageRows->pluck('environmentVariable.key')->all())
->toBe(['OPTIONAL_FIRST', 'REQUIRED_SECOND', 'HARDCODED_FIRST']);
});
it('does not show the empty production message when search only matches hardcoded variables', function () {
$service = Service::factory()->create([
'environment_id' => $this->environment->id,
@@ -80,6 +80,19 @@ test('resource environment variables table has a Managed column and no name-cell
expect($show)->toContain('<x-helper :helper="e($comment)" />');
});
test('resource environment variables table remains horizontally scrollable on mobile', function () {
$view = file_get_contents(resource_path('views/livewire/project/shared/environment-variable/all.blade.php'));
$css = file_get_contents(resource_path('css/app.css'));
expect($view)
->toContain('environment-table-scroll')
->and($css)
->toContain(".environment-table-scroll {\n overflow-x: auto;")
->toContain(".environment-table-scroll .env-table-grid {\n min-width: 53rem;")
->not->toContain('.data-table-row.env-table-grid > :nth-child')
->not->toContain(".env-type-desktop {\n display: none");
});
test('shared environment variables table still omits Managed column', function () {
$editor = file_get_contents(resource_path('views/components/shared-variables/editor.blade.php'));
$show = file_get_contents(resource_path('views/livewire/project/shared/environment-variable/show.blade.php'));
@@ -104,7 +117,20 @@ test('managed environment variables are ordered first', function () {
expect($component)
->toContain("CASE WHEN key LIKE 'SERVICE_FQDN%'")
->toMatch("/'kind' => 'hardcoded',[\\s\\S]+?'kind' => 'managed'/");
->toMatch("/'kind' => 'managed',[\\s\\S]+?'kind' => 'hardcoded'/");
});
test('missing required environment variables are ordered before generated service variables', function () {
$component = file_get_contents(app_path('Livewire/Project/Shared/EnvironmentVariable/All.php'));
$requiredOrder = strpos($component, '$this->missingRequiredEnvironmentVariableIds($isPreview)', strpos($component, 'private function managedEnvironmentVariablesQuery'));
$generatedOrder = strpos($component, "CASE WHEN key LIKE 'SERVICE_FQDN%'", strpos($component, 'private function managedEnvironmentVariablesQuery'));
expect($requiredOrder)
->not->toBeFalse()
->toBeLessThan($generatedOrder)
->and($component)
->toContain('->filter(fn (EnvironmentVariable $environmentVariable): bool => $environmentVariable->is_really_required)');
});
test('environment variable toolbar does not use blade directives inside component attributes', function () {
@@ -7,6 +7,7 @@ use App\Models\Environment;
use App\Models\EnvironmentVariable;
use App\Models\LocalFileVolume;
use App\Models\Project;
use App\Models\Service;
use App\Models\Team;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
@@ -93,7 +94,35 @@ it('supports timed compact popup notifications', function () {
->toContain('@click="restore()"')
->toContain('@click.stop="minimizeToIcon()"')
->toContain('x-show="!iconOnly"')
->toContain('x-show="!compact"');
->toContain('x-show="!compact"')
->toContain("'w-[calc(100%-2rem)] sm:w-auto sm:max-w-[calc(100%-2rem)]'");
});
it('warns when a service has missing required environment variables', function () {
$service = Service::factory()->create(['environment_id' => $this->environment->id]);
$service->environment_variables()->create([
'key' => 'PLUNK_API_KEY',
'value' => '',
'is_required' => true,
]);
Livewire::test(ConfigurationChecker::class, ['resource' => $service])
->assertSet('missingRequiredEnvironmentVariableCount', 1)
->assertSee('Required environment variable missing')
->assertSee('PLUNK_API_KEY')
->assertSee('Open environment variables');
});
it('marks the service environment variables menu when required values are missing', function () {
$configuration = file_get_contents(resource_path('views/livewire/project/service/configuration.blade.php'));
$sidebar = file_get_contents(resource_path('views/components/service/configuration-sidebar.blade.php'));
expect($configuration)
->toContain("'hasWarning' => ! \$service->isDeployable")
->toContain('title="Required environment variables missing"')
->and($sidebar)
->toContain("'hasWarning' => ! \$service->isDeployable")
->toContain('title="Required environment variables missing"');
});
it('refreshes configuration changes when the event is received', function () {