< Summary - Kestrun — Combined Coverage

Information
Class: Public.Server.Enable-KrConfiguration
Assembly: Kestrun.PowerShell.Public
File(s): /home/runner/work/Kestrun/Kestrun/src/PowerShell/Kestrun/Public/Server/Enable-KrConfiguration.ps1
Tag: Kestrun/Kestrun@0d738bf294e6281b936d031e1979d928007495ff
Line coverage
0%
Covered lines: 0
Uncovered lines: 41
Coverable lines: 41
Total lines: 115
Line coverage: 0%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100 08/26/2025 - 14:53:17 Line coverage: 84.6% (11/13) Total lines: 59 Tag: Kestrun/Kestrun@78d1e497d8ba989d121b57aa39aa3c6b22de743109/02/2025 - 17:53:35 Line coverage: 92.8% (13/14) Total lines: 60 Tag: Kestrun/Kestrun@58c69eb1b344fcfa1f4b9c597030af85fac9e31b09/03/2025 - 13:55:51 Line coverage: 91.6% (11/12) Total lines: 62 Tag: Kestrun/Kestrun@80ce2a54be2f719c7be1c21a92a8156bfdc48eb409/04/2025 - 17:02:01 Line coverage: 76.9% (10/13) Total lines: 68 Tag: Kestrun/Kestrun@f3880b25ea131298aa2f8b1e0d0a8d55eb160bc009/04/2025 - 18:11:31 Line coverage: 76.9% (10/13) Total lines: 69 Tag: Kestrun/Kestrun@de99e24698289f3f61ac7b73e96092732ae12b0509/07/2025 - 18:41:40 Line coverage: 73.5% (25/34) Total lines: 105 Tag: Kestrun/Kestrun@2192d4ccb46312ce89b7f7fda1aa8c915bfa228409/08/2025 - 20:34:03 Line coverage: 72.2% (26/36) Total lines: 109 Tag: Kestrun/Kestrun@3790ee5884494a7a2a829344a47743e0bf492e7210/13/2025 - 16:52:37 Line coverage: 0% (0/37) Total lines: 110 Tag: Kestrun/Kestrun@10d476bee71c71ad215bb8ab59f219887b5b4a5e11/14/2025 - 12:29:34 Line coverage: 0% (0/36) Total lines: 109 Tag: Kestrun/Kestrun@5e12b09a6838e68e704cd3dc975331b9e680a62611/19/2025 - 02:25:56 Line coverage: 0% (0/37) Total lines: 110 Tag: Kestrun/Kestrun@98ff905e5605a920343154665980a71211a03c6d12/12/2025 - 17:27:19 Line coverage: 0% (0/41) Total lines: 115 Tag: Kestrun/Kestrun@826bf9dcf9db118c5de4c78a3259bce9549f0dcd

Metrics

File(s)

/home/runner/work/Kestrun/Kestrun/src/PowerShell/Kestrun/Public/Server/Enable-KrConfiguration.ps1

#LineLine coverage
 1<#
 2    .SYNOPSIS
 3        Enables Kestrun server configuration and starts the server.
 4    .DESCRIPTION
 5        This function applies the configuration to the Kestrun server and starts it.
 6    .PARAMETER Server
 7        The Kestrun server instance to configure and start. This parameter is mandatory.
 8    .PARAMETER ExcludeVariables
 9        An array of variable names to exclude from the runspaces.
 10    .PARAMETER ExcludeFunctions
 11        An array of function name patterns to exclude from the runspaces.
 12    .PARAMETER Quiet
 13        If specified, suppresses output messages during the configuration and startup process.
 14    .PARAMETER PassThru
 15        If specified, the cmdlet will return the modified server instance after applying the configuration.
 16    .EXAMPLE
 17        Enable-KrConfiguration -Server $server
 18        Applies the configuration to the specified Kestrun server instance and starts it.
 19    .NOTES
 20        This function is designed to be used after the server has been configured with routes, listeners,
 21        and other middleware components.
 22#>
 23function Enable-KrConfiguration {
 24    [KestrunRuntimeApi('Definition')]
 25    [CmdletBinding()]
 26    [OutputType([Kestrun.Hosting.KestrunHost])]
 27    [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingWriteHost', '')]
 28    param(
 29        [Parameter(Mandatory = $false, ValueFromPipeline = $true)]
 30        [Kestrun.Hosting.KestrunHost]$Server,
 31        [Parameter()]
 32        [string[]]$ExcludeVariables,
 33        [Parameter()]
 34        [string[]]$ExcludeFunctions,
 35        [Parameter()]
 36        [switch]$Quiet,
 37        [Parameter()]
 38        [switch]$PassThru
 39    )
 40    begin {
 41        # Ensure the server instance is resolved
 042        $Server = Resolve-KestrunServer -Server $Server
 43    }
 44    process {
 045        $Variables = Get-KrAssignedVariable -FromParent -ResolveValues -IncludeSetVariable
 46
 47        # Build user variable map as before
 048        $vars = [System.Collections.Generic.Dictionary[string, object]]::new()
 049        foreach ($v in $Variables) {
 050            if ($ExcludeVariables -notcontains $v.Name) {
 051                $null = $Server.SharedState.Set($v.Name, $v.Value, $true)
 52            }
 53        }
 054        Write-KrLog -Level Debug -Logger $Server.Logger -Message 'Collected {VarCount} user-defined variables for server
 055        $callerPath = $null
 056        $selfPath = $PSCommandPath
 057        foreach ($f in Get-PSCallStack) {
 058            $p = $f.InvocationInfo.ScriptName
 059            if ($p) {
 060                $rp = $null
 061                try { $tmp = Resolve-Path -LiteralPath $p -ErrorAction Stop; $rp = $tmp.ProviderPath } catch { Write-Deb
 062                if ($rp -and (!$selfPath -or $rp -ne (Resolve-Path -LiteralPath $selfPath).ProviderPath)) {
 063                    $callerPath = $rp
 64                    break
 65                }
 66            }
 67        }
 68        # AUTO: collect session-defined functions present now
 069        $fx = @( Get-Command -CommandType Function | Where-Object { -not $_.Module } )
 70
 071        if ($callerPath) {
 072            $fx = $fx | Where-Object {
 073                $_.ScriptBlock.File -and
 074                ((Resolve-Path -LiteralPath $_.ScriptBlock.File -ErrorAction SilentlyContinue)?.ProviderPath) -eq $calle
 75            }
 076            $fx = @($fx)  # normalize again
 77        }
 78
 79        # Exclude functions by name patterns if specified
 080        if ($ExcludeFunctions) {
 081            $fx = $fx | Where-Object {
 082                $n = $_.Name
 083                -not ($ExcludeFunctions | Where-Object { $n -like $_ }).Count
 84            }
 085            $fx = @($fx)  # normalize again
 86        }
 87
 88        # Create a dictionary of function names to their definitions
 089        $fxMap = $null
 090        if ($fx -and $fx.Count -gt 0) {
 091            $fxMap = [System.Collections.Generic.Dictionary[string, string]]::new([System.StringComparer]::OrdinalIgnore
 092            foreach ($f in $fx) { $fxMap[$f.Name] = $f.Definition }
 93        }
 094        Write-KrLog -Level Debug -Logger $Server.Logger -Message 'Enabling Kestrun server configuration with {VarCount} 
 95        # Apply the configuration to the server
 96        # Set the user-defined variables in the server configuration
 097        $Server.EnableConfiguration($vars, $fxMap) | Out-Null
 98
 099        Write-KrLog -Level Information -Logger $Server.Logger -Message 'Kestrun server configuration enabled successfull
 100
 0101        if (-not $Quiet.IsPresent) {
 0102            Write-Host 'Kestrun server configuration enabled successfully.'
 0103            Write-Host "Server Name: $($Server.Options.ApplicationName)"
 104        }
 105        # Generate OpenAPI components for all documents
 0106        foreach ( $doc in $Server.OpenApiDocumentDescriptor.Values ) {
 0107            $doc.GenerateComponents()
 108        }
 109
 0110        if ($PassThru.IsPresent) {
 111            # if the PassThru switch is specified, return the modified server instance
 0112            return $Server
 113        }
 114    }
 115}

Methods/Properties

Enable-KrConfiguration()