Private/Compile/Get-GovernanceMigrationConfigScope.ps1

function Get-GovernanceMigrationConfigScope {
    <#
        .SYNOPSIS
        Reads the migration query out of an Azure DevOps Migration Tools
        configuration file, so preflight validates exactly the work items the
        migration will move (sources.yaml `migrationConfig:`).

        The query is the WIQLQuery of the single enabled
        TfsWorkItemMigrationProcessor. The label is the optional top-level
        "_label" string. Returns @{ query; label } — the shape of a
        sources.yaml scope. Throws, naming the file, when it is missing, is not
        JSON, or does not hold exactly one enabled work item processor with a
        query: a preflight that silently ran without its query would validate
        the whole area, archive included.
    #>

    [CmdletBinding()]
    param(
        [Parameter(Mandatory)][string]$Path,
        [string]$Code = ''
    )
    $at = if ($Code) { "sources.yaml '$Code' migrationConfig" } else { 'migrationConfig' }
    if (-not (Test-Path -LiteralPath $Path)) { throw "$at not found: $Path" }
    try { $cfg = Get-Content -LiteralPath $Path -Raw | ConvertFrom-Json -AsHashtable -Depth 50 }
    catch { throw "$at is not valid JSON: $Path ($($_.Exception.Message))" }

    $procs = @($cfg.MigrationTools.Processors | Where-Object {
        $_ -and [string]$_.ProcessorType -eq 'TfsWorkItemMigrationProcessor' -and $_.Enabled -ne $false })
    if ($procs.Count -ne 1) {
        throw "$at must hold exactly one enabled TfsWorkItemMigrationProcessor, found $($procs.Count): $Path"
    }
    $query = [string]$procs[0].WIQLQuery
    if ([string]::IsNullOrWhiteSpace($query)) { throw "$at has an empty WIQLQuery: $Path" }

    return [ordered]@{
        query = $query
        label = if ($cfg.Contains('_label')) { [string]$cfg['_label'] } else { '' }
    }
}