From abd51d01b29a67795217d4e0e7d45f9ecd9ea62a Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 24 Nov 2026 17:15:24 +0000 Subject: [PATCH] Let environment:update set the read-only build token The API now reports uses_read_only_build_token on an environment and accepts it on update. The Environment DTO exposes it, so --json and --fields can return it, and environment:update takes --uses-read-only-build-token and offers it in the field picker. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01T1Sq4VgnsPT8SHCykH1gmJ --- .../Requests/UpdateEnvironmentRequestData.php | 2 ++ app/Commands/EnvironmentUpdate.php | 3 ++ app/Dto/Environment.php | 2 ++ tests/Feature/EnvironmentUpdateTest.php | 30 +++++++++++++++++-- 4 files changed, 35 insertions(+), 2 deletions(-) diff --git a/app/Client/Requests/UpdateEnvironmentRequestData.php b/app/Client/Requests/UpdateEnvironmentRequestData.php index 5b6b09d2..e139dc32 100644 --- a/app/Client/Requests/UpdateEnvironmentRequestData.php +++ b/app/Client/Requests/UpdateEnvironmentRequestData.php @@ -14,6 +14,7 @@ public function __construct( public readonly ?string $branch = null, public readonly ?bool $usesPushToDeploy = null, public readonly ?bool $usesDeployHook = null, + public readonly ?bool $usesReadOnlyBuildToken = null, public readonly ?int $timeout = null, public readonly ?string $phpVersion = null, public readonly ?string $buildCommand = null, @@ -65,6 +66,7 @@ public function toRequestData(): array 'branch' => $this->branch, 'uses_push_to_deploy' => $this->usesPushToDeploy, 'uses_deploy_hook' => $this->usesDeployHook, + 'uses_read_only_build_token' => $this->usesReadOnlyBuildToken, 'timeout' => $this->timeout, 'php_version' => $this->phpVersion, 'build_command' => $this->buildCommand, diff --git a/app/Commands/EnvironmentUpdate.php b/app/Commands/EnvironmentUpdate.php index 7c43b9af..8f5d4aff 100644 --- a/app/Commands/EnvironmentUpdate.php +++ b/app/Commands/EnvironmentUpdate.php @@ -42,6 +42,7 @@ class EnvironmentUpdate extends BaseCommand {--node-version= : Node version (20, 22, 24, 26)} {--uses-push-to-deploy= : Deploy on push} {--uses-deploy-hook= : Enable the deploy hook} + {--uses-read-only-build-token= : Clone the repository with a read-only token during builds (GitHub only)} {--uses-vanity-domain= : Serve the Laravel Cloud domain} {--uses-octane= : Uses Octane} {--http-basic-auth-password= : Require visitors to sign in as `admin` with this password; pass an empty value to turn basic auth off} @@ -116,6 +117,7 @@ protected function updateEnvironment(Environment $environment): Environment branch: $this->form()->get('branch'), usesPushToDeploy: $this->form()->boolean('uses_push_to_deploy'), usesDeployHook: $this->form()->boolean('uses_deploy_hook'), + usesReadOnlyBuildToken: $this->form()->boolean('uses_read_only_build_token'), timeout: $this->form()->integer('timeout'), phpVersion: $this->form()->get('php_version'), buildCommand: $this->form()->get('build_command'), @@ -331,6 +333,7 @@ protected function defineFields(Environment $environment): void $this->defineBoolean('uses_push_to_deploy', 'Push to deploy', $environment->usesPushToDeploy); $this->defineBoolean('uses_deploy_hook', 'Deploy hook', $environment->usesDeployHook); + $this->defineBoolean('uses_read_only_build_token', 'Read-only build token', $environment->usesReadOnlyBuildToken); $this->defineBoolean('uses_vanity_domain', 'Vanity domain', null); $this->defineBoolean('uses_octane', 'Octane', $environment->usesOctane); $this->form()->define( diff --git a/app/Dto/Environment.php b/app/Dto/Environment.php index 0a71809b..4158ea19 100644 --- a/app/Dto/Environment.php +++ b/app/Dto/Environment.php @@ -36,6 +36,7 @@ public function __construct( public readonly bool $usesHibernation = false, public readonly bool $usesPushToDeploy = false, public readonly bool $usesDeployHook = false, + public readonly bool $usesReadOnlyBuildToken = false, #[WithTransformer(MaskEnvironmentVariables::class)] public readonly array $environmentVariables = [], public readonly array $networkSettings = [], @@ -100,6 +101,7 @@ public static function createFromResponse(array $response): self 'usesHibernation' => $attributes['uses_hibernation'] ?? false, 'usesPushToDeploy' => $attributes['uses_push_to_deploy'] ?? false, 'usesDeployHook' => $attributes['uses_deploy_hook'] ?? false, + 'usesReadOnlyBuildToken' => $attributes['uses_read_only_build_token'] ?? false, 'environmentVariables' => $attributes['environment_variables'] ?? [], 'networkSettings' => $attributes['network_settings'] ?? [], 'createdAt' => $attributes['created_at'] ?? null, diff --git a/tests/Feature/EnvironmentUpdateTest.php b/tests/Feature/EnvironmentUpdateTest.php index 3c99defb..e2657248 100644 --- a/tests/Feature/EnvironmentUpdateTest.php +++ b/tests/Feature/EnvironmentUpdateTest.php @@ -32,6 +32,7 @@ 'shutdown_timeout' => 45, 'post_deploy_command' => 'php artisan cache:clear', 'uses_http_basic_auth' => true, + 'uses_read_only_build_token' => true, 'internal_networking' => [ 'enabled' => true, 'hostname' => 'production.internal', @@ -122,6 +123,7 @@ function updateEnvironment(array $options): void })->with([ ['uses-push-to-deploy', 'uses_push_to_deploy', 'false', false], ['uses-deploy-hook', 'uses_deploy_hook', 'true', true], + ['uses-read-only-build-token', 'uses_read_only_build_token', 'true', true], ['uses-vanity-domain', 'uses_vanity_domain', 'false', false], ['uses-octane', 'uses_octane', '0', false], ['uses-purge-edge-cache-on-deploy', 'uses_purge_edge_cache_on_deploy', '1', true], @@ -236,7 +238,7 @@ function updateEnvironment(array $options): void Artisan::registerCommand(new InteractiveEnvironmentUpdateCommand); Prompt::fake([ - ...array_fill(0, 14, Key::DOWN), Key::SPACE, Key::ENTER, + ...array_fill(0, 15, Key::DOWN), Key::SPACE, Key::ENTER, Key::ENTER, 'h', 'u', 'n', 't', 'e', 'r', '2', Key::ENTER, ]); @@ -253,7 +255,7 @@ function updateEnvironment(array $options): void Artisan::registerCommand(new InteractiveEnvironmentUpdateCommand); Prompt::fake([ - ...array_fill(0, 14, Key::DOWN), Key::SPACE, Key::ENTER, + ...array_fill(0, 15, Key::DOWN), Key::SPACE, Key::ENTER, 'n', Key::ENTER, ]); @@ -305,3 +307,27 @@ function updateEnvironment(array $options): void expect(json_decode(Artisan::output(), true))->toBe(['modelGatewayKeyId' => 'mgk-1']) ->and(explode(',', $this->sent->include))->toContain('modelGatewayKey'); }); + +it('exposes whether builds use a read-only token', function () { + Artisan::call('environment:get', [ + 'environment' => 'env-1', + '--json' => true, + '--fields' => 'usesReadOnlyBuildToken', + '--no-interaction' => true, + ]); + + expect(json_decode(Artisan::output(), true))->toBe(['usesReadOnlyBuildToken' => true]); +}); + +it('turns the read-only build token off interactively', function () { + Artisan::registerCommand(new InteractiveEnvironmentUpdateCommand); + + Prompt::fake([ + ...array_fill(0, 12, Key::DOWN), Key::SPACE, Key::ENTER, + 'n', Key::ENTER, + ]); + + $this->artisan('test:interactive-environment-update', ['environment' => 'env-1'])->assertSuccessful(); + + expect($this->sent->body)->toBe(['uses_read_only_build_token' => false]); +});