Modules/businessdev.ALbuild.Apps/Public/Compare-BcCallGraph.ps1

function Compare-BcCallGraph {
    <#
    .SYNOPSIS
        Compares a call graph with a baseline and returns the impact of the change.
 
    .DESCRIPTION
        A member counts as changed when it was added, removed, calls something different, or - when the
        baseline folder has an analysis.json with source hashes - when its body text changed. The impact is
        everything that transitively calls a changed member (and the former callers of a removed one), plus
        the [Test] methods that reach the change: the tests worth running first.
 
    .PARAMETER GraphPath
        The current call graph folder (or its graph.jsonl).
 
    .PARAMETER BaselinePath
        The baseline call graph folder (or its graph.jsonl).
 
    .PARAMETER WorkspaceRoot
        Root that source paths are shown relative to.
 
    .PARAMETER MaxItems
        Maximum entries per list. Default 2000.
 
    .EXAMPLE
        Compare-BcCallGraph -GraphPath .albuild/callgraph -BaselinePath ./previous/callgraph
 
    .OUTPUTS
        PSCustomObject: Added, Modified, Removed, Affected, Tests (member lists) and their totals.
    #>

    [CmdletBinding()]
    [OutputType([PSCustomObject])]
    param(
        [Parameter(Mandatory)] [string] $GraphPath,
        [Parameter(Mandatory)] [string] $BaselinePath,
        [string] $WorkspaceRoot,
        [ValidateRange(1, [int]::MaxValue)] [int] $MaxItems = 2000
    )

    if (-not (Resolve-BcCallGraphPath -Path $BaselinePath)) { throw "No call graph in the baseline '$BaselinePath'." }
    $analysis = Invoke-BcCallGraphAnalysis -GraphPath $GraphPath -BaselinePath $BaselinePath -WorkspaceRoot $WorkspaceRoot -MaxListItems $MaxItems
    $impact = $analysis['impact']
    $list = { param($items) @($items | ForEach-Object { [PSCustomObject]@{ Object = $_['object']; Member = $_['member']; Kind = $_['kind']; Path = $_['path']; Line = $_['line']; Id = $_['id'] } }) }
    [PSCustomObject]@{
        Baseline           = $analysis['baseline']
        Added              = & $list $impact['added']
        Modified           = & $list $impact['modified']
        Removed            = & $list $impact['removed']
        Affected           = & $list $impact['affected']
        Tests              = & $list $impact['tests']
        AddedTotal         = $impact['addedTotal']
        ModifiedTotal      = $impact['modifiedTotal']
        RemovedTotal       = $impact['removedTotal']
        AffectedTotal      = $impact['affectedTotal']
        AffectedObjects    = $impact['affectedObjects']
        TestsTotal         = $impact['testsTotal']
        BodyHashesCompared = [bool]$impact['bodyHashesCompared']
    }
}