From 201c9fada342f5584414164f2f7f0cde3a4425e9 Mon Sep 17 00:00:00 2001 From: Andras Bacsai <5845193+andrasbacsai@users.noreply.github.com> Date: Tue, 18 Nov 2025 12:47:43 +0100 Subject: [PATCH] feat: limit comment field to 256 characters for environment variables --- .../Shared/EnvironmentVariable/Show.php | 4 +-- ...comment_to_environment_variables_table.php | 4 +-- .../environment-variable/show.blade.php | 7 ++-- .../EnvironmentVariableCommentTest.php | 32 ++++++++++++++++++- 4 files changed, 38 insertions(+), 9 deletions(-) diff --git a/app/Livewire/Project/Shared/EnvironmentVariable/Show.php b/app/Livewire/Project/Shared/EnvironmentVariable/Show.php index 33a2c83b9..75149a0d4 100644 --- a/app/Livewire/Project/Shared/EnvironmentVariable/Show.php +++ b/app/Livewire/Project/Shared/EnvironmentVariable/Show.php @@ -65,7 +65,7 @@ class Show extends Component protected $rules = [ 'key' => 'required|string', 'value' => 'nullable', - 'comment' => 'nullable|string|max:1000', + 'comment' => 'nullable|string|max:256', 'is_multiline' => 'required|boolean', 'is_literal' => 'required|boolean', 'is_shown_once' => 'required|boolean', @@ -107,7 +107,7 @@ public function syncData(bool $toModel = false) $this->validate([ 'key' => 'required|string', 'value' => 'nullable', - 'comment' => 'nullable|string|max:1000', + 'comment' => 'nullable|string|max:256', 'is_multiline' => 'required|boolean', 'is_literal' => 'required|boolean', 'is_shown_once' => 'required|boolean', diff --git a/database/migrations/2025_11_17_145255_add_comment_to_environment_variables_table.php b/database/migrations/2025_11_17_145255_add_comment_to_environment_variables_table.php index 0e17e720f..abbae3573 100644 --- a/database/migrations/2025_11_17_145255_add_comment_to_environment_variables_table.php +++ b/database/migrations/2025_11_17_145255_add_comment_to_environment_variables_table.php @@ -12,11 +12,11 @@ public function up(): void { Schema::table('environment_variables', function (Blueprint $table) { - $table->text('comment')->nullable(); + $table->string('comment', 256)->nullable(); }); Schema::table('shared_environment_variables', function (Blueprint $table) { - $table->text('comment')->nullable(); + $table->string('comment', 256)->nullable(); }); } diff --git a/resources/views/livewire/project/shared/environment-variable/show.blade.php b/resources/views/livewire/project/shared/environment-variable/show.blade.php index 259f90828..80b607bd7 100644 --- a/resources/views/livewire/project/shared/environment-variable/show.blade.php +++ b/resources/views/livewire/project/shared/environment-variable/show.blade.php @@ -121,6 +121,7 @@ @endif + @else
@@ -136,7 +137,7 @@ @endif
- + @endif @else @@ -148,9 +149,7 @@ @endif - @if (!$isDisabled) - - @endif + @endcan @can('update', $this->env) diff --git a/tests/Feature/EnvironmentVariableCommentTest.php b/tests/Feature/EnvironmentVariableCommentTest.php index 05126c23a..5efb2b953 100644 --- a/tests/Feature/EnvironmentVariableCommentTest.php +++ b/tests/Feature/EnvironmentVariableCommentTest.php @@ -85,7 +85,7 @@ 'resourceable_id' => $this->application->id, ]); - // The model's booted() method should create a preview version + // The model's created() event listener automatically creates a preview version $previewEnv = EnvironmentVariable::where('key', 'TEST_VAR') ->where('resourceable_id', $this->application->id) ->where('is_preview', true) @@ -118,3 +118,33 @@ expect($env1->value)->toBe('value_with_#_in_it'); expect($env1->comment)->toBe('Contains hash symbol'); }); + +test('environment variable comment can store up to 256 characters', function () { + $comment = str_repeat('a', 256); + $env = EnvironmentVariable::create([ + 'key' => 'TEST_VAR', + 'value' => 'test_value', + 'comment' => $comment, + 'resourceable_type' => Application::class, + 'resourceable_id' => $this->application->id, + ]); + + expect($env->comment)->toBe($comment); + expect(strlen($env->comment))->toBe(256); +}); + +test('environment variable comment cannot exceed 256 characters via Livewire', function () { + $env = EnvironmentVariable::create([ + 'key' => 'TEST_VAR', + 'value' => 'test_value', + 'resourceable_type' => Application::class, + 'resourceable_id' => $this->application->id, + ]); + + $longComment = str_repeat('a', 257); + + Livewire::test(\App\Livewire\Project\Shared\EnvironmentVariable\Show::class, ['env' => $env, 'type' => 'application']) + ->set('comment', $longComment) + ->call('submit') + ->assertHasErrors(['comment' => 'max']); +});