create([ 'tenant_id' => null, 'external_id' => 'platform', 'name' => 'Platform', ]); }); it('disables running when preflight indicates nothing to do', function () { Queue::fake(); $platformTenant = Tenant::query()->where('external_id', 'platform')->firstOrFail(); $tenant = Tenant::factory()->create([ 'workspace_id' => (int) $platformTenant->workspace_id, ]); Finding::factory()->create([ 'tenant_id' => (int) $tenant->getKey(), ]); $user = PlatformUser::factory()->create([ 'capabilities' => [ PlatformCapabilities::ACCESS_SYSTEM_PANEL, PlatformCapabilities::OPS_VIEW, PlatformCapabilities::RUNBOOKS_VIEW, PlatformCapabilities::RUNBOOKS_RUN, PlatformCapabilities::RUNBOOKS_FINDINGS_LIFECYCLE_BACKFILL, ], 'is_active' => true, ]); $this->actingAs($user, 'platform'); Livewire::test(Runbooks::class) ->callAction('preflight', data: [ 'scope_mode' => FindingsLifecycleBackfillScope::MODE_ALL_TENANTS, ]) ->assertSet('preflight.affected_count', 0) ->assertActionDisabled('run'); }); it('requires typed confirmation and a reason for all-tenants runs', function () { Queue::fake(); $platformTenant = Tenant::query()->where('external_id', 'platform')->firstOrFail(); $tenant = Tenant::factory()->create([ 'workspace_id' => (int) $platformTenant->workspace_id, ]); Finding::factory()->create([ 'tenant_id' => (int) $tenant->getKey(), 'due_at' => null, ]); $user = PlatformUser::factory()->create([ 'capabilities' => [ PlatformCapabilities::ACCESS_SYSTEM_PANEL, PlatformCapabilities::OPS_VIEW, PlatformCapabilities::RUNBOOKS_VIEW, PlatformCapabilities::RUNBOOKS_RUN, PlatformCapabilities::RUNBOOKS_FINDINGS_LIFECYCLE_BACKFILL, ], 'is_active' => true, ]); $this->actingAs($user, 'platform'); Livewire::test(Runbooks::class) ->callAction('preflight', data: [ 'scope_mode' => FindingsLifecycleBackfillScope::MODE_ALL_TENANTS, ]) ->assertSet('preflight.affected_count', 1) ->callAction('run', data: []) ->assertHasActionErrors([ 'typed_confirmation', 'reason_code', 'reason_text', ]); Livewire::test(Runbooks::class) ->callAction('preflight', data: [ 'scope_mode' => FindingsLifecycleBackfillScope::MODE_ALL_TENANTS, ]) ->assertSet('preflight.affected_count', 1) ->callAction('run', data: [ 'typed_confirmation' => 'backfill', 'reason_code' => 'DATA_REPAIR', 'reason_text' => 'Test run', ]) ->assertHasActionErrors(['typed_confirmation']); });