Public/Test-Governance.ps1
|
function Test-Governance { <# .SYNOPSIS Validates the authored governance source — schema, unique short codes, resolvable owner references, and Azure DevOps area-path limits — without writing the resolved file or making any live calls. #> [CmdletBinding()] param( [Parameter(Mandatory)][string]$ProgramPath ) $program = Split-Path $ProgramPath -Leaf $source = Import-GovernanceSource -ProgramPath $ProgramPath $resolved = Resolve-Governance -Manifest $source.Manifest -Source $source.Hierarchy -Access $source.Access -Members $source.Members -SourceHash $source.Hash -Systems $source.Systems $issues = Test-ResolvedGovernance -Resolved $resolved $issues += Test-GovernanceAzManifest -Manifest $source.Manifest $issues += Test-GovernanceSources -Sources $source.Sources -Resolved $resolved -Labels $source.SourceLabels ` -Reporting $source.SourceReporting -Scope $source.SourceScope # Owner references must resolve to a real team's product-qualified code (e.g. PTL-FND). $teamKeys = @($resolved.teams | Where-Object { $_.codePath } | ForEach-Object { $_.codePath }) foreach ($area in $resolved.areaPaths) { if ($area.owner -and $area.owner -notin $teamKeys) { $issues += "Owner '$($area.owner)' on '$($area.path)' does not resolve to a team" } } if ($issues.Count -gt 0) { $issues | ForEach-Object { Write-Error $_ } throw "Governance validation failed for '$program' with $($issues.Count) issue(s)." } Write-Host "Governance '$program' is valid." -ForegroundColor Green # Where the Azure CLI context is declared, and whether anything competes # with it (ADR-012). Reported after the verdict because none of it makes # the authored source invalid — a program with no azure: block is valid, # it just has no identity of its own. Stated even when there is nothing # wrong: a check whose only output is silence teaches nobody it exists. $azCtx = Get-GovernanceAzContext -Manifest $source.Manifest if ($azCtx -and $azCtx.ProfileDir) { Write-Host "Azure CLI profile: $($azCtx.ProfileDir) (manifest.yaml azure:; sign in with 'connect')" -ForegroundColor DarkGray } Show-GovernanceAzContextPlacement -Manifest $source.Manifest -ProgramPath $ProgramPath | Out-Null return $true } |