Public/Test-CCReleaseWorkflow.ps1

function Test-CCReleaseWorkflow {
    <#
    .SYNOPSIS
        Reports the state of CodeCompass-managed workflows in a repository — without changing anything.
    .DESCRIPTION
        Read-only adoption assessment. For each workflow CodeCompass.Release would manage, reports
        Absent / Matches / Behind / Differs / Adopted, and lists other (unmanaged) workflow files
        present so you can spot overlap before adopting. Behind is a file as CodeCompass wrote it
        where the template has moved on: the next update writes it. Differs is a file that was
        edited, or that CodeCompass did not write: an update leaves it alone. With -Diff, shows
        the actual delta (current vs. what would be written).

        Modified is true for an adopted workflow that has changed since it was enrolled. Nothing
        overwrites such a file, and nothing else reports the change: the weekly freshness check
        names it. Where the change is meant, enrol the file again with
        Install-CCReleaseWorkflow -AdoptFile, and the manifest holds what it is now.
    .EXAMPLE
        Test-CCReleaseWorkflow -Path .
    .EXAMPLE
        Test-CCReleaseWorkflow -Path . -Diff
    #>

    [CmdletBinding()]
    [OutputType([pscustomobject])]
    param(
        [Parameter(Position = 0)]
        [string]$Path = '.',

        [switch]$Diff
    )

    $full = (Resolve-Path -LiteralPath $Path).Path
    $service = [CodeCompass.Core.Workflows.WorkflowService]::new()

    if (-not $Diff) {
        $report = $service.Assess($full, 'CodeCompass.Release')
        foreach ($workflow in $report.Workflows) {
            [pscustomobject]@{
                Path     = $workflow.TargetRelativePath
                Status   = $workflow.Status.ToString()
                Detail   = $workflow.Detail
                Modified = $workflow.ModifiedSinceEnrolment
            }
        }
        foreach ($other in $report.OtherWorkflows) {
            [pscustomobject]@{
                Path     = $other
                Status   = 'Unmanaged'
                Detail   = 'Not managed by CodeCompass; review for overlap.'
                Modified = $false
            }
        }
        return
    }

    # -Diff: show the delta between what exists and what CodeCompass would generate.
    foreach ($file in $service.Preview($full, 'CodeCompass.Release')) {
        $target = Join-Path $full $file.RelativePath
        $current = if (Test-Path -LiteralPath $target) { (Get-Content -LiteralPath $target -Raw) } else { '' }
        if ($null -eq $current) { $current = '' }

        $normalizedCurrent = $current -replace "`r`n", "`n" -replace "`r", "`n"
        $normalizedProposed = $file.Content -replace "`r`n", "`n" -replace "`r", "`n"
        if ($normalizedCurrent -eq $normalizedProposed) { continue }

        $verb = if ($normalizedCurrent -eq '') { 'would create' } else { 'would update' }
        "=== $($file.RelativePath) ($verb) ==="
        Get-CCTextDiff -Current $normalizedCurrent -Proposed $normalizedProposed
        ''
    }
}