From 5699510c9e6d98ff913e0afee64371f8a231e818 Mon Sep 17 00:00:00 2001 From: Ahmed Darrazi Date: Sat, 10 Jan 2026 21:11:31 +0100 Subject: [PATCH] ui: add include_foundations toggle to inventory sync --- app/Filament/Pages/InventoryLanding.php | 10 ++++++++ tests/Feature/Filament/InventoryPagesTest.php | 3 ++- .../Inventory/InventorySyncButtonTest.php | 25 +++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/app/Filament/Pages/InventoryLanding.php b/app/Filament/Pages/InventoryLanding.php index 19d7265..71418b3 100644 --- a/app/Filament/Pages/InventoryLanding.php +++ b/app/Filament/Pages/InventoryLanding.php @@ -90,6 +90,13 @@ protected function getHeaderActions(): array new \App\Rules\SupportedPolicyTypesRule, ]) ->columnSpanFull(), + Toggle::make('include_foundations') + ->label('Include foundation types') + ->helperText('Include scope tags, assignment filters, and notification templates.') + ->default(true) + ->dehydrated() + ->rules(['boolean']) + ->columnSpanFull(), Toggle::make('include_dependencies') ->label('Include dependencies') ->helperText('Include dependency extraction where supported.') @@ -135,6 +142,9 @@ protected function getHeaderActions(): array if (array_key_exists('policy_types', $data)) { $selectionPayload['policy_types'] = $data['policy_types']; } + if (array_key_exists('include_foundations', $data)) { + $selectionPayload['include_foundations'] = (bool) $data['include_foundations']; + } if (array_key_exists('include_dependencies', $data)) { $selectionPayload['include_dependencies'] = (bool) $data['include_dependencies']; } diff --git a/tests/Feature/Filament/InventoryPagesTest.php b/tests/Feature/Filament/InventoryPagesTest.php index f1db79d..21f0ab8 100644 --- a/tests/Feature/Filament/InventoryPagesTest.php +++ b/tests/Feature/Filament/InventoryPagesTest.php @@ -17,7 +17,8 @@ $this->actingAs($user) ->get(InventoryLanding::getUrl(tenant: $tenant)) - ->assertOk(); + ->assertOk() + ->assertSee('Run Inventory Sync'); $this->actingAs($user) ->get(InventoryCoverage::getUrl(tenant: $tenant)) diff --git a/tests/Feature/Inventory/InventorySyncButtonTest.php b/tests/Feature/Inventory/InventorySyncButtonTest.php index 3b32a5f..0369083 100644 --- a/tests/Feature/Inventory/InventorySyncButtonTest.php +++ b/tests/Feature/Inventory/InventorySyncButtonTest.php @@ -95,6 +95,31 @@ expect((bool) ($run->selection_payload['include_dependencies'] ?? true))->toBeFalse(); }); +it('defaults include foundations toggle to true and persists it into the run selection payload', function () { + Queue::fake(); + + [$user, $tenant] = createUserWithTenant(role: 'owner'); + $this->actingAs($user); + + $tenant->makeCurrent(); + Filament::setTenant($tenant, true); + + $sync = app(InventorySyncService::class); + $allTypes = $sync->defaultSelectionPayload()['policy_types']; + $selectedTypes = array_slice($allTypes, 0, min(2, count($allTypes))); + + Livewire::test(InventoryLanding::class) + ->mountAction('run_inventory_sync') + ->set('mountedActions.0.data.policy_types', $selectedTypes) + ->assertActionDataSet(['include_foundations' => true]) + ->callMountedAction() + ->assertHasNoActionErrors(); + + $run = InventorySyncRun::query()->where('tenant_id', $tenant->id)->latest('id')->first(); + expect($run)->not->toBeNull(); + expect((bool) ($run->selection_payload['include_foundations'] ?? false))->toBeTrue(); +}); + it('rejects cross-tenant initiation attempts (403) with no side effects', function () { Queue::fake();