Modules/businessdev.ALbuild.Containers/Public/Get-BcArtifactSymbolFolder.ps1

function Get-BcArtifactSymbolFolder {
    <#
    .SYNOPSIS
        Returns the symbol (package cache) folders a host AL compile needs from a downloaded BC artifact.
 
    .DESCRIPTION
        Collects every folder of a Get-BcArtifact result that provides compiled first-party symbols
        for a host (AL Tool) compile, in one place instead of each caller re-deriving the layout:
 
          * '<application>/Extensions' - first-party app symbols shipped with the country artifact.
          * '<application>/Applications.<COUNTRY>' - the compiled country apps INCLUDING the test toolkit
            (Tests-TestLibraries, Library Assert, Test Runner, ...). Localized artifacts only.
          * the platform folder holding 'System.app' - the AL system/runtime symbols.
 
        The W1 artifact ships no 'Applications.W1' folder - its compiled test toolkit lives scattered
        through the PLATFORM artifact instead ('Applications/TestFramework/**', 'Applications/BaseApp/Test',
        'Applications/System Application/Test', ...). Without it, compiling a test app against W1 fails
        with AL1022 ('Tests-TestLibraries ... could not be found'). So when the country artifact has no
        'Applications.*' folder, the platform's toolkit apps (paths matching 'TestFramework', a 'Test'
        segment, or a 'Test Library' name; ~22 MB) are staged once into '.albuild-toolkit-symbols'
        beside the platform artifact and that folder is returned too. The staging is keyed to the
        artifact version (it lives inside that artifact's cache folder), so it is reused across builds.
 
    .PARAMETER Artifact
        The artifact object returned by Get-BcArtifact (ApplicationPath / PlatformPath).
 
    .PARAMETER Force
        Re-stage the W1 toolkit symbols even when the staging folder already exists.
 
    .EXAMPLE
        $artifact = Get-BcArtifact -ArtifactUrl $url
        $symbols = Get-BcArtifactSymbolFolder -Artifact $artifact
        Invoke-BcCompiler -ProjectFolder .\app -PackageCachePath (@('.alpackages') + $symbols)
 
    .OUTPUTS
        System.String[] - existing folders, ready for the compiler's package cache path.
    #>

    [CmdletBinding()]
    [OutputType([string[]])]
    param(
        [Parameter(Mandatory)] [ValidateNotNull()] [object] $Artifact,
        [switch] $Force
    )

    $paths = [System.Collections.Generic.List[string]]::new()

    $extensions = Join-Path $Artifact.ApplicationPath 'Extensions'
    if (Test-Path -LiteralPath $extensions) { $paths.Add($extensions) }

    # Compiled, country-specific first-party apps incl. the test toolkit (localized artifacts only).
    $countryApps = @(Get-ChildItem -LiteralPath $Artifact.ApplicationPath -Directory -ErrorAction SilentlyContinue |
            Where-Object { $_.Name -match '^Applications\..+' })
    foreach ($folder in $countryApps) { $paths.Add($folder.FullName) }

    if ($Artifact.PlatformPath) {
        # The platform 'System.app' (AL system/runtime symbols) sits in a version-specific folder.
        $systemApp = Get-ChildItem -LiteralPath $Artifact.PlatformPath -Recurse -Filter 'System.app' -File -ErrorAction SilentlyContinue |
            Select-Object -First 1
        if ($systemApp) { $paths.Add($systemApp.Directory.FullName) }

        # W1 (no Applications.<country> folder): stage the platform's compiled test toolkit once.
        if ($countryApps.Count -eq 0) {
            $platformApps = Join-Path $Artifact.PlatformPath 'Applications'
            if (Test-Path -LiteralPath $platformApps) {
                $staging = Join-Path $Artifact.PlatformPath '.albuild-toolkit-symbols'
                # Wrapped in @(): an if that emits an empty array collapses to $null via the pipeline,
                # and .Count on $null then dies under Set-StrictMode.
                $staged = @(if (Test-Path -LiteralPath $staging) {
                        Get-ChildItem -LiteralPath $staging -Filter '*.app' -File -ErrorAction SilentlyContinue
                    })
                if ($Force -or $staged.Count -eq 0) {
                    New-Item -ItemType Directory -Force -Path $staging | Out-Null
                    Get-ChildItem -LiteralPath $platformApps -Recurse -Filter '*.app' -File -ErrorAction SilentlyContinue |
                        Where-Object { $_.FullName -match '(?i)[\\/]TestFramework[\\/]|[\\/]Test[\\/]|Test Library' } |
                        Copy-Item -Destination $staging -Force
                    Write-ALbuildLog -Level Information "Staged the W1 test toolkit symbols from the platform artifact into '$staging'."
                }
                if (@(Get-ChildItem -LiteralPath $staging -Filter '*.app' -File -ErrorAction SilentlyContinue).Count -gt 0) {
                    $paths.Add($staging)
                }
            }
        }
    }

    return $paths.ToArray()
}