From a385500963dd3a3ba700e18bc621d50c1a6d554d Mon Sep 17 00:00:00 2001 From: Amp Date: Sun, 15 Nov 2026 09:50:41 +0000 Subject: [PATCH 1/4] Attach bucket keys with environment:update --bucket-keys The API attaches object storage to an environment through filesystem_keys on PATCH /environments/{environment}, but no command set it, so buckets could only be attached from the dashboard. --bucket-keys takes comma-separated KEY_ID:DISK entries, with :default on at most one. The API replaces the whole list, so the option names every bucket the environment should end up with, an empty string detaches them all, and replacing buckets that are already attached needs --force. Environments now include their buckets, so environment:get reports bucketIds. Amp-Thread-ID: https://ampcode.com/threads/T-01a1de2b-3aa5-7684-a19c-87386ad7c591 Co-authored-by: Ed Grosvenor --- app/Client/Resources/EnvironmentsResource.php | 1 + app/Commands/EnvironmentUpdate.php | 120 +++++++++++++++++ app/Dto/Environment.php | 6 + skills/deploying-to-cloud/SKILL.md | 2 + .../reference/checklists.md | 1 + .../Feature/EnvironmentRelationshipsTest.php | 121 +++++++++++++++++- 6 files changed, 250 insertions(+), 1 deletion(-) diff --git a/app/Client/Resources/EnvironmentsResource.php b/app/Client/Resources/EnvironmentsResource.php index e814f9d3..b41dc6f4 100644 --- a/app/Client/Resources/EnvironmentsResource.php +++ b/app/Client/Resources/EnvironmentsResource.php @@ -172,6 +172,7 @@ public function withDefaultIncludes(): static 'database', 'cache', 'websocketApplication', + 'buckets', ); } } diff --git a/app/Commands/EnvironmentUpdate.php b/app/Commands/EnvironmentUpdate.php index b40d67c9..90550422 100644 --- a/app/Commands/EnvironmentUpdate.php +++ b/app/Commands/EnvironmentUpdate.php @@ -3,9 +3,11 @@ namespace App\Commands; use App\Client\Requests\UpdateEnvironmentRequestData; +use App\Dto\BucketKey; use App\Dto\Cache; use App\Dto\Database; use App\Dto\Environment; +use App\Dto\ObjectStorageBucket; use App\Dto\WebsocketApplication; use App\Dto\WebsocketCluster; use App\Enums\EnvironmentColor; @@ -59,6 +61,7 @@ class EnvironmentUpdate extends BaseCommand {--database-id= : Database ID to attach (empty string to detach)} {--cache-id= : Cache ID to attach (empty string to detach)} {--websocket-application-id= : WebSocket application ID to attach (empty string to detach)} + {--bucket-keys= : Bucket keys to attach as comma-separated KEY_ID:DISK entries, with :default on at most one (fk-1:local:default,fk-2:public). Replaces every attached bucket; empty string to detach all} {--force : Force update without confirmation}'; protected $description = 'Update an environment'; @@ -95,6 +98,8 @@ public function handle() protected function updateEnvironment(Environment $environment): Environment { + $filesystemKeys = $this->filesystemKeys($environment); + spin( fn () => $this->client->environments()->update( new UpdateEnvironmentRequestData( @@ -128,6 +133,7 @@ protected function updateEnvironment(Environment $environment): Environment responseHeadersHsts: $this->hsts($environment), firewallBlockPath: $this->form()->boolean('firewall_block_path'), firewallBrowserIntegrityCheck: $this->form()->boolean('firewall_browser_integrity_check'), + filesystemKeys: $filesystemKeys, ), ), 'Updating environment...', @@ -136,6 +142,61 @@ protected function updateEnvironment(Environment $environment): Environment return $this->client->environments()->get($environment->id); } + /** + * The API takes the attached buckets as one list and replaces it, so the option names every bucket the environment should end up with. + * + * @return array|null + */ + protected function filesystemKeys(Environment $environment): ?array + { + $value = $this->form()->get('bucket_keys'); + + if ($value === null) { + return null; + } + + $keys = $this->parseBucketKeys($value); + + $attached = spin( + fn () => $this->client->environments()->include('buckets')->get($environment->id)->bucketIds, + 'Fetching attached buckets...', + ); + + if ($attached !== []) { + $this->confirmDestructive($keys === [] + ? "Detach every bucket from {$environment->name}?" + : "Replace the buckets attached to {$environment->name}? Any attached bucket not listed will be detached."); + } + + return $keys; + } + + /** + * @return array + */ + protected function parseBucketKeys(string $value): array + { + if (trim($value) === '') { + return []; + } + + $keys = collect(explode(',', $value))->map(function (string $entry) { + $parts = array_map(trim(...), explode(':', $entry)); + + if (count($parts) < 2 || count($parts) > 3 || $parts[0] === '' || $parts[1] === '' || (isset($parts[2]) && $parts[2] !== 'default')) { + $this->failAndExit("Invalid bucket key entry: {$entry}. Use KEY_ID:DISK, or KEY_ID:DISK:default for the default disk."); + } + + return ['id' => $parts[0], 'disk' => $parts[1], 'is_default_disk' => isset($parts[2])]; + }); + + if ($keys->where('is_default_disk', true)->count() > 1) { + $this->failAndExit('Only one bucket can be the default disk.'); + } + + return $keys->values()->all(); + } + protected function clearableInteger(string $key): int|string|null { $value = $this->form()->get($key); @@ -348,6 +409,14 @@ protected function defineFields(Environment $environment): void ), 'websocket-application-id', )->setPreviousValue($environment->websocketApplicationId ?? ''); + + $this->form()->define( + 'bucket_keys', + fn ($resolver) => $resolver->fromInput( + fn ($value) => $this->selectBucketKeys(), + ), + 'bucket-keys', + )->setLabel('Buckets'); } /** @@ -534,6 +603,57 @@ protected function selectWebsocketApplication(?string $value, ?string $currentId ); } + protected function selectBucketKeys(): string + { + $buckets = spin( + fn () => $this->client->objectStorageBuckets()->list()->collect(), + 'Fetching buckets...', + ); + + if ($buckets->isEmpty()) { + $this->failAndExit('No buckets found. Create one with `cloud bucket:create`.'); + } + + $entries = []; + $hasDefault = false; + + do { + $bucketId = (string) select( + label: $entries === [] ? 'Bucket' : 'Another bucket', + options: ($entries === [] ? ['' => '— Detach all —'] : []) + $buckets->mapWithKeys( + fn (ObjectStorageBucket $bucket) => [$bucket->id => $bucket->name], + )->all(), + ); + + if ($bucketId === '') { + return ''; + } + + $keys = spin( + fn () => $this->client->bucketKeys()->list($bucketId)->collect(), + 'Fetching bucket keys...', + ); + + if ($keys->isEmpty()) { + $this->failAndExit('That bucket has no keys. Create one with `cloud bucket-key:create`.'); + } + + $keyId = (string) select( + label: 'Bucket key', + options: $keys->mapWithKeys(fn (BucketKey $key) => [$key->id => "{$key->name} ({$key->permission})"])->all(), + ); + + $disk = text(label: 'Disk name', placeholder: 'public', required: true); + + $isDefault = ! $hasDefault && confirm(label: 'Make it the default disk?', default: false); + $hasDefault = $hasDefault || $isDefault; + + $entries[] = $isDefault ? "{$keyId}:{$disk}:default" : "{$keyId}:{$disk}"; + } while (confirm(label: 'Attach another bucket?', default: false)); + + return implode(',', $entries); + } + protected function collectDataAndUpdate(Environment $environment): Environment { $selection = multiselect( diff --git a/app/Dto/Environment.php b/app/Dto/Environment.php index 65c48482..0e7fb37d 100644 --- a/app/Dto/Environment.php +++ b/app/Dto/Environment.php @@ -50,6 +50,8 @@ public function __construct( public readonly ?string $databaseSchemaId = null, public readonly ?string $cacheId = null, public readonly ?string $websocketApplicationId = null, + /** IDs of the attached buckets. The API does not say which key or disk each one uses. */ + public readonly array $bucketIds = [], #[DataCollectionOf(Secret::class)] public readonly array $secrets = [], public readonly ?EnvironmentResend $resend = null, @@ -148,6 +150,10 @@ public static function createFromResponse(array $response): self $transformed['websocketApplicationId'] = $relationships['websocketApplication']['data']['id']; } + if (isset($relationships['buckets']['data'])) { + $transformed['bucketIds'] = array_column($relationships['buckets']['data'], 'id'); + } + if (isset($relationships['secrets']['data'])) { $secretIds = array_column($relationships['secrets']['data'], 'id'); diff --git a/skills/deploying-to-cloud/SKILL.md b/skills/deploying-to-cloud/SKILL.md index 07023154..c599e701 100644 --- a/skills/deploying-to-cloud/SKILL.md +++ b/skills/deploying-to-cloud/SKILL.md @@ -106,6 +106,8 @@ Determine the task and follow the matching path: - Secrets: `echo "$VALUE" | cloud secret:create --name=NAME --json -n`, then `cloud environment-secret:attach` +- Buckets: `cloud environment:update {environment} --bucket-keys=KEY_ID:DISK:default,KEY_ID:public --json -n --force` attaches bucket keys, read from `cloud bucket-key:list {bucket} --json -n`. It replaces every attached bucket, so list all of them; `--force` is needed when buckets are already attached + - Provision infrastructure: `cloud :create --json -n` - Brand new project (no code yet): `cloud new --starter-kit= --repository=/ --path= -n` creates a private GitHub repository from the starter kit, deploys it (with a database for Laravel kits), and clones it to ``. The repository must not exist yet. Run `cloud new -h` for the kits. diff --git a/skills/deploying-to-cloud/reference/checklists.md b/skills/deploying-to-cloud/reference/checklists.md index 5ddc94c2..f9fd9c3b 100644 --- a/skills/deploying-to-cloud/reference/checklists.md +++ b/skills/deploying-to-cloud/reference/checklists.md @@ -9,6 +9,7 @@ Use these checklists when performing complex setups. Copy the relevant checklist - [ ] Create the environment - [ ] Provision the database (`database-cluster:create` then `database:create`) - [ ] Provision the cache (`cache:create`) +- [ ] Create and attach any buckets (`bucket:create`, then `environment:update --bucket-keys`) - [ ] Set environment variables (`environment:variables`) - [ ] Create and attach any secrets (`secret:create` then `environment-secret:attach`) - [ ] Attach custom domain (`domain:create` then `domain:verify`) diff --git a/tests/Feature/EnvironmentRelationshipsTest.php b/tests/Feature/EnvironmentRelationshipsTest.php index 10ee19e5..90bcc5bb 100644 --- a/tests/Feature/EnvironmentRelationshipsTest.php +++ b/tests/Feature/EnvironmentRelationshipsTest.php @@ -30,7 +30,7 @@ * The API returns a relationship only when the request asked to include it, so * the fake has to drop anything the caller did not request. */ -function attachedEnvironmentResponse(?string $include): array +function attachedEnvironmentResponse(?string $include, array $bucketIds = []): array { $requested = explode(',', $include ?? ''); @@ -39,6 +39,7 @@ function attachedEnvironmentResponse(?string $include): array 'database' => ['data' => ['id' => '65634813', 'type' => 'databaseSchemas']], 'cache' => ['data' => null], 'websocketApplication' => ['data' => null], + 'buckets' => ['data' => array_map(fn (string $id) => ['id' => $id, 'type' => 'filesystems'], $bucketIds)], ], fn ($key) => in_array($key, $requested, true), ARRAY_FILTER_USE_KEY); return [ @@ -120,3 +121,121 @@ function captureEnvironmentIncludes(): Closure expect($sentDatabaseSchemaId->value)->toBe('65634813'); }); + +it('reads the attached bucket ids from the environment relationships', function () { + MockClient::global([ + GetOrganizationRequest::class => MockResponse::make(organizationResponse(), 200), + GetApplicationRequest::class => MockResponse::make(['data' => createApplicationResponse()], 200), + GetEnvironmentRequest::class => fn (PendingRequest $request) => MockResponse::make( + attachedEnvironmentResponse($request->query()->get('include'), ['fs-1']), + 200, + ), + ]); + + $this->artisan('environment:get', [ + 'environment' => 'env-1', + '--json' => true, + '--fields' => 'bucketIds', + '--no-interaction' => true, + ])->assertSuccessful() + ->expectsOutputToContain('"bucketIds":["fs-1"]'); +}); + +/** + * @return stdClass whose `body` holds the update request body, or stays unset when no update was sent + */ +function captureBucketUpdate(array $attachedBucketIds): stdClass +{ + $sent = new stdClass; + + MockClient::global([ + GetOrganizationRequest::class => MockResponse::make(organizationResponse(), 200), + GetApplicationRequest::class => MockResponse::make(['data' => createApplicationResponse()], 200), + GetEnvironmentRequest::class => fn (PendingRequest $request) => MockResponse::make( + attachedEnvironmentResponse($request->query()->get('include'), $attachedBucketIds), + 200, + ), + UpdateEnvironmentRequest::class => function (PendingRequest $request) use ($sent) { + $sent->body = $request->body()->all(); + + return MockResponse::make(attachedEnvironmentResponse(null), 200); + }, + ]); + + return $sent; +} + +it('attaches several bucket keys with their disks', function () { + $sent = captureBucketUpdate([]); + + $this->artisan('environment:update', [ + 'environment' => 'env-1', + '--bucket-keys' => 'fk-1:local:default,fk-2:public', + '--json' => true, + '--no-interaction' => true, + ])->assertSuccessful(); + + expect($sent->body['filesystem_keys'])->toBe([ + ['id' => 'fk-1', 'disk' => 'local', 'is_default_disk' => true], + ['id' => 'fk-2', 'disk' => 'public', 'is_default_disk' => false], + ]); +}); + +it('refuses to replace attached buckets without --force', function () { + $sent = captureBucketUpdate(['fs-existing']); + + $this->artisan('environment:update', [ + 'environment' => 'env-1', + '--bucket-keys' => 'fk-1:local', + '--json' => true, + '--no-interaction' => true, + ])->assertFailed(); + + expect(isset($sent->body))->toBeFalse(); +}); + +it('replaces attached buckets with --force', function () { + $sent = captureBucketUpdate(['fs-existing']); + + $this->artisan('environment:update', [ + 'environment' => 'env-1', + '--bucket-keys' => 'fk-1:local', + '--force' => true, + '--json' => true, + '--no-interaction' => true, + ])->assertSuccessful(); + + expect($sent->body['filesystem_keys'])->toBe([['id' => 'fk-1', 'disk' => 'local', 'is_default_disk' => false]]); +}); + +it('detaches every bucket when given an empty list', function () { + $sent = captureBucketUpdate(['fs-existing']); + + $this->artisan('environment:update', [ + 'environment' => 'env-1', + '--bucket-keys' => '', + '--force' => true, + '--json' => true, + '--no-interaction' => true, + ])->assertSuccessful(); + + expect($sent->body)->toHaveKey('filesystem_keys') + ->and($sent->body['filesystem_keys'])->toBe([]); +}); + +it('rejects bucket key entries without a disk or with two default disks', function (string $value) { + $sent = captureBucketUpdate([]); + + $this->artisan('environment:update', [ + 'environment' => 'env-1', + '--bucket-keys' => $value, + '--json' => true, + '--no-interaction' => true, + ])->assertFailed(); + + expect(isset($sent->body))->toBeFalse(); +})->with([ + 'missing disk' => 'fk-1', + 'unknown suffix' => 'fk-1:local:primary', + 'two defaults' => 'fk-1:local:default,fk-2:public:default', +]); From bae980e0cf876a7746ef441616b23f8ef337483c Mon Sep 17 00:00:00 2001 From: Amp Date: Sun, 15 Nov 2026 16:32:18 +0000 Subject: [PATCH 2/4] Ask for the buckets again when the API rejects one The form field was named bucket_keys, so a 422 on filesystem_keys.0.disk matched no field: an interactive update resent the same list and exited instead of reopening the bucket selector. Name the field after the API field and keep --bucket-keys as the option. Amp-Thread-ID: https://ampcode.com/threads/T-01a1de2b-3aa5-7684-a19c-87386ad7c591 Co-authored-by: Ed Grosvenor --- app/Commands/EnvironmentUpdate.php | 5 ++- .../Feature/EnvironmentRelationshipsTest.php | 45 +++++++++++++++++++ .../InteractiveEnvironmentUpdateCommand.php | 32 +++++++++++++ 3 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 tests/Fixtures/InteractiveEnvironmentUpdateCommand.php diff --git a/app/Commands/EnvironmentUpdate.php b/app/Commands/EnvironmentUpdate.php index 90550422..4aab4983 100644 --- a/app/Commands/EnvironmentUpdate.php +++ b/app/Commands/EnvironmentUpdate.php @@ -149,7 +149,7 @@ protected function updateEnvironment(Environment $environment): Environment */ protected function filesystemKeys(Environment $environment): ?array { - $value = $this->form()->get('bucket_keys'); + $value = $this->form()->get('filesystem_keys'); if ($value === null) { return null; @@ -410,8 +410,9 @@ protected function defineFields(Environment $environment): void 'websocket-application-id', )->setPreviousValue($environment->websocketApplicationId ?? ''); + // Named after the API field so a validation error on filesystem_keys.* asks for the buckets again. $this->form()->define( - 'bucket_keys', + 'filesystem_keys', fn ($resolver) => $resolver->fromInput( fn ($value) => $this->selectBucketKeys(), ), diff --git a/tests/Feature/EnvironmentRelationshipsTest.php b/tests/Feature/EnvironmentRelationshipsTest.php index 90bcc5bb..205532d4 100644 --- a/tests/Feature/EnvironmentRelationshipsTest.php +++ b/tests/Feature/EnvironmentRelationshipsTest.php @@ -1,14 +1,20 @@ mockGit = Mockery::mock(Git::class); @@ -239,3 +245,42 @@ function captureBucketUpdate(array $attachedBucketIds): stdClass 'unknown suffix' => 'fk-1:local:primary', 'two defaults' => 'fk-1:local:default,fk-2:public:default', ]); + +it('asks for the buckets again when the API rejects an attached bucket', function () { + $bodies = []; + + MockClient::global([ + GetOrganizationRequest::class => MockResponse::make(organizationResponse(), 200), + GetApplicationRequest::class => MockResponse::make(['data' => createApplicationResponse()], 200), + GetEnvironmentRequest::class => fn (PendingRequest $request) => MockResponse::make( + attachedEnvironmentResponse($request->query()->get('include')), + 200, + ), + ListObjectStorageBucketsRequest::class => MockResponse::make(['data' => [bucketResponse()], 'links' => ['next' => null]], 200), + ListBucketKeysRequest::class => MockResponse::make(['data' => [bucketKeyResponse()], 'links' => ['next' => null]], 200), + UpdateEnvironmentRequest::class => function (PendingRequest $request) use (&$bodies) { + $bodies[] = $request->body()->all(); + + return count($bodies) === 1 + ? MockResponse::make(['message' => 'Invalid.', 'errors' => ['filesystem_keys.0.disk' => ['The disk format is invalid.']]], 422) + : MockResponse::make(attachedEnvironmentResponse(null), 200); + }, + ]); + + Artisan::registerCommand(new InteractiveEnvironmentUpdateCommand); + + Prompt::fake([ + // Choose Buckets, the last field. + Key::UP, Key::SPACE, Key::ENTER, + // The bucket, its only key, a disk name the API rejects, not the default, no more buckets. + Key::DOWN, Key::ENTER, Key::ENTER, 'm', 'y', '.', 'd', 'i', 's', 'k', Key::ENTER, Key::ENTER, Key::ENTER, + // Asked for the buckets again. + Key::DOWN, Key::ENTER, Key::ENTER, 'f', 'i', 'l', 'e', 's', Key::ENTER, Key::ENTER, Key::ENTER, + ]); + + $this->artisan('test:interactive-environment-update', ['environment' => 'env-1'])->assertSuccessful(); + + expect($bodies)->toHaveCount(2) + ->and($bodies[0]['filesystem_keys'])->toBe([['id' => 'flsk-1', 'disk' => 'my.disk', 'is_default_disk' => false]]) + ->and($bodies[1]['filesystem_keys'])->toBe([['id' => 'flsk-1', 'disk' => 'files', 'is_default_disk' => false]]); +}); diff --git a/tests/Fixtures/InteractiveEnvironmentUpdateCommand.php b/tests/Fixtures/InteractiveEnvironmentUpdateCommand.php new file mode 100644 index 00000000..6432352e --- /dev/null +++ b/tests/Fixtures/InteractiveEnvironmentUpdateCommand.php @@ -0,0 +1,32 @@ +signature = str_replace('environment:update', 'test:interactive-environment-update', $this->signature); + + parent::__construct(); + } + + protected function isInteractive(): bool + { + return true; + } + + protected function configurePrompts(InputInterface $input): void + { + parent::configurePrompts($input); + + Prompt::interactive(true); + } +} From 6d54f9d432fc1b14289c13181b23b97293a9807d Mon Sep 17 00:00:00 2001 From: Amp Date: Sun, 15 Nov 2026 16:40:24 +0000 Subject: [PATCH 3/4] Validate the interactive disk name against the API's rule The prompt accepted ':' and ',', the characters bucket entries are joined with, so a disk named local:default became the default disk even after answering no, and my,disk aborted the command. Check the name against the API's own pattern, which excludes both. Amp-Thread-ID: https://ampcode.com/threads/T-01a1de2b-3aa5-7684-a19c-87386ad7c591 Co-authored-by: Ed Grosvenor --- app/Commands/EnvironmentUpdate.php | 10 +++++- .../Feature/EnvironmentRelationshipsTest.php | 32 +++++++++++++++++-- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/app/Commands/EnvironmentUpdate.php b/app/Commands/EnvironmentUpdate.php index 4aab4983..661f2baf 100644 --- a/app/Commands/EnvironmentUpdate.php +++ b/app/Commands/EnvironmentUpdate.php @@ -644,7 +644,15 @@ protected function selectBucketKeys(): string options: $keys->mapWithKeys(fn (BucketKey $key) => [$key->id => "{$key->name} ({$key->permission})"])->all(), ); - $disk = text(label: 'Disk name', placeholder: 'public', required: true); + // The API's own rule, which also keeps out the ':' and ',' the entries are joined with. + $disk = text( + label: 'Disk name', + placeholder: 'public', + required: true, + validate: fn (string $name) => preg_match('/^[A-Za-z0-9 _-]{1,40}$/', $name) + ? null + : 'Use up to 40 letters, numbers, spaces, dashes, or underscores.', + ); $isDefault = ! $hasDefault && confirm(label: 'Make it the default disk?', default: false); $hasDefault = $hasDefault || $isDefault; diff --git a/tests/Feature/EnvironmentRelationshipsTest.php b/tests/Feature/EnvironmentRelationshipsTest.php index 205532d4..f6674f08 100644 --- a/tests/Feature/EnvironmentRelationshipsTest.php +++ b/tests/Feature/EnvironmentRelationshipsTest.php @@ -262,7 +262,7 @@ function captureBucketUpdate(array $attachedBucketIds): stdClass $bodies[] = $request->body()->all(); return count($bodies) === 1 - ? MockResponse::make(['message' => 'Invalid.', 'errors' => ['filesystem_keys.0.disk' => ['The disk format is invalid.']]], 422) + ? MockResponse::make(['message' => 'Invalid.', 'errors' => ['filesystem_keys.0.disk' => ['The disk has already been taken.']]], 422) : MockResponse::make(attachedEnvironmentResponse(null), 200); }, ]); @@ -273,7 +273,7 @@ function captureBucketUpdate(array $attachedBucketIds): stdClass // Choose Buckets, the last field. Key::UP, Key::SPACE, Key::ENTER, // The bucket, its only key, a disk name the API rejects, not the default, no more buckets. - Key::DOWN, Key::ENTER, Key::ENTER, 'm', 'y', '.', 'd', 'i', 's', 'k', Key::ENTER, Key::ENTER, Key::ENTER, + Key::DOWN, Key::ENTER, Key::ENTER, 't', 'a', 'k', 'e', 'n', Key::ENTER, Key::ENTER, Key::ENTER, // Asked for the buckets again. Key::DOWN, Key::ENTER, Key::ENTER, 'f', 'i', 'l', 'e', 's', Key::ENTER, Key::ENTER, Key::ENTER, ]); @@ -281,6 +281,32 @@ function captureBucketUpdate(array $attachedBucketIds): stdClass $this->artisan('test:interactive-environment-update', ['environment' => 'env-1'])->assertSuccessful(); expect($bodies)->toHaveCount(2) - ->and($bodies[0]['filesystem_keys'])->toBe([['id' => 'flsk-1', 'disk' => 'my.disk', 'is_default_disk' => false]]) + ->and($bodies[0]['filesystem_keys'])->toBe([['id' => 'flsk-1', 'disk' => 'taken', 'is_default_disk' => false]]) ->and($bodies[1]['filesystem_keys'])->toBe([['id' => 'flsk-1', 'disk' => 'files', 'is_default_disk' => false]]); }); + +it('refuses a disk name the bucket list cannot carry when choosing buckets interactively', function () { + $sent = captureBucketUpdate([]); + + MockClient::global()->addResponses([ + ListObjectStorageBucketsRequest::class => MockResponse::make(['data' => [bucketResponse()], 'links' => ['next' => null]], 200), + ListBucketKeysRequest::class => MockResponse::make(['data' => [bucketKeyResponse()], 'links' => ['next' => null]], 200), + ]); + + Artisan::registerCommand(new InteractiveEnvironmentUpdateCommand); + + Prompt::fake([ + // Choose Buckets, the last field, then the bucket and its only key. + Key::UP, Key::SPACE, Key::ENTER, + Key::DOWN, Key::ENTER, Key::ENTER, + // A colon would read back as the default-disk marker, so the prompt refuses it. + 'l', 'o', 'c', 'a', 'l', ':', 'd', 'e', 'f', 'a', 'u', 'l', 't', Key::ENTER, + Key::BACKSPACE, Key::BACKSPACE, Key::BACKSPACE, Key::BACKSPACE, Key::BACKSPACE, Key::BACKSPACE, Key::BACKSPACE, Key::BACKSPACE, Key::ENTER, + // Not the default disk, no more buckets. + Key::ENTER, Key::ENTER, + ]); + + $this->artisan('test:interactive-environment-update', ['environment' => 'env-1'])->assertSuccessful(); + + expect($sent->body['filesystem_keys'])->toBe([['id' => 'flsk-1', 'disk' => 'local', 'is_default_disk' => false]]); +}); From 41eae638e73894fee3fcb594198c3655c403a2b2 Mon Sep 17 00:00:00 2001 From: Joe Tannenbaum Date: Mon, 23 Nov 2026 20:38:15 -0500 Subject: [PATCH 4/4] remove extra query --- app/Commands/EnvironmentUpdate.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/app/Commands/EnvironmentUpdate.php b/app/Commands/EnvironmentUpdate.php index 661f2baf..734082e8 100644 --- a/app/Commands/EnvironmentUpdate.php +++ b/app/Commands/EnvironmentUpdate.php @@ -157,12 +157,7 @@ protected function filesystemKeys(Environment $environment): ?array $keys = $this->parseBucketKeys($value); - $attached = spin( - fn () => $this->client->environments()->include('buckets')->get($environment->id)->bucketIds, - 'Fetching attached buckets...', - ); - - if ($attached !== []) { + if ($environment->bucketIds !== []) { $this->confirmDestructive($keys === [] ? "Detach every bucket from {$environment->name}?" : "Replace the buckets attached to {$environment->name}? Any attached bucket not listed will be detached.");